Skip to content

[Helm]Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names#64763

Merged
jscheffl merged 6 commits intoapache:mainfrom
shlomitubul:tpl-render-sa-annotations-and-metadata
Apr 12, 2026
Merged

[Helm]Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names#64763
jscheffl merged 6 commits intoapache:mainfrom
shlomitubul:tpl-render-sa-annotations-and-metadata

Conversation

@shlomitubul
Copy link
Copy Markdown
Contributor

@shlomitubul shlomitubul commented Apr 6, 2026

The scheduler ServiceAccount already tpl-renders annotations via range/tpl, but all other ServiceAccounts (pgbouncer, webserver, workers, triggerer, dag-processor, api-server) use raw toYaml. This makes it impossible to use template expressions like
{{ .Values.global.appName }}-sa@project.iam.gserviceaccount.com in annotation values for those components.

Apply the same range/tpl pattern from the scheduler to all ServiceAccount templates for consistency.

Also tpl-render data.metadataConnection.user and
data.metadataConnection.db so wrapper charts can derive database credentials from template expressions instead of requiring static values. This affects the metadata connection secret and pgbouncer config.

Also tpl-render webserverConfigConfigMapName and
apiServerConfigConfigMapName so wrapper charts can use {{ .Release.Name }}-custom-config instead of hardcoding the release name.

All changes are backward compatible: tpl on a plain string without template expressions returns the string unchanged.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    Generated-by: Claude Code (Anthropic Claude Opus 4.6) following the guidelines

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 6, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg bot added the area:helm-chart Airflow Helm Chart label Apr 6, 2026
@shlomitubul shlomitubul changed the title Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names [Helm]Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names Apr 6, 2026
@shlomitubul shlomitubul force-pushed the tpl-render-sa-annotations-and-metadata branch from 5e77629 to 3816392 Compare April 6, 2026 15:26
…on, and config ConfigMap names

The scheduler ServiceAccount already tpl-renders annotations via
range/tpl, but all other ServiceAccounts (pgbouncer, webserver, workers,
triggerer, dag-processor, api-server) use raw toYaml. This makes it
impossible to use template expressions like
{{ .Values.global.appName }}-sa@project.iam.gserviceaccount.com in
annotation values for those components.

Apply the same range/tpl pattern from the scheduler to all ServiceAccount
templates for consistency.

Also tpl-render data.metadataConnection.user and
data.metadataConnection.db so wrapper charts can derive database
credentials from template expressions instead of requiring static values.
This affects the metadata connection secret and pgbouncer config.

Also tpl-render webserverConfigConfigMapName and
apiServerConfigConfigMapName so wrapper charts can use
{{ .Release.Name }}-custom-config instead of hardcoding the release name.

All changes are backward compatible: tpl on a plain string without
template expressions returns the string unchanged.
@shlomitubul shlomitubul force-pushed the tpl-render-sa-annotations-and-metadata branch from 3816392 to 3e7fda5 Compare April 6, 2026 15:28
@shlomitubul shlomitubul requested a review from jscheffl April 6, 2026 15:31
Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for me, leavinf review to another pair of eyes prior merge.

@jscheffl jscheffl added the backport-to-chart/v1-2x-test Automatic backport to chart 1.2x maintenance branch label Apr 6, 2026
@Miretpl
Copy link
Copy Markdown
Contributor

Miretpl commented Apr 7, 2026

Also, looking at the tests, I would recommend configuring prek for running hooks before commit and push - you can find a guide here -> https://github.com/apache/airflow/blob/main/contributing-docs/03_contributors_quick_start.rst#id9

… files

- Remove nindent from tplDict helper, move indent to call sites
- Move SA annotation tpl tests to test_annotations.py
- Move metadataConnection tpl tests to test_metadata_connection_secret.py
- Split Airflow 2/3 version tests into separate parametrized cases
- Remove conditional logic from tests per review feedback
- Fix result-backend nit (remove unnecessary parens)
- Delete test_tpl_rendering.py (tests relocated)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shlomitubul
Copy link
Copy Markdown
Contributor Author

@Miretpl Thanks for the thorough review! All feedback addressed in the latest commit:

  • tplDict helper: Removed nindent — now generic, indent controlled at call sites
  • Tests restructured: Deleted test_tpl_rendering.py, moved annotation tests to test_annotations.py and metadata connection tests to test_metadata_connection_secret.py
  • No conditional test logic: Split Airflow 2.x/3.x into separate parametrized test methods
  • result-backend nit: Fixed

Will also set up pre-commit hooks as suggested. Thanks!

@shlomitubul shlomitubul requested a review from Miretpl April 8, 2026 12:27
Copy link
Copy Markdown
Contributor

@Miretpl Miretpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better! Just small nits

shlomitubul and others added 2 commits April 9, 2026 09:51
…x versions

- Separate pgbouncer into dedicated test (no conditional logic)
- Use workers.celery.serviceAccount for Celery worker tpl test
- Add workers.kubernetes.serviceAccount test for KubernetesExecutor
- Use airflowVersion 2.11.0 (first supported 2.11) instead of 2.11.2
- Remove explicit airflowVersion from Airflow 3 tests (default is 3.x)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… template

The worker SA template reads from workers.serviceAccount (merged from
workers.celery), not workers.kubernetes.serviceAccount. Removed invalid test.

All 82 tests in test_annotations.py and test_metadata_connection_secret.py pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@eladkal eladkal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM
probably need also @jedcunningham eye on this one

@shlomitubul shlomitubul requested a review from Miretpl April 9, 2026 08:41
@shlomitubul
Copy link
Copy Markdown
Contributor Author

@Miretpl All feedback addressed and tests verified locally (82/82 pass):

  • Separated pgbouncer into dedicated test — no conditional logic
  • Used workers.celery.serviceAccount for Celery worker test
  • Changed airflowVersion to 2.11.0 and removed explicit version from Airflow 3 tests
  • Removed the kubernetes worker SA test — workers.kubernetes.serviceAccount doesn't propagate to the worker SA template (it only affects the pod-template-file); the worker SA reads from workers.serviceAccount merged via workers.celery
  • Pre-commit hooks (prek) passing

@Miretpl
Copy link
Copy Markdown
Contributor

Miretpl commented Apr 9, 2026

Removed the kubernetes worker SA test — workers.kubernetes.serviceAccount doesn't propagate to the worker SA template (it only affects the pod-template-file); the worker SA reads from workers.serviceAccount merged via workers.celery

@shlomitubul it works in a little different way. The workers.celery configuration only affects the rendering for celery workers deployments with the whole overwrite logic of workers.celery to workers. The pod-template-file is not affected by it in any form, and it uses the workers service account or dedicated workers kubernetes service account (if workers.kubernetes.serviceAccount.create=true) with respective fields and fallbacks, so basically in current form we are missing the testing of workers.serviceAccount.annotations which is deprecated already and workers.kubernetes.serviceAccount (which is kinda ok as this PR does not modify the content of workers-kubernetes-serviceaccount.yaml file -> "kinda ok" as it will be not strightforward from user perspective why we support template annotations in most of the places, but not in this one).

@Miretpl
Copy link
Copy Markdown
Contributor

Miretpl commented Apr 9, 2026

@shlomitubul I see that the commits were co-authored by Claude. I would really encourage you to make sure that everything that Claude did is fully understandable to be compliant with our AI-usage policy - https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions

@shlomitubul
Copy link
Copy Markdown
Contributor Author

@shlomitubul I see that the commits were co-authored by Claude. I would really encourage you to make sure that everything that Claude did is fully understandable to be compliant with our AI-usage policy - https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions

@Miretpl i appreciate your excellent review !, yes im aware of the project AI policy and fully understand the changeset

@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR enables broader Helm tpl rendering support across the chart so wrapper charts can derive values (ServiceAccount annotations, metadata DB credentials, and config ConfigMap names) from template expressions.

Changes:

  • Standardize ServiceAccount annotation rendering to use a shared tpl-rendering helper across components.
  • tpl-render data.metadataConnection.user and .db for the metadata connection secret and PgBouncer config.
  • tpl-render webserverConfigConfigMapName and apiServerConfigConfigMapName overrides.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
helm-tests/tests/helm_tests/security/test_metadata_connection_secret.py Adds tests for tpl rendering of metadata connection user and db.
helm-tests/tests/helm_tests/airflow_aux/test_annotations.py Adds tests ensuring ServiceAccount annotations support tpl rendering across components.
chart/templates/workers/worker-serviceaccount.yaml Switches worker SA annotations rendering to shared tpl dict helper.
chart/templates/webserver/webserver-serviceaccount.yaml Switches webserver SA annotations rendering to shared tpl dict helper.
chart/templates/triggerer/triggerer-serviceaccount.yaml Switches triggerer SA annotations rendering to shared tpl dict helper.
chart/templates/secrets/metadata-connection-secret.yaml Applies tpl rendering to metadata connection user and db in generated connection URIs.
chart/templates/scheduler/scheduler-serviceaccount.yaml Refactors scheduler SA annotations to use shared tpl dict helper.
chart/templates/pgbouncer/pgbouncer-serviceaccount.yaml Switches PgBouncer SA annotations rendering to shared tpl dict helper.
chart/templates/dag-processor/dag-processor-serviceaccount.yaml Switches dag-processor SA annotations rendering to shared tpl dict helper.
chart/templates/api-server/api-server-serviceaccount.yaml Switches api-server SA annotations rendering to shared tpl dict helper.
chart/templates/_helpers.yaml Introduces airflow.tplDict helper; tpl-renders PgBouncer db/user fields and config ConfigMap name overrides.

shlomitubul and others added 2 commits April 11, 2026 10:59
The previous printf-based approach concatenated multiple annotations
into a single YAML line due to whitespace trimming. Replace with
dict-building + toYaml for correct YAML output with any number of
entries. Also adds toString for non-string value safety.

Added test_tpl_rendered_multiple_annotations to verify 3 annotations
(2 templated + 1 plain) render correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The worker-serviceaccount.yaml template serves both CeleryExecutor and
KubernetesExecutor. Add test verifying tpl rendering works for the
KubernetesExecutor path via workers.serviceAccount.annotations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jscheffl
Copy link
Copy Markdown
Contributor

@Miretpl can you re-review if OK now?

Copy link
Copy Markdown
Contributor

@Miretpl Miretpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jscheffl jscheffl merged commit 3a458de into apache:main Apr 12, 2026
106 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 12, 2026

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

github-actions bot pushed a commit that referenced this pull request Apr 12, 2026
…tations, metadataConnection, and config ConfigMap names (#64763)

* Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names

The scheduler ServiceAccount already tpl-renders annotations via
range/tpl, but all other ServiceAccounts (pgbouncer, webserver, workers,
triggerer, dag-processor, api-server) use raw toYaml. This makes it
impossible to use template expressions like
{{ .Values.global.appName }}-sa@project.iam.gserviceaccount.com in
annotation values for those components.

Apply the same range/tpl pattern from the scheduler to all ServiceAccount
templates for consistency.

Also tpl-render data.metadataConnection.user and
data.metadataConnection.db so wrapper charts can derive database
credentials from template expressions instead of requiring static values.
This affects the metadata connection secret and pgbouncer config.

Also tpl-render webserverConfigConfigMapName and
apiServerConfigConfigMapName so wrapper charts can use
{{ .Release.Name }}-custom-config instead of hardcoding the release name.

All changes are backward compatible: tpl on a plain string without
template expressions returns the string unchanged.

* Address review feedback: make tplDict generic, move tests to existing files

- Remove nindent from tplDict helper, move indent to call sites
- Move SA annotation tpl tests to test_annotations.py
- Move metadataConnection tpl tests to test_metadata_connection_secret.py
- Split Airflow 2/3 version tests into separate parametrized cases
- Remove conditional logic from tests per review feedback
- Fix result-backend nit (remove unnecessary parens)
- Delete test_tpl_rendering.py (tests relocated)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address round 2 review: split pgbouncer, use celery/k8s worker SA, fix versions

- Separate pgbouncer into dedicated test (no conditional logic)
- Use workers.celery.serviceAccount for Celery worker tpl test
- Add workers.kubernetes.serviceAccount test for KubernetesExecutor
- Use airflowVersion 2.11.0 (first supported 2.11) instead of 2.11.2
- Remove explicit airflowVersion from Airflow 3 tests (default is 3.x)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Remove kubernetes worker SA test — workers.kubernetes does not own SA template

The worker SA template reads from workers.serviceAccount (merged from
workers.celery), not workers.kubernetes.serviceAccount. Removed invalid test.

All 82 tests in test_annotations.py and test_metadata_connection_secret.py pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix tplDict multi-annotation bug: use toYaml instead of printf

The previous printf-based approach concatenated multiple annotations
into a single YAML line due to whitespace trimming. Replace with
dict-building + toYaml for correct YAML output with any number of
entries. Also adds toString for non-string value safety.

Added test_tpl_rendered_multiple_annotations to verify 3 annotations
(2 templated + 1 plain) render correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add KubernetesExecutor worker SA tpl annotation test

The worker-serviceaccount.yaml template serves both CeleryExecutor and
KubernetesExecutor. Add test verifying tpl rendering works for the
KubernetesExecutor path via workers.serviceAccount.annotations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------
(cherry picked from commit 3a458de)

Co-authored-by: shlomi tubul <33376277+shlomitubul@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Backport successfully created: chart/v1-2x-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
chart/v1-2x-test PR Link

jscheffl pushed a commit that referenced this pull request Apr 12, 2026
…tations, metadataConnection, and config ConfigMap names (#64763) (#65081)

* Support tpl rendering in ServiceAccount annotations, metadataConnection, and config ConfigMap names

The scheduler ServiceAccount already tpl-renders annotations via
range/tpl, but all other ServiceAccounts (pgbouncer, webserver, workers,
triggerer, dag-processor, api-server) use raw toYaml. This makes it
impossible to use template expressions like
{{ .Values.global.appName }}-sa@project.iam.gserviceaccount.com in
annotation values for those components.

Apply the same range/tpl pattern from the scheduler to all ServiceAccount
templates for consistency.

Also tpl-render data.metadataConnection.user and
data.metadataConnection.db so wrapper charts can derive database
credentials from template expressions instead of requiring static values.
This affects the metadata connection secret and pgbouncer config.

Also tpl-render webserverConfigConfigMapName and
apiServerConfigConfigMapName so wrapper charts can use
{{ .Release.Name }}-custom-config instead of hardcoding the release name.

All changes are backward compatible: tpl on a plain string without
template expressions returns the string unchanged.

* Address review feedback: make tplDict generic, move tests to existing files

- Remove nindent from tplDict helper, move indent to call sites
- Move SA annotation tpl tests to test_annotations.py
- Move metadataConnection tpl tests to test_metadata_connection_secret.py
- Split Airflow 2/3 version tests into separate parametrized cases
- Remove conditional logic from tests per review feedback
- Fix result-backend nit (remove unnecessary parens)
- Delete test_tpl_rendering.py (tests relocated)



* Address round 2 review: split pgbouncer, use celery/k8s worker SA, fix versions

- Separate pgbouncer into dedicated test (no conditional logic)
- Use workers.celery.serviceAccount for Celery worker tpl test
- Add workers.kubernetes.serviceAccount test for KubernetesExecutor
- Use airflowVersion 2.11.0 (first supported 2.11) instead of 2.11.2
- Remove explicit airflowVersion from Airflow 3 tests (default is 3.x)



* Remove kubernetes worker SA test — workers.kubernetes does not own SA template

The worker SA template reads from workers.serviceAccount (merged from
workers.celery), not workers.kubernetes.serviceAccount. Removed invalid test.

All 82 tests in test_annotations.py and test_metadata_connection_secret.py pass.



* Fix tplDict multi-annotation bug: use toYaml instead of printf

The previous printf-based approach concatenated multiple annotations
into a single YAML line due to whitespace trimming. Replace with
dict-building + toYaml for correct YAML output with any number of
entries. Also adds toString for non-string value safety.

Added test_tpl_rendered_multiple_annotations to verify 3 annotations
(2 templated + 1 plain) render correctly.



* Add KubernetesExecutor worker SA tpl annotation test

The worker-serviceaccount.yaml template serves both CeleryExecutor and
KubernetesExecutor. Add test verifying tpl rendering works for the
KubernetesExecutor path via workers.serviceAccount.annotations.



---------
(cherry picked from commit 3a458de)

Co-authored-by: shlomi tubul <33376277+shlomitubul@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:helm-chart Airflow Helm Chart backport-to-chart/v1-2x-test Automatic backport to chart 1.2x maintenance branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants