From bfccf60a37314c20ed654200d7bbc559c97a56d1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 07:37:47 -0500 Subject: [PATCH] refactor: simplify tls handling by always redirecting --- plugins/scheduler-k3s/template.go | 11 +++++------ .../templates/chart/ingress-route.yaml | 9 ++++----- .../scheduler-k3s/templates/chart/ingress.yaml | 5 ++++- plugins/scheduler-k3s/triggers.go | 15 +++++---------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/plugins/scheduler-k3s/template.go b/plugins/scheduler-k3s/template.go index c371daae8..3addd48d3 100644 --- a/plugins/scheduler-k3s/template.go +++ b/plugins/scheduler-k3s/template.go @@ -161,12 +161,11 @@ type ProcessCron struct { } type ProcessPortMap struct { - ContainerPort int32 `yaml:"container_port"` - HostPort int32 `yaml:"host_port"` - Scheme string `yaml:"scheme"` - Protocol PortmapProtocol `yaml:"protocol"` - Name string `yaml:"name"` - RedirectToHttps bool `yaml:"redirect_to_https"` + ContainerPort int32 `yaml:"container_port"` + HostPort int32 `yaml:"host_port"` + Scheme string `yaml:"scheme"` + Protocol PortmapProtocol `yaml:"protocol"` + Name string `yaml:"name"` } type PortmapProtocol string diff --git a/plugins/scheduler-k3s/templates/chart/ingress-route.yaml b/plugins/scheduler-k3s/templates/chart/ingress-route.yaml index ca9e3f87e..f5fcbb96c 100644 --- a/plugins/scheduler-k3s/templates/chart/ingress-route.yaml +++ b/plugins/scheduler-k3s/templates/chart/ingress-route.yaml @@ -26,16 +26,15 @@ metadata: namespace: {{ $.Values.global.namespace }} spec: entryPoints: - {{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }} + {{- if $config.web.tls.enabled }} - websecure - {{- else }} - - web {{- end }} + - web routes: {{- range $ddx, $domain := $config.web.domains }} - kind: Rule match: Host(`{{ $domain }}`) - {{- if and $config.web.tls.enabled (and (eq $port_map.scheme "http") $port_map.redirect_to_https) }} + {{- if $config.web.tls.enabled }} middlewares: - name: {{ $.Values.global.app_name}}-{{ $processName }}-redirect-to-https namespace: {{ $.Values.global.namespace }} @@ -47,7 +46,7 @@ spec: port: {{ $port_map.name }} scheme: http {{- end }} - {{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }} + {{- if $config.web.tls.enabled }} tls: secretName: tls-{{ $.Values.global.app_name }}-{{ $processName }} {{- end }} diff --git a/plugins/scheduler-k3s/templates/chart/ingress.yaml b/plugins/scheduler-k3s/templates/chart/ingress.yaml index 36a622a8b..414022b07 100644 --- a/plugins/scheduler-k3s/templates/chart/ingress.yaml +++ b/plugins/scheduler-k3s/templates/chart/ingress.yaml @@ -18,6 +18,9 @@ metadata: {{ $k }}: {{ $v | quote }} {{- end }} {{- end }} + {{- if $config.web.tls.enabled }} + nginx.ingress.kubernetes.io/force-ssl-redirect: "true" + {{- end }} labels: app.kubernetes.io/instance: {{ $.Values.global.app_name }}-{{ $processName }} app.kubernetes.io/name: {{ $processName }} @@ -26,7 +29,7 @@ metadata: namespace: {{ $.Values.global.namespace }} spec: ingressClassName: nginx - {{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }} + {{- if $config.web.tls.enabled }} tls: - hosts: {{- range $ddx, $domain := $config.web.domains }} diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index 16f824271..51caafee4 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -417,17 +417,12 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e protocol = PortmapProtocol_UDP } - redirecToHttps := false - if _, ok := portMaps[fmt.Sprintf("https-443-%d", portMap.ContainerPort)]; ok && portMap.Scheme == "http" { - redirecToHttps = true - } processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{ - ContainerPort: portMap.ContainerPort, - HostPort: portMap.HostPort, - Name: portMap.String(), - Protocol: protocol, - RedirectToHttps: redirecToHttps, - Scheme: portMap.Scheme, + ContainerPort: portMap.ContainerPort, + HostPort: portMap.HostPort, + Name: portMap.String(), + Protocol: protocol, + Scheme: portMap.Scheme, }) }