feat: always skip the https ingress/ingress-route/deployment port entry if there is a corresponding http entry

Also inject the corresponding entries as necessary
This commit is contained in:
Jose Diaz-Gonzalez committed 2024-02-12 01:31:39 -05:00
1 parent bfccf60a37
commit 433eb26f3c
5 files changed
+46 -1

No files matched your search

+1 -1
View File
@@ -243,7 +243,7 @@ dokku scheduler-k3s:set --global letsencrypt-email-prod automated@dokku.sh
dokku scheduler-k3s:set --global letsencrypt-email-stag automated@dokku.sh dokku scheduler-k3s:set --global letsencrypt-email-stag automated@dokku.sh
``` ```
After enabling and rebuilding, all apps with an `https` port mapping that utilize the related letsencrypt server will be automatically updated to enable ssl. All http requests will then be redirected to https. After enabling and rebuilding, all apps with an `http:80` port mapping will have a corresponding `https:443` added and ssl will be automatically enabled. All http requests will then be redirected to https.
### Customizing the letsencrypt server ### Customizing the letsencrypt server
@@ -1,5 +1,9 @@
{{- $processName := "PROCESS_NAME" }} {{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }} {{- $config := index .Values.processes "PROCESS_NAME" }}
{{- $mappings := dict }}
{{- range $pdx, $port_map := $config.web.port_maps }}
{{- $mappings := set $mappings $port_map.name "true" }}
{{- end }}
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@@ -76,6 +80,9 @@ spec:
{{- if eq $processName "web" }} {{- if eq $processName "web" }}
ports: ports:
{{- range $pdx, $port_map := $config.web.port_maps }} {{- range $pdx, $port_map := $config.web.port_maps }}
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
{{- continue }}
{{- end }}
- containerPort: {{ $port_map.container_port }} - containerPort: {{ $port_map.container_port }}
name: {{ $port_map.name }} name: {{ $port_map.name }}
protocol: {{ $port_map.protocol }} protocol: {{ $port_map.protocol }}
@@ -1,7 +1,14 @@
{{- $processName := "PROCESS_NAME" }} {{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }} {{- $config := index .Values.processes "PROCESS_NAME" }}
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "traefik") }} {{- if and $config.web.domains (eq $.Values.global.network.ingress_class "traefik") }}
{{- $mappings := dict }}
{{- range $pdx, $port_map := $config.web.port_maps }} {{- range $pdx, $port_map := $config.web.port_maps }}
{{- $mappings := set $mappings $port_map.name "true" }}
{{- end }}
{{- range $pdx, $port_map := $config.web.port_maps }}
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
{{- continue }}
{{- end }}
--- ---
apiVersion: traefik.io/v1alpha1 apiVersion: traefik.io/v1alpha1
kind: IngressRoute kind: IngressRoute
@@ -1,7 +1,14 @@
{{- $processName := "PROCESS_NAME" }} {{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }} {{- $config := index .Values.processes "PROCESS_NAME" }}
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }} {{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }}
{{- $mappings := dict }}
{{- range $pdx, $port_map := $config.web.port_maps }} {{- range $pdx, $port_map := $config.web.port_maps }}
{{- $mappings := set $mappings $port_map.name "true" }}
{{- end }}
{{- range $pdx, $port_map := $config.web.port_maps }}
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
{{- continue }}
{{- end }}
--- ---
apiVersion: networking.k8s.io/v1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
+24
View File
@@ -426,6 +426,30 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
}) })
} }
for _, portMap := range processValues.Web.PortMaps {
_, httpOk := portMaps[fmt.Sprintf("http-80-%d", portMap.ContainerPort)]
_, httpsOk := portMaps[fmt.Sprintf("https-443-%d", portMap.ContainerPort)]
if portMap.Scheme == "http" && !httpsOk && tlsEnabled {
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
ContainerPort: portMap.ContainerPort,
HostPort: 443,
Name: fmt.Sprintf("https-443-%d", portMap.ContainerPort),
Protocol: PortmapProtocol_TCP,
Scheme: "https",
})
}
if portMap.Scheme == "https" && !httpOk {
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
ContainerPort: portMap.ContainerPort,
HostPort: 80,
Name: fmt.Sprintf("http-80-%d", portMap.ContainerPort),
Protocol: PortmapProtocol_TCP,
Scheme: "http",
})
}
}
sort.Sort(NameSorter(processValues.Web.PortMaps)) sort.Sort(NameSorter(processValues.Web.PortMaps))
sort.Strings(processValues.Web.Domains) sort.Strings(processValues.Web.Domains)
} }