From 77ff7306afc954d37bb583875a9e96a65d64757f Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Sun, 28 Feb 2021 22:16:07 +0100 Subject: [PATCH] Abstract away certificate creation to support ingress (#195) --- library/common/Chart.yaml | 2 +- library/common/templates/_all.tpl | 1 - .../classes/ingress/_appIngressHTTP.tpl | 2 +- .../classes/ingress/_appIngressTCP.tpl | 2 +- .../templates/lib/resources/_appingress.tpl | 5 +++- .../templates/lib/resources/_certHelpers.tpl | 8 +++---- .../templates/lib/resources/_certSecret.yaml | 23 +++++++++++++------ 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index e63273841cf..581c6243025 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 kubeVersion: ">=1.16.0-0" name: common -version: 1.4.0 +version: 1.5.0 # upstream_version: 3.0.1 # appVersion: description: Function library for TrueCharts diff --git a/library/common/templates/_all.tpl b/library/common/templates/_all.tpl index 7b66ceb7e41..f3157f15631 100644 --- a/library/common/templates/_all.tpl +++ b/library/common/templates/_all.tpl @@ -37,5 +37,4 @@ Main entrypoint for the common library chart. It will render all underlying temp {{- print "---" | nindent 0 -}} {{ include "common.appIngress" . | nindent 0 }} {{ include "common.storage.permissions" . | nindent 0 }} - {{ include "common.resources.cert.secret" . | nindent 0 }} {{- end -}} diff --git a/library/common/templates/classes/ingress/_appIngressHTTP.tpl b/library/common/templates/classes/ingress/_appIngressHTTP.tpl index 51a6a51244c..7f60b10505d 100644 --- a/library/common/templates/classes/ingress/_appIngressHTTP.tpl +++ b/library/common/templates/classes/ingress/_appIngressHTTP.tpl @@ -51,7 +51,7 @@ spec: {{ else if eq $values.certType "existingcert" }} secretName: {{ $values.existingcert }} {{ else if eq $values.certType "ixcert" }} - secretName: {{ include "common.names.fullname" . }}-ix-cert + secretName: {{ $IngressName }} {{ else if eq $values.certType "wildcard" }} secretName: wildcardcert {{ else }} diff --git a/library/common/templates/classes/ingress/_appIngressTCP.tpl b/library/common/templates/classes/ingress/_appIngressTCP.tpl index f301ee782d6..2ed8a834923 100644 --- a/library/common/templates/classes/ingress/_appIngressTCP.tpl +++ b/library/common/templates/classes/ingress/_appIngressTCP.tpl @@ -52,7 +52,7 @@ spec: {{ else if eq $values.certType "existingcert" }} secretName: {{ $values.existingcert }} {{ else if eq $values.certType "ixcert" }} - secretName: {{ include "common.names.fullname" . }}-ix-cert + secretName: {{ $IngressName }} {{ else if eq $values.certType "wildcard" }} secretName: wildcardcert {{ else }} diff --git a/library/common/templates/lib/resources/_appingress.tpl b/library/common/templates/lib/resources/_appingress.tpl index 7ad37560b08..aa95eb48972 100644 --- a/library/common/templates/lib/resources/_appingress.tpl +++ b/library/common/templates/lib/resources/_appingress.tpl @@ -11,7 +11,7 @@ Renders the additional ingress objects from appIngress {{- if not $ingressValues.nameSuffix -}} {{- $_ := set $ingressValues "nameSuffix" $name -}} {{ end -}} - {{- $_ := set $ "ObjectValues" (dict "appIngress" $ingressValues) -}} + {{- $_ := set $ "ObjectValues" (dict "appIngress" $ingressValues) -}} {{- if $ingressValues.type -}} {{- if eq $ingressValues.type "UDP" -}} {{- include "common.classes.appIngressUDP" $ }} @@ -29,6 +29,9 @@ Renders the additional ingress objects from appIngress {{- include "common.classes.appAuthForward" $ }} {{- end }} {{- end }} + {{- $_ := set $ "ObjectValues" (dict "certHolder" $ingressValues) -}} + {{- print ("---") | nindent 0 -}} + {{- include "common.resources.cert.secret" $ }} {{- end }} {{- end }} {{- end }} diff --git a/library/common/templates/lib/resources/_certHelpers.tpl b/library/common/templates/lib/resources/_certHelpers.tpl index b9ecaa6d536..d2b07a9b7d1 100644 --- a/library/common/templates/lib/resources/_certHelpers.tpl +++ b/library/common/templates/lib/resources/_certHelpers.tpl @@ -2,9 +2,9 @@ Retrieve true/false if certificate is configured */}} {{- define "common.resources.cert.available" -}} -{{- if .Values.certificate -}} +{{- if .ObjectValues.certHolder.certificate -}} {{- $values := (. | mustDeepCopy) -}} -{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.Values.certificate) -}} +{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.ObjectValues.certHolder.certificate) -}} {{- template "common.resources.cert_present" $values -}} {{- else -}} {{- false -}} @@ -17,7 +17,7 @@ Retrieve public key of certificate */}} {{- define "common.resources.cert.publicKey" -}} {{- $values := (. | mustDeepCopy) -}} -{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.Values.certificate "publicKey" true) -}} +{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.ObjectValues.certHolder.certificate "publicKey" true) -}} {{ include "common.resources.cert" $values }} {{- end -}} @@ -27,6 +27,6 @@ Retrieve private key of certificate */}} {{- define "common.resources.cert.privateKey" -}} {{- $values := (. | mustDeepCopy) -}} -{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.Values.certificate) -}} +{{- $_ := set $values "commonCertOptions" (dict "certKeyName" $values.ObjectValues.certHolder.certificate) -}} {{ include "common.resources.cert" $values }} {{- end -}} diff --git a/library/common/templates/lib/resources/_certSecret.yaml b/library/common/templates/lib/resources/_certSecret.yaml index 3f09ac712c3..308b55e0e0e 100644 --- a/library/common/templates/lib/resources/_certSecret.yaml +++ b/library/common/templates/lib/resources/_certSecret.yaml @@ -1,14 +1,23 @@ {{- define "common.resources.cert.secret" -}} -{{ if eq (include "common.resources.cert.available" .) "true" }} ---- + + +{{- $secretName := include "common.names.fullname" . -}} + +{{- if .ObjectValues.certHolder -}} + {{- $secretName = printf "%v-%v" $secretName .ObjectValues.certHolder.nameSuffix -}} +{{ else }} + {{- $_ := set $ "ObjectValues" (dict "certHolder" .Values) -}} +{{ end -}} + +{{- if eq (include "common.resources.cert.available" $ ) "true" -}} apiVersion: v1 kind: Secret metadata: - name: {{ include "common.names.fullname" . }}-ix-cert + name: {{ $secretName }} labels: {{ include "common.labels" . | nindent 4 }} type: kubernetes.io/tls data: - tls.crt: {{ (include "common.resources.cert.publicKey" .) | toString | b64enc | quote }} - tls.key: {{ (include "common.resources.cert.privateKey" .) | toString | b64enc | quote }} -{{ end }} -{{- end }} + tls.crt: {{ (include "common.resources.cert.publicKey" $ ) | toString | b64enc | quote }} + tls.key: {{ (include "common.resources.cert.privateKey" $ ) | toString | b64enc | quote }} +{{- end -}} +{{- end -}}