From 648d7bb175cebfeed4c636922fdee43df37bd483 Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 10 Oct 2025 15:31:35 +0800 Subject: [PATCH] Refactor Helm template to handle optional envFrom values safely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • 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 --- k8s-deploy/lightrag/templates/deployment.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/k8s-deploy/lightrag/templates/deployment.yaml b/k8s-deploy/lightrag/templates/deployment.yaml index e261cf27..d8dcfc34 100644 --- a/k8s-deploy/lightrag/templates/deployment.yaml +++ b/k8s-deploy/lightrag/templates/deployment.yaml @@ -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 }} \ No newline at end of file + {{- toYaml .Values.updateStrategy | nindent 4 }}