diff --git a/charts/dify/Chart.yaml b/charts/dify/Chart.yaml index 4d6fd11..c87692c 100644 --- a/charts/dify/Chart.yaml +++ b/charts/dify/Chart.yaml @@ -20,7 +20,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.10.0 +version: 0.10.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/dify/templates/_helpers.tpl b/charts/dify/templates/_helpers.tpl index 3e69ea6..a6fc25a 100644 --- a/charts/dify/templates/_helpers.tpl +++ b/charts/dify/templates/_helpers.tpl @@ -206,4 +206,47 @@ commonBackendEnvs are for api and worker containers value: http://{{ include "dify.fullname" . }}-api-svc:{{ .Values.api.service.port }} {{- end }} +{{- end }} + +{{/* +Container env assembly. + +A container's `env` is a strategic-merge list keyed by `name`. Emitting the same +name twice (e.g. a var already in api.envs also set via global.extraBackendEnvs) +is tolerated by the container runtime — last value wins — but breaks the +strategic-merge diff used by `kubectl apply`, `helm upgrade`, and ArgoCD. The +helpers below assemble each container's env in the existing upstream order and +then de-duplicate, keeping the last occurrence of each name (same last-wins rule +the runtime already applied) so the effective environment is unchanged while the +rendered list stays well-formed. +*/}} +{{- define "dify.dedupeEnv" -}} +{{- $items := .items -}} +{{- $last := dict -}} +{{- range $items -}}{{- $_ := set $last .name . -}}{{- end -}} +{{- $order := list -}} +{{- range $items -}}{{- if not (has .name $order) -}}{{- $order = append $order .name -}}{{- end -}}{{- end -}} +{{- $out := list -}} +{{- range $order -}}{{- $out = append $out (index $last .) -}}{{- end -}} +{{- toYaml $out -}} +{{- end }} + +{{- define "dify.backendEnvs" -}} +{{- $ctx := .ctx -}} +{{- $items := concat + (include "dify.commonEnvs" $ctx | fromYamlArray) + (include "dify.commonBackendEnvs" $ctx | fromYamlArray) + ($ctx.Values.global.extraEnvs | default list) + ($ctx.Values.global.extraBackendEnvs | default list) + (.componentEnvs | default list) -}} +{{- include "dify.dedupeEnv" (dict "items" $items) -}} +{{- end }} + +{{- define "dify.frontendEnvs" -}} +{{- $ctx := .ctx -}} +{{- $items := concat + (include "dify.commonEnvs" $ctx | fromYamlArray) + ($ctx.Values.global.extraEnvs | default list) + (.componentEnvs | default list) -}} +{{- include "dify.dedupeEnv" (dict "items" $items) -}} {{- end }} \ No newline at end of file diff --git a/charts/dify/templates/deployment.yaml b/charts/dify/templates/deployment.yaml index fb823ab..8013fe2 100644 --- a/charts/dify/templates/deployment.yaml +++ b/charts/dify/templates/deployment.yaml @@ -43,17 +43,7 @@ spec: env: - name: MODE value: "api" - {{- include "dify.commonEnvs" . | nindent 12 }} - {{- include "dify.commonBackendEnvs" . | nindent 12 }} - {{- with .Values.global.extraEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.global.extraBackendEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.api.envs }} - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "dify.backendEnvs" (dict "ctx" . "componentEnvs" .Values.api.envs) | nindent 12 }} {{- with .Values.volumeMounts }} volumeMounts: {{- toYaml . | nindent 12 }} @@ -136,17 +126,7 @@ spec: env: - name: MODE value: "worker" - {{- include "dify.commonEnvs" . | nindent 12 }} - {{- include "dify.commonBackendEnvs" . | nindent 12 }} - {{- with .Values.global.extraEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.global.extraBackendEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.worker.envs }} - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "dify.backendEnvs" (dict "ctx" . "componentEnvs" .Values.worker.envs) | nindent 12 }} {{- with .Values.volumeMounts }} volumeMounts: {{- toYaml . | nindent 12 }} @@ -224,17 +204,7 @@ spec: env: - name: MODE value: "beat" - {{- include "dify.commonEnvs" . | nindent 12 }} - {{- include "dify.commonBackendEnvs" . | nindent 12 }} - {{- with .Values.global.extraEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.global.extraBackendEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.workerBeat.envs }} - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "dify.backendEnvs" (dict "ctx" . "componentEnvs" .Values.workerBeat.envs) | nindent 12 }} {{- with .Values.volumeMounts }} volumeMounts: {{- toYaml . | nindent 12 }} @@ -309,13 +279,7 @@ spec: image: "{{ .Values.frontend.image.repository }}:{{ coalesce .Values.frontend.image.tag .Values.global.image.tag .Chart.AppVersion }}" imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} env: - {{- include "dify.commonEnvs" . | nindent 12 }} - {{- with .Values.global.extraEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.frontend.envs }} - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "dify.frontendEnvs" (dict "ctx" . "componentEnvs" .Values.frontend.envs) | nindent 12 }} ports: - name: http containerPort: {{ .Values.frontend.containerPort }} @@ -510,17 +474,7 @@ spec: value: {{ .Values.pluginDaemon.difyInnerApiKey | quote }} {{- else }} {{- end }} - {{- include "dify.commonEnvs" . | nindent 12 }} - {{- include "dify.commonBackendEnvs" . | nindent 12 }} - {{- with .Values.global.extraEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.global.extraBackendEnvs }} - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.pluginDaemon.envs }} - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "dify.backendEnvs" (dict "ctx" . "componentEnvs" .Values.pluginDaemon.envs) | nindent 12 }} volumeMounts: - name: plugin-daemon-storage mountPath: /app/storage