Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate dynamic myhostname for each pod #165

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions helm/mail/templates/hostname-script.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- $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

# 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
1 change: 0 additions & 1 deletion helm/mail/templates/service-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ spec:
selector:
matchLabels:
app.kubernetes.io/instance: {{ $chart }}
prometheus: unknown
{{- end -}}
{{- end -}}
36 changes: 35 additions & 1 deletion helm/mail/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,32 @@ spec:
{{ with .Values.affinity }}affinity: {{- toYaml . | nindent 8 }} {{- end }}
{{ with .Values.tolerations }}tolerations: {{- toYaml . | nindent 8 }} {{- end }}

{{- if .Values.extraInitContainers }}
{{- if or .Values.extraInitContainers .Values.GenerateHostName.enabled }}
#
# 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 @@ -81,6 +99,9 @@ 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 @@ -132,6 +153,13 @@ spec:
readOnly: true
{{- 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"
name: hostname-init
{{- end }}
resources: {{ toYaml .Values.resources | nindent 12 }}
{{- if .Values.metrics.enabled }}
- name: exporter
Expand Down Expand Up @@ -218,6 +246,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:
Expand Down
7 changes: 7 additions & 0 deletions helm/mail/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ 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.
Expand Down