Abstract away certificate creation to support ingress (#195)

This commit is contained in:
Kjeld Schouten-Lebbing
2021-02-28 22:16:07 +01:00
committed by kjeld Schouten-Lebbing
parent cb4d70764b
commit 77ff7306af
7 changed files with 27 additions and 16 deletions
+1 -1
View File
@@ -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
-1
View File
@@ -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 -}}
@@ -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 }}
@@ -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 }}
@@ -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 }}
@@ -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 -}}
@@ -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 -}}