potiuk commented on code in PR #75945:
URL: https://github.com/apache/airflow/pull/75945#discussion_r4752862417


##########
chart/templates/dag-processor/dag-processor-serviceaccount.yaml:
##########
@@ -20,23 +20,43 @@
 #######################################
 ## Airflow Dag Processor ServiceAccount
 #######################################
-{{- if and .Values.dagProcessor.enabled 
.Values.dagProcessor.serviceAccount.create }}
+{{- if .Values.dagProcessor.enabled }}
+{{- $globals := deepCopy . -}}
+{{- $parentName := include "dagProcessor.serviceAccountName" . -}}
+{{- $rendered := dict -}}
+{{- range $dagProcessor := (include "dagProcessor.expandSets" . | 
fromYaml).dagProcessors -}}
+  {{- $_ := set $globals.Values "dagProcessor" $dagProcessor -}}
+  {{- with $globals -}}
+    {{- if .Values.dagProcessor.serviceAccount.create -}}
+      {{- $name := include "dagProcessor.serviceAccountName" . -}}
+      {{- $config := toJson (pick .Values.dagProcessor.serviceAccount 
"annotations" "automountServiceAccountToken") -}}
+      {{- if and (hasKey $rendered $name) (ne (get $rendered $name) $config) 
-}}
+        {{- fail (printf "Dag processor sets use the ServiceAccount %s with 
conflicting configuration" $name) -}}
+      {{- end -}}
+      {{- if not (hasKey $rendered $name) -}}
+        {{- $_ := set $rendered $name $config -}}
+        {{- $labels := ternary $.Values.dagProcessor.labels 
.Values.dagProcessor.labels (eq $name $parentName) }}
+---
 apiVersion: v1
 kind: ServiceAccount
 automountServiceAccountToken: {{ 
.Values.dagProcessor.serviceAccount.automountServiceAccountToken }}
 metadata:
-  name: {{ include "dagProcessor.serviceAccountName" . }}
+  name: {{ $name }}
   labels:
     tier: airflow
     component: dag-processor
     release: {{ .Release.Name }}
     chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
     heritage: {{ .Release.Service }}
-    {{- if or .Values.labels .Values.dagProcessor.labels }}
-      {{- mustMerge .Values.dagProcessor.labels .Values.labels | toYaml | 
nindent 4 }}
+    {{- if or .Values.labels $labels }}
+      {{- mustMerge (default dict $labels) .Values.labels | toYaml | nindent 4 
}}
     {{- end }}
-  {{- with .Values.dagProcessor.serviceAccount.annotations}}
+  {{- with .Values.dagProcessor.serviceAccount.annotations }}
   annotations:
     {{- include "airflow.tplDict" (dict "values" . "context" $) | nindent 4 }}

Review Comment:
   **Set ServiceAccount annotations are templated against the parent values**
   
   Inside the loop each set's merged values are in `$globals`, but the 
annotations are rendered with `"context" $`, the root context with the unmerged 
`dagProcessor`. With per-set ServiceAccounts, an inherited annotation such as 
`eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/{{ 
.Values.dagProcessor.serviceAccount.name }}` renders the parent's name for 
every set, so each set gets the parent's cloud identity instead of its own. The 
conflict check at line 32 also compares the raw, untemplated annotations. The 
same root `$` is passed at `dag-processor-deployment.yaml` 172 
(`waitForMigrations.env`) and 276 (`logGroomerSidecar.env`); before sets, `$` 
and `.` were the same. Pass `$globals` as the context in all three places, and 
compare the rendered annotations in the conflict check.
   
   *Flagged by codex and antigravity (adversarial review); cross-checked.*
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting



##########
chart/templates/dag-processor/dag-processor-deployment.yaml:
##########
@@ -165,8 +191,8 @@ spec:
           {{- if .Values.dagProcessor.command }}
           command: {{ tpl (toYaml .Values.dagProcessor.command) . | nindent 12 
}}
           {{- end }}
-          {{- if .Values.dagProcessor.args }}
-          args: {{ tpl (toYaml .Values.dagProcessor.args) . | nindent 12 }}
+          {{- if $args }}
+          args: {{ tpl (toYaml $args) . | nindent 12 }}

Review Comment:
   **Bundle names are inserted after `toYaml`**
   
   `args: {{ tpl (toYaml $args) . }}` serialises the default `args` first and 
expands `dagProcessor.bundleNameArgs` afterwards, inside a YAML plain scalar. 
The shell quoting from the last round handles `'`, but YAML never sees the 
name: a bundle named `a: b` turns `args[2]` into a mapping (rejected by the API 
server), and `a #b` truncates it at the comment, leaving a shell syntax error. 
Neither the chart schema nor core restricts bundle names. Expand the template 
before serialising (e.g. `tpl` each `args` item, then `toYaml` the result), or 
restrict bundle names in the schema.
   
   *Flagged by codex and antigravity (adversarial review); cross-checked.*
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting



##########
chart/templates/_helpers.yaml:
##########
@@ -1236,6 +1236,105 @@ Usage:
   {{- toYaml $outputMap -}}
 {{- end -}}
 
+{{/*
+Values of every Dag processor Deployment: the default one (named `default`) 
when enabled, followed by
+each item of `dagProcessor.sets` merged over `dagProcessor`. Fails on an 
invalid set configuration.
+Call it only when `dagProcessor.enabled` is true.
+
+Usage:
+  {{- $dagProcessors := (include "dagProcessor.expandSets" . | 
fromYaml).dagProcessors }}
+*/}}
+{{- define "dagProcessor.expandSets" -}}
+  {{- $sets := .Values.dagProcessor.sets | default list -}}
+  {{- $definedBundles := list -}}
+  {{- range .Values.dagProcessor.dagBundleConfigList | default list -}}
+    {{- $definedBundles = append $definedBundles .name -}}
+  {{- end -}}
+  {{- $seenSetNames := dict -}}
+  {{- range $sets -}}
+    {{- $setName := .name | default "" | toString -}}
+    {{- if eq $setName "default" -}}
+      {{- fail "`dagProcessor.sets` items cannot be named `default`; that name 
is used by the default Dag processor" -}}
+    {{- end -}}
+    {{- if not (and (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" $setName) 
(le (len $setName) 63)) -}}
+      {{- fail (printf "`dagProcessor.sets` item name %q is not a valid 
DNS-1123 label (lowercase alphanumerics and '-', starting and ending with an 
alphanumeric, at most 63 characters)" $setName) -}}
+    {{- end -}}
+    {{- if hasKey $seenSetNames $setName -}}
+      {{- fail (printf "`dagProcessor.sets` contains the name %q more than 
once" $setName) -}}
+    {{- end -}}
+    {{- $_ := set $seenSetNames $setName true -}}
+    {{- if hasKey . "dagBundleConfigList" -}}

Review Comment:
   **`enabled: false` on a set is ignored**
   
   The schema says a set can override any parent value except 
`dagBundleConfigList`, but `enabled` is only read from the root, so `enabled: 
false` on a set still deploys it. Skip such sets in `dagProcessor.expandSets`, 
or reject `enabled` there like `dagBundleConfigList`.
   
   *Flagged by antigravity (adversarial review); cross-checked.*
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting



##########
chart/templates/_helpers.yaml:
##########
@@ -1236,6 +1236,105 @@ Usage:
   {{- toYaml $outputMap -}}
 {{- end -}}
 
+{{/*
+Values of every Dag processor Deployment: the default one (named `default`) 
when enabled, followed by
+each item of `dagProcessor.sets` merged over `dagProcessor`. Fails on an 
invalid set configuration.
+Call it only when `dagProcessor.enabled` is true.
+
+Usage:
+  {{- $dagProcessors := (include "dagProcessor.expandSets" . | 
fromYaml).dagProcessors }}
+*/}}
+{{- define "dagProcessor.expandSets" -}}
+  {{- $sets := .Values.dagProcessor.sets | default list -}}
+  {{- $definedBundles := list -}}
+  {{- range .Values.dagProcessor.dagBundleConfigList | default list -}}
+    {{- $definedBundles = append $definedBundles .name -}}
+  {{- end -}}
+  {{- $seenSetNames := dict -}}
+  {{- range $sets -}}
+    {{- $setName := .name | default "" | toString -}}
+    {{- if eq $setName "default" -}}
+      {{- fail "`dagProcessor.sets` items cannot be named `default`; that name 
is used by the default Dag processor" -}}
+    {{- end -}}
+    {{- if not (and (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" $setName) 
(le (len $setName) 63)) -}}
+      {{- fail (printf "`dagProcessor.sets` item name %q is not a valid 
DNS-1123 label (lowercase alphanumerics and '-', starting and ending with an 
alphanumeric, at most 63 characters)" $setName) -}}
+    {{- end -}}
+    {{- if hasKey $seenSetNames $setName -}}
+      {{- fail (printf "`dagProcessor.sets` contains the name %q more than 
once" $setName) -}}
+    {{- end -}}
+    {{- $_ := set $seenSetNames $setName true -}}
+    {{- if hasKey . "dagBundleConfigList" -}}
+      {{- fail "`dagProcessor.sets` items cannot define `dagBundleConfigList`; 
define all bundles in `dagProcessor.dagBundleConfigList` and select them per 
set with `bundleNames`" -}}
+    {{- end -}}
+  {{- end -}}
+  {{- $enableDefault := .Values.dagProcessor.enableDefault -}}
+  {{- if kindIs "invalid" $enableDefault -}}
+    {{- $enableDefault = not $sets -}}
+  {{- end -}}
+  {{- if and (not $enableDefault) (not $sets) -}}
+    {{- fail "`dagProcessor.enableDefault` is false and `dagProcessor.sets` is 
empty, so no Dag processor would run; add a set, enable the default Dag 
processor, or set `dagProcessor.enabled` to false" -}}
+  {{- end -}}
+  {{- if $enableDefault -}}
+    {{- $sets = concat (list (dict "name" "default")) $sets -}}
+  {{- end -}}
+  {{- $dagProcessors := list -}}
+  {{- range $set := $sets -}}
+    {{- $dagProcessor := include "workersMergeValues" (list 
$.Values.dagProcessor $set) | fromYaml -}}

Review Comment:
   **`[]` on a set inherits the parent's list for every list value**
   
   `workersMergeValues` falls back to the parent whenever a set's list is 
empty. The docs now say so for `bundleNames`, but it applies to every list: a 
set that sets its own `command` (e.g. `[airflow, dag-processor, --bundle-name, 
b1]`) with `args: []` keeps the default `bash -c` args, passes the 
`--bundle-name` check, and fails at runtime; parent `tolerations`, `env`, 
`extraVolumes` and the like cannot be cleared on a set either. Document it for 
all lists (with `args: ~` as the way to drop args), or treat an explicit `[]` 
on a set as an override.
   
   *Flagged by antigravity (adversarial review); cross-checked.*
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to