@@ -59,17 +59,23 @@ spec:
5959 bun run db:migrate
6060 {{- /*
6161 The account token backfill script migration seals with the app's key and honors its
62- ENCRYPT_ACCOUNT_TOKENS opt-out, read the way the app container reads them; without a
63- usable key it does nothing and stays pending.
62+ ENCRYPT_ACCOUNT_TOKENS opt-out. Each resolves as it does on the app container : the last
63+ matching entry of the app's inline overrides (envDefaults, existingSecret inlining,
64+ extraEnvVars), else the app Secret. Without a usable key the step stays pending.
6465 */}}
6566 env :
66- {{- $useExistingSecret := and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }}
67+ {{- $appOverrides := include "sim.appEnvOverrides" . | fromYamlArray }}
6768 {{- range $key := list "ENCRYPTION_KEY" "ENCRYPT_ACCOUNT_TOKENS" }}
68- {{- $inline := index ($.Values.app.env | default dict) $key }}
69- - name : {{ $key }}
70- {{- if and $useExistingSecret (ne (toString $inline) "") (ne (toString $inline) "<nil>") }}
71- value : {{ $inline | quote }}
69+ {{- $override := dict }}
70+ {{- range $appOverrides }}
71+ {{- if eq (toString .name) $key }}
72+ {{- $override = . }}
73+ {{- end }}
74+ {{- end }}
75+ {{- if $override }}
76+ - {{ toYaml $override | nindent 14 | trim }}
7277 {{- else }}
78+ - name : {{ $key }}
7379 valueFrom :
7480 secretKeyRef :
7581 name : {{ include "sim.appSecretName" $ }}
@@ -111,42 +117,6 @@ spec:
111117 value : {{ include "sim.ollamaUrl" . | quote }}
112118 - name : PII_URL
113119 value : {{ include "sim.piiUrl" . | quote }}
114- {{- /*
115- Skip envDefaults keys that the user has explicitly overridden in app.env
116- with a non-empty value. K8s `env` takes precedence over `envFrom`, so an
117- inline default would otherwise mask the user's Secret-bound value.
118- Also skip envDefaults entirely in existingSecret mode : the pre-existing
119- Secret is the source of truth, and inlining localhost URL defaults would
120- silently shadow keys (NEXT_PUBLIC_APP_URL, BETTER_AUTH_URL, etc.) the
121- user stored in their Secret but left empty in app.env.
122- */}}
123- {{- $appEnv := .Values.app.env | default dict }}
124- {{- $useExistingSecret := and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }}
125- {{- if not $useExistingSecret }}
126- {{- range $key, $value := .Values.app.envDefaults | default dict }}
127- {{- $override := index $appEnv $key }}
128- {{- if and (ne (toString $value) "") (ne (toString $value) "<nil>") (or (not $override) (eq (toString $override) "") (eq (toString $override) "<nil>")) }}
129- - name : {{ $key }}
130- value : {{ $value | quote }}
131- {{- end }}
132- {{- end }}
133- {{- end }}
134- {{- /*
135- In existingSecret mode the chart-managed Secret is not rendered, so
136- non-empty values in app.env would otherwise go nowhere — inline them
137- here so the user's overrides actually reach the pod. Skipped in ESO
138- mode (ESO is the source of truth; inlining would mask the synced value)
139- and in inline mode (values flow through the chart-managed Secret).
140- */}}
141- {{- if and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }}
142- {{- $chartComputed := list "DATABASE_URL" "SOCKET_SERVER_URL" "OLLAMA_URL" "PII_URL" }}
143- {{- range $key, $value := $appEnv }}
144- {{- if and (ne (toString $value) "") (ne (toString $value) "<nil>") (not (has $key $chartComputed)) }}
145- - name : {{ $key }}
146- value : {{ $value | quote }}
147- {{- end }}
148- {{- end }}
149- {{- end }}
150120 {{- if .Values.telemetry.enabled }}
151121 {{- $nodeEnv := default (default "production" (index (.Values.app.envDefaults | default dict) "NODE_ENV")) (index (.Values.app.env | default dict) "NODE_ENV") }}
152122 # OpenTelemetry configuration
@@ -159,9 +129,8 @@ spec:
159129 - name : OTEL_RESOURCE_ATTRIBUTES
160130 value : " service.name=sim-app,service.version={{ .Chart.AppVersion }},deployment.environment={{ $nodeEnv }}"
161131 {{- end }}
162- {{- with .Values.extraEnvVars }}
163- {{- toYaml . | nindent 12 }}
164- {{- end }}
132+ {{- /* Operator overrides last, so they win over the defaults above and over envFrom. */}}
133+ {{- include "sim.appEnvOverrides" . | trim | nindent 12 }}
165134 envFrom :
166135 # Bundled Redis URL. Listed FIRST so any operator-supplied REDIS_URL
167136 # in a later source overrides it — see templates/configmap-redis.yaml.
0 commit comments