Skip to content

Commit

Permalink
Try doing it better
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathon2nd committed Dec 29, 2023
1 parent 3f18892 commit f8ca5ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
16 changes: 8 additions & 8 deletions helm/mail/templates/hostname-script.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- else if .Values.GenerateHostName.enabled }}
{{- $chart := "mail" -}}
{{- $fullName := include (print $chart ".fullname") . -}}
{{- $labels := include (print $chart ".labels") . -}}
Expand All @@ -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 }}
28 changes: 2 additions & 26 deletions helm/mail/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down

0 comments on commit f8ca5ad

Please sign in to comment.