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


##########
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:
   Fixed in 4dfc046f90. The annotations are now rendered with the set's merged 
values, and so are
   `waitForMigrations.env` and `logGroomerSidecar.env` in the Deployment. With
   `role: "{{ .Values.dagProcessor.serviceAccount.name }}"` on the parent and a 
set using the
   ServiceAccount `team-a`, the set's ServiceAccount now gets `role: team-a`. 
The conflict check compares
   the rendered annotations, so two sets that share a ServiceAccount name but 
render different annotations
   fail at render time.
   
   On kind (Kubernetes v1.31.12) with four sets and the parent values above, 
the ServiceAccounts `team-a` and
   `team-b` got `role: team-a` and `role: team-b`, and `SET_NAME` in the init 
container and the log groomer
   was the set's own name in all four set Pods.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by `xchwan` 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:
   Fixed in 4dfc046f90. Each `args` item is now templated first and serialized 
with `toYaml` afterwards,
   so YAML quotes what `dagProcessor.bundleNameArgs` inserts. Bundle names `a: 
b` and `a #b` render a
   valid manifest, and `shlex.split` of the rendered command gives back the 
exact name (tested). With the
   default values, the rendered Deployment is unchanged.
   
   On kind, sets selecting bundles named `a: b` and `a #b` rendered the args
   `exec airflow dag-processor --bundle-name 'a: b'` and `... 'a #b'` as one 
item each, started with 0
   restarts, and their Dags were listed under those exact bundle names and ran 
to success. Core logs
   `Invalid stat name` once for each of these names (metric names do not allow 
`:` or `#`); parsing and runs
   are not affected.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by `xchwan` 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:
   Documented for every list in `manage-dag-files.rst`, `values.yaml` and the 
schema: a non-empty list
   replaces the inherited one, and an empty list keeps it. I kept the 
`workers.celery.sets` merge semantics
   so both kinds of sets behave the same. To run a set with its own `command` 
and without the parent `args`,
   set `args: ~` on it; I checked that this drops the args, while `args: []` 
keeps the parent's `bash -c`.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by `xchwan` 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` on a set now fails at render time, like `dagBundleConfigList`: 
"`dagProcessor.sets` items
   cannot define `enabled`; remove the set from `dagProcessor.sets` to stop 
deploying it". The schema,
   `values.yaml` and the docs say so as well.
   
   ---
   Drafted-by: Claude Code (Opus 5.5); reviewed by `xchwan` 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