From e95255b81084f0665d67c3776999d0d16b85a9cd Mon Sep 17 00:00:00 2001 From: Ariel Sosnovsky Date: Thu, 14 Mar 2024 13:15:51 -0400 Subject: [PATCH] fixing ingress for 2nd domain --- .../ingresses/templates/_helpers/domain.yaml | 11 +++ .../templates/_helpers/ingress.tls.yaml | 43 ++++++++++++ .../ingresses/templates/_helpers/ingress.yaml | 68 +++---------------- 3 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 k8s/apps/ingresses/templates/_helpers/domain.yaml create mode 100644 k8s/apps/ingresses/templates/_helpers/ingress.tls.yaml diff --git a/k8s/apps/ingresses/templates/_helpers/domain.yaml b/k8s/apps/ingresses/templates/_helpers/domain.yaml new file mode 100644 index 0000000..5f05cb0 --- /dev/null +++ b/k8s/apps/ingresses/templates/_helpers/domain.yaml @@ -0,0 +1,11 @@ +{{- define "homelab.ingress.domain" -}} + {{- if .useSecondaryDomain -}} + {{- "{{.prefix}}.{{.global.secondaryDomain}}" -}} + {{- else -}} + {{- if .useDirectPrefix -}} + {{- "{{.prefix}}.{{.global.domain}}" -}} + {{- else -}} + {{- "{{.prefix}}.{{.rootSubDomain}}.{{.global.domain}}" -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/k8s/apps/ingresses/templates/_helpers/ingress.tls.yaml b/k8s/apps/ingresses/templates/_helpers/ingress.tls.yaml new file mode 100644 index 0000000..24eb608 --- /dev/null +++ b/k8s/apps/ingresses/templates/_helpers/ingress.tls.yaml @@ -0,0 +1,43 @@ +{{ define "homelab.ingress.domain.tls"}} +{{ if (.useWildCard | default .global.tls.useWildCard) }} +--- +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: "tls-{{ .domain }}" + namespace: {{ .namespace }} +spec: + refreshInterval: 1h + secretStoreRef: + kind: ClusterSecretStore + name: apps-ingresses + target: + name: tls-{{ .domain }} + creationPolicy: Owner + deletionPolicy: Delete + data: + - secretKey: tls.crt + remoteRef: + key: cloudflare-wildcard.{{ .domain }} + property: tls.crt + - secretKey: tls.key + remoteRef: + key: cloudflare-wildcard.{{ .domain }} + property: tls.key +{{ else }} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: "tls-{{ .domain }}" + namespace: {{ .namespace }} +spec: + secretName: "tls-{{ .domain }}" + issuerRef: + kind: ClusterIssuer + name: "{{ .global.tls.issuer }}" + commonName: "{{ .domain }}" + dnsNames: + - "{{ .domain }}" +{{ end }} +{{ end }} \ No newline at end of file diff --git a/k8s/apps/ingresses/templates/_helpers/ingress.yaml b/k8s/apps/ingresses/templates/_helpers/ingress.yaml index 71201b8..bc638c7 100644 --- a/k8s/apps/ingresses/templates/_helpers/ingress.yaml +++ b/k8s/apps/ingresses/templates/_helpers/ingress.yaml @@ -11,67 +11,20 @@ # useWildCard: bool = False # middleware: str = "https-redirect" # -{{ if .useSecondaryDomain }} -{{ $domin := {{ .global.secondaryDomain }} }} -{{ else }} -{{ $domin := {{ .global.domain }} }} -{{ end }} -{{ if .useDirectPrefix }} -{{ $domin := printf "%s.%s" .prefix $domain }} -{{ else }} -{{ $domin := printf "%s.%s.%s" .prefix .rootSubDomain $domain }} -{{ end }} +{{ $domain := (include "homelab.ingress.domain" .) }} + +{{ $_ := set . "domain" $domain }} {{ if .global.tls.enabled }} -{{ if (.useWildCard | default .global.tls.useWildCard) }} ---- -apiVersion: external-secrets.io/v1beta1 -kind: ExternalSecret -metadata: - name: "tls-{{ $domin }}" - namespace: {{ .namespace }} -spec: - refreshInterval: 1h - secretStoreRef: - kind: ClusterSecretStore - name: apps-ingresses - target: - name: tls-{{ $domin }} - creationPolicy: Owner - deletionPolicy: Delete - data: - - secretKey: tls.crt - remoteRef: - key: cloudflare-wildcard.{{ $domin }} - property: tls.crt - - secretKey: tls.key - remoteRef: - key: cloudflare-wildcard.{{ $domin }} - property: tls.key -{{ else }} ---- -apiVersion: cert-manager.io/v1 -kind: Certificate -metadata: - name: "tls-{{ $domin }}" - namespace: {{ .namespace }} -spec: - secretName: "tls-{{ $domin }}" - issuerRef: - kind: ClusterIssuer - name: "{{ .global.tls.issuer }}" - commonName: "{{ $domin }}" - dnsNames: - - "{{ $domin }}" -{{ end }} +{{ include "homelab.ingress.domain.tls" . }} {{ end }} --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: "{{ $domin }}" + name: "{{ $domain }}" namespace: {{ .namespace }} annotations: homelab-ingress/managing-app-namespace: "apps-ingresses" @@ -92,7 +45,7 @@ metadata: {{ end }} spec: rules: - - host: "{{ $domin }}" + - host: "{{ $domain }}" http: paths: - backend: @@ -104,13 +57,8 @@ spec: pathType: Prefix {{ if .global.tls.enabled }} tls: - - secretName: "tls-{{ $domin }}" + - secretName: "tls-{{ $domain }}" hosts: - - "{{ $domin }}" + - "{{ $domain }}" {{ end }} - -{{ else }} - -{{ end }} - {{- end -}} \ No newline at end of file