diff --git a/helm/mail/templates/hostname-script.yaml b/helm/mail/templates/hostname-script.yaml index cd0a742..649293f 100644 --- a/helm/mail/templates/hostname-script.yaml +++ b/helm/mail/templates/hostname-script.yaml @@ -1,3 +1,4 @@ +{{- else if .Values.GenerateHostName.enabled }} {{- $chart := "mail" -}} {{- $fullName := include (print $chart ".fullname") . -}} {{- $labels := include (print $chart ".labels") . -}} @@ -10,11 +11,10 @@ metadata: data: set_hostname.sh: | #!/usr/bin/env bash - - # Load the hostname from the file - if [ -f /var/worker-ip/hostname.txt ]; then - export POSTFIX_myhostname=$(cat /var/worker-ip/hostname.txt) - fi - - # Execute the main container command - /scripts/run.sh + # 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 aa8b794..4ef984d 100644 --- a/helm/mail/templates/statefulset.yaml +++ b/helm/mail/templates/statefulset.yaml @@ -48,32 +48,14 @@ spec: {{ with .Values.affinity }}affinity: {{- toYaml . | nindent 8 }} {{- end }} {{ with .Values.tolerations }}tolerations: {{- toYaml . | nindent 8 }} {{- end }} - {{- if or .Values.extraInitContainers .Values.GenerateHostName.enabled }} + {{- if .Values.extraInitContainers }} # # Init containers # initContainers: - {{- end }} - {{- if .Values.extraInitContainers}} {{- tpl .Values.extraInitContainers . | nindent 6 }} - {{- else if .Values.GenerateHostName.enabled }} - - name: get-public-ip - image: curlimages/curl:latest - command: ["/bin/sh", "-c"] - args: - - > - IP=$(curl http://ipinfo.io/ip); - IP=$(echo "$IP" | tr '.' '-') - PREFIX={{- .Values.GenerateHostName.prefix -}}; - DOMAIN={{- .Values.GenerateHostName.domain -}}; - echo "${PREFIX}-${IP}.${DOMAIN}" > /var/worker-ip/hostname.txt; - volumeMounts: - - mountPath: "/var/worker-ip" - name: {{ $fullName | quote }} - subPath: ip {{- end }} - # Allow up to 2 minutes for Postfix to flush / empty the queue before shutting down the container terminationGracePeriodSeconds: 120 containers: @@ -99,9 +81,6 @@ spec: {{- if .Values.lifecycle.postStart }} postStart: {{- toYaml .Values.lifecycle.postStart | nindent 14 }} {{- end }} - {{- if .Values.GenerateHostName.enabled }} - command: ["/var/generate-hostname/set_hostname.sh"] - {{- end }} envFrom: - configMapRef: name: {{ $fullName | quote }} @@ -154,10 +133,7 @@ spec: {{- end }} {{- if .Values.extraVolumeMounts }}{{- toYaml .Values.extraVolumeMounts | nindent 12 }}{{ end }} {{- if .Values.GenerateHostName.enabled }} - - mountPath: "/var/worker-ip" - name: {{ $fullName | quote }} - subPath: ip - - mountPath: "/var/generate-hostname" + - mountPath: "/docker-init.db/" name: hostname-init {{- end }} resources: {{ toYaml .Values.resources | nindent 12 }}