diff --git a/helm/mail/templates/hostname-script.yaml b/helm/mail/templates/hostname-script.yaml new file mode 100644 index 0000000..70a2ea5 --- /dev/null +++ b/helm/mail/templates/hostname-script.yaml @@ -0,0 +1,20 @@ +{{- if .Values.GenerateHostName.enabled }} +{{- $chart := "mail" -}} +{{- $fullName := include (print $chart ".fullname") . -}} +{{- $labels := include (print $chart ".labels") . -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: hostname-init + labels: + {{- $labels | nindent 4 }} +data: + set_hostname.sh: | + #!/usr/bin/env bash + # This should be placed under /docker-init.db/set_hostname.sh + IP=$(curl http://ipinfo.io/ip) + IP=$(echo "$IP" | tr '.' '-') + PREFIX={{- .Values.GenerateHostName.prefix -}}; + DOMAIN={{- .Values.GenerateHostName.domain -}}; + postconf -e "myhostname=${PREFIX}-${IP}.${DOMAIN}" +{{- end }} \ No newline at end of file diff --git a/helm/mail/templates/statefulset.yaml b/helm/mail/templates/statefulset.yaml index 7b3ef7e..4ef984d 100644 --- a/helm/mail/templates/statefulset.yaml +++ b/helm/mail/templates/statefulset.yaml @@ -132,6 +132,10 @@ spec: readOnly: true {{- end }} {{- if .Values.extraVolumeMounts }}{{- toYaml .Values.extraVolumeMounts | nindent 12 }}{{ end }} + {{- if .Values.GenerateHostName.enabled }} + - mountPath: "/docker-init.db/" + name: hostname-init + {{- end }} resources: {{ toYaml .Values.resources | nindent 12 }} {{- if .Values.metrics.enabled }} - name: exporter @@ -218,6 +222,12 @@ spec: name: {{ print $fullName "-scripts" | quote }} defaultMode: 0777 {{- end }} + {{- if .Values.GenerateHostName.enabled }} + - name: hostname-init + configMap: + name: hostname-init + defaultMode: 0777 + {{- end }} {{- if .Values.extraVolumes }}{{- toYaml .Values.extraVolumes | nindent 8 }}{{ end }} {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} volumeClaimTemplates: diff --git a/helm/mail/values.yaml b/helm/mail/values.yaml index 2efa6a9..d1046ad 100644 --- a/helm/mail/values.yaml +++ b/helm/mail/values.yaml @@ -152,6 +152,12 @@ mountSecret: # < redacted > # -----END RSA PRIVATE KEY----- +# if the following is true, config.prefix.myhostname should not be set +GenerateHostName: + enabled: false + domain: example.com + prefix: smtp + config: general: {} # e.g.