fix: replace existing port-map ingress objects with domain ingress objects

Domains cannot be reused across ingress objects, and port maps are a function of a domain, so the inversion here makes most sense (at the cost of some downtime when migrating.
This commit is contained in:
Jose Diaz-Gonzalez committed 2024-03-12 03:55:40 -04:00
1 parent 59958181e4
commit d4b484a33a
10 files changed
+152 -25

No files matched your search

@@ -15,3 +15,35 @@
{{- end }}
{{- end }}
{{- end }}
{{- define "primary.port" -}}
{{- $found := dict -}}
{{- range $idx, $port_map := . -}}
{{- if hasPrefix "https-443-" $port_map.name -}}
{{- $found := set $found "https-443" $port_map.name -}}
{{- end -}}
{{- if hasPrefix "http-80-" $port_map.name -}}
{{- $found := set $found "http-80" $port_map.name -}}
{{- end -}}
{{- if and (eq "https" $port_map.scheme) (not (hasKey $found "https")) -}}
{{- $found := set $found "https" $port_map.name -}}
{{- end -}}
{{- if and (eq "http" $port_map.scheme) (not (hasKey $found "http")) -}}
{{- $found := set $found "http" $port_map.name -}}
{{- end -}}
{{- if not (hasKey $found "any") -}}
{{- $found := set $found "any" $port_map.name -}}
{{- end -}}
{{- end -}}
{{- if hasKey $found "https-443" -}}
{{- get $found "https-443" -}}
{{- else if hasKey $found "http-80" -}}
{{- get $found "http-80" -}}
{{- else if hasKey $found "https" -}}
{{- get $found "https" -}}
{{- else if hasKey $found "http" -}}
{{- get $found "http" -}}
{{- else if hasKey $found "any" -}}
{{- get $found "any" -}}
{{- end -}}
{{- end -}}
@@ -30,7 +30,7 @@ spec:
{{ include "print.labels" (dict "config" $.Values.global "key" "secret") | indent 6 }}
{{ include "print.labels" (dict "config" $config "key" "secret") | indent 6 }}
dnsNames:
{{- range $config.web.domains }}
- {{ . }}
{{- range $idx, $domain := $config.web.domains }}
- {{ $domain.name }}
{{- end }}
{{- end }}
@@ -34,7 +34,7 @@ spec:
routes:
{{- range $ddx, $domain := $config.web.domains }}
- kind: Rule
match: Host(`{{ $domain }}`)
match: Host(`{{ $domain.name }}`)
{{- if $config.web.tls.enabled }}
middlewares:
- name: {{ $.Values.global.app_name}}-{{ $processName }}-redirect-to-https
@@ -1,14 +1,7 @@
{{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }}
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }}
{{- $mappings := dict }}
{{- 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 }}
{{- range $pdx, $domain := $config.web.domains }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
@@ -26,30 +19,28 @@ metadata:
app.kubernetes.io/part-of: {{ $.Values.global.app_name }}
{{ include "print.labels" (dict "config" $.Values.global "key" "ingress") | indent 4 }}
{{ include "print.labels" (dict "config" $config "key" "ingress") | indent 4 }}
name: {{ $.Values.global.app_name }}-{{ $processName }}-{{ $port_map.name }}
name: {{ $.Values.global.app_name }}-{{ $processName }}-{{ $domain.slug }}
namespace: {{ $.Values.global.namespace }}
spec:
ingressClassName: nginx
{{- if $config.web.tls.enabled }}
tls:
- hosts:
{{- range $ddx, $domain := $config.web.domains }}
- {{ $domain | quote }}
{{- end }}
- {{ $domain.domain | quote }}
secretName: tls-{{ $.Values.global.app_name }}-{{ $processName }}
{{- end }}
rules:
{{- range $ddx, $domain := $config.web.domains }}
- host: {{ $domain | quote }}
- host: {{ $domain.domain | quote }}
http:
paths:
{{- if $config.web.port_maps }}
- backend:
service:
name: {{ $.Values.global.app_name }}-{{ $processName }}
port:
name: {{ $port_map.name }}
name: {{ include "primary.port" $config.web.port_maps }}
pathType: ImplementationSpecific
path: /
{{- end }}
{{- end }}
{{- end }}
{{- end }}