Refactor Helm template to handle optional envFrom values safely
• Add null checks for envFrom fields • Support both secrets and configmaps • Build envFrom list dynamically • Only render envFrom when entries exist • Fix template indentation issues
This commit is contained in:
@@ -43,14 +43,17 @@ spec:
|
||||
- name: env-file
|
||||
mountPath: /app/.env
|
||||
subPath: .env
|
||||
envFrom:
|
||||
{{- range .Values.envFrom.secrets }}
|
||||
- secretRef:
|
||||
name: {{ .name }}
|
||||
{{- $envFrom := default (dict) .Values.envFrom }}
|
||||
{{- $envFromEntries := list }}
|
||||
{{- range (default (list) (index $envFrom "secrets")) }}
|
||||
{{- $envFromEntries = append $envFromEntries (dict "secretRef" (dict "name" .name)) }}
|
||||
{{- end }}
|
||||
{{- range .Values.envFrom.configmaps }}
|
||||
- configMapRef:
|
||||
name: {{ .name }}
|
||||
{{- range (default (list) (index $envFrom "configmaps")) }}
|
||||
{{- $envFromEntries = append $envFromEntries (dict "configMapRef" (dict "name" .name)) }}
|
||||
{{- end }}
|
||||
{{- if gt (len $envFromEntries) 0 }}
|
||||
envFrom:
|
||||
{{- toYaml $envFromEntries | nindent 12 }}
|
||||
{{- end }}
|
||||
{{- with .Values.image.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
@@ -75,4 +78,4 @@ spec:
|
||||
{{- end }}
|
||||
|
||||
strategy:
|
||||
{{- toYaml .Values.updateStrategy | nindent 4 }}
|
||||
{{- toYaml .Values.updateStrategy | nindent 4 }}
|
||||
|
||||
Reference in New Issue
Block a user