Allow setting existing secret name for TLS certs (#233)

* allow change of cert secret name

* change to helpers.tpl

* update secretName

* fix certname

* fix name of default

* set static name

* Removing comment

* update Readme and set cert name as ${mail.fullname}

* update test file name

* add create

* Removing the certs.existing. As this was not setup to be used.

* Update to allow setting only existingSecret or certs.create

* allow existing secret to add certs script

---------

Co-authored-by: nicholasm <nicholas.matters@prontocloud.com.au>
This commit is contained in:
mrskul 2025-07-29 20:59:03 +10:00 committed by GitHub
parent a47f941243
commit bbe209cea2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 23 additions and 8 deletions

View file

@ -640,7 +640,8 @@ Chart configuration is as follows:
| `nodeSelector` | `{}` | Standard Kubernetes stuff | | `nodeSelector` | `{}` | Standard Kubernetes stuff |
| `tolerations` | `[]` | Standard Kubernetes stuff | | `tolerations` | `[]` | Standard Kubernetes stuff |
| `affinity` | `{}` | Standard Kubernetes stuff | | `affinity` | `{}` | Standard Kubernetes stuff |
| `certs.create` | `{}` | Auto generate TLS certificates for Postfix | | `certs.create` | `false` | Auto generate TLS certificates for Postfix |
| `certs.existingSecret` | `""` | Existing secret containing the TLS certificates for Postfix |
| `extraVolumes` | `[]` | Append any extra volumes to the pod | | `extraVolumes` | `[]` | Append any extra volumes to the pod |
| `extraVolumeMounts` | `[]` | Append any extra volume mounts to the postfix container | | `extraVolumeMounts` | `[]` | Append any extra volume mounts to the postfix container |
| `extraInitContainers` | `[]` | Execute any extra init containers on startup | | `extraInitContainers` | `[]` | Execute any extra init containers on startup |

View file

@ -76,3 +76,14 @@ checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . |
configmap.reloader.stakater.com/reload: "{{ include "mail.fullname" . }}" configmap.reloader.stakater.com/reload: "{{ include "mail.fullname" . }}"
{{- end -}} {{- end -}}
{{/*
Return the secret containing HTTPS/TLS certificates
*/}}
{{- define "tls.secretName" -}}
{{- $secretName := .Values.certs.existingSecret -}}
{{- if $secretName -}}
{{- printf "%s" (tpl $secretName .) -}}
{{- else -}}
{{- printf "%s-certs" (include "mail.fullname" .) -}}
{{- end -}}
{{- end -}}

View file

@ -16,7 +16,7 @@ data:
{{- range $key, $value := .Values.config.opendkim }} {{- range $key, $value := .Values.config.opendkim }}
OPENDKIM_{{ $key }}: {{ $value | quote }} OPENDKIM_{{ $key }}: {{ $value | quote }}
{{- end }} {{- end }}
{{- if .Values.certs.create }} {{- if or .Values.certs.create .Values.certs.existingSecret }}
_enable_tls.sh: | _enable_tls.sh: |
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e

View file

@ -10,7 +10,7 @@ apiVersion: v1
kind: Secret kind: Secret
type: kubernetes.io/tls type: kubernetes.io/tls
metadata: metadata:
name: {{ $fullName }}-certs name: {{ include "tls.secretName" . }}
labels: labels:
{{- $labels | nindent 4 }} {{- $labels | nindent 4 }}
annotations: annotations:

View file

@ -117,7 +117,7 @@ spec:
subPath: logrotate.sh subPath: logrotate.sh
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if .Values.certs.create }} {{- if or .Values.certs.create .Values.certs.existingSecret }}
- name: certs - name: certs
mountPath: /var/run/certs mountPath: /var/run/certs
readOnly: true readOnly: true
@ -189,14 +189,14 @@ spec:
volumes: volumes:
- name: tmp - name: tmp
emptyDir: {} emptyDir: {}
{{- if .Values.certs.create }} {{- if or .Values.certs.create .Values.certs.existingSecret }}
- name: certs-init - name: certs-init
configMap: configMap:
name: {{ $fullName }} name: {{ $fullName }}
defaultMode: 0755 defaultMode: 0755
- name: certs - name: certs
secret: secret:
secretName: {{ $fullName }}-certs secretName: {{ include "tls.secretName" . }}
{{- end }} {{- end }}
# Socket directories # Socket directories
{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }} {{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}

View file

@ -138,8 +138,8 @@ container:
certs: certs:
# Auto-generate certificates for the server and mount them into Postfix volume # Auto-generate certificates for the server and mount them into Postfix volume
create: false create: false
# Provide existing cert # Provide existing secret name
existing: false existingSecret: ""
# Define data which should be stored in a Secret # Define data which should be stored in a Secret
# (and shared with the pod as environment variables) # (and shared with the pod as environment variables)

View file

@ -0,0 +1,3 @@
certs:
create: false
existingSecret: "controller-generated-secret"