Skip to content

Add option to override Celery worker images#63514

Open
sg-c0de wants to merge 3 commits intoapache:mainfrom
sg-c0de:celery-worker-image-override
Open

Add option to override Celery worker images#63514
sg-c0de wants to merge 3 commits intoapache:mainfrom
sg-c0de:celery-worker-image-override

Conversation

@sg-c0de
Copy link
Copy Markdown

@sg-c0de sg-c0de commented Mar 13, 2026

Summary

Since we have the option to configure multiple Celery worker sets, it is useful to be able to use different images for specific sets (for example, to include CUDA drivers). This adds the option to override the image for all Celery workers globally or on a per-set basis using Values.workers.celery.image and Values.workers.celery.sets[].image.

Changes

chart/templates/_helpers.yaml: Add airflow_worker_image, airflow_worker_image_pull_policy, and airflow_worker_image_for_migrations helpers, and patch the fullOverwrite helper to support image overrides.

chart/templates/workers/worker-deployment.yaml: Update image and imagePullPolicy references to use the new helper templates.

chart/values.yaml: Add new values to support the image overrides.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Mar 13, 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 Mar 13, 2026
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.

Thanks, that option makes sense to me. Can you also please add some tests?

@potiuk
Copy link
Copy Markdown
Member

potiuk commented Mar 16, 2026

@sg-c0de This PR has a few issues that need to be addressed before it can be reviewed — please see our Pull Request quality criteria.

Issues found:

  • ⚠️ Missing Tests: The PR adds new Helm chart behavior (Celery worker image overrides via new helper templates and new values) but no Helm unit test files are included in the changeset. Per review guidelines, new public behavior requires tests covering success, failure, and edge cases. The Helm tests suite has a dedicated area for exactly this kind of templating logic.
  • ⚠️ Description Does Not Match Code: The PR description states the new values are at Values.workers.celery.image and Values.workers.celery.sets[].image, but the _helpers.yaml patch references .Values.workers.image (not .Values.workers.celery.image). The values.yaml patch adds the image block inside the workers.celery section (after queue: "default"). This discrepancy between the described API surface and the actual template code is a code-correctness concern that warrants scrutiny from maintainers.

Note: Your branch is 73 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.

@sg-c0de sg-c0de requested a review from dstandish as a code owner March 19, 2026 12:09
@sg-c0de sg-c0de force-pushed the celery-worker-image-override branch from 366cbfc to 9105d17 Compare March 19, 2026 12:11
@sg-c0de
Copy link
Copy Markdown
Author

sg-c0de commented Mar 19, 2026

@potiuk
Thanks for the review feedback! Here's what I've addressed:

Tests added:

Added test_worker_image.py with 24 tests covering:

  • Default image behavior (no override, global images.airflow override)
  • workers.celery.image overrides (full, partial repository/tag, digest precedence)
  • Per-set image overrides (workers.celery.sets[].image) including full overwrite
  • imagePullPolicy at celery and per-set levels
  • wait-for-airflow-migrations init container image behavior with useDefaultImageForMigration
  • Container consistency (worker, log-groomer, kerberos containers)

Description vs code mismatch clarified:

Updated the airflow_worker_image helper comment in _helpers.yaml to explain the merge indirection: users configure at Values.workers.celery.image, but workersMergeValues in worker-deployment.yaml promotes it to Values.workers.image before the helper runs.

All 24 tests pass locally. Branch has been rebased onto main.

@jscheffl jscheffl added this to the Airflow Helm Chart 1.21.0 milestone Mar 19, 2026
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.

Overall, this is a nice change that aligns with the Workers Sets feature. Let's wait a bit and revisit it in the next round after some discussions on the Helm Chart releases (the images section and design of it are one of the action items) are finished.

in worker-deployment.yaml has already merged celery/set values into Values.workers, so the
effective image is at Values.workers.image (post-merge).
*/}}
{{- define "airflow_worker_image" -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Most of this function copies logic from airflow_image. Maybe there is some nice way to not duplicate code here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure. I created common helpers for images and tags/digests, and reused them across the image helpers.

Comment on lines +36 to +49
def _all_airflow_images(doc):
"""Extract all airflow images from a rendered worker deployment/statefulset."""
init_images = jmespath.search("spec.template.spec.initContainers[*].image", doc) or []
container_images = jmespath.search("spec.template.spec.containers[*].image", doc) or []
# Filter out git-sync sidecar images (they don't use airflow_worker_image)
all_images = init_images + container_images
return [img for img in all_images if "git-sync" not in img]


def _all_airflow_pull_policies(doc):
"""Extract all imagePullPolicy values from airflow containers."""
init_policies = jmespath.search("spec.template.spec.initContainers[*].imagePullPolicy", doc) or []
container_policies = jmespath.search("spec.template.spec.containers[*].imagePullPolicy", doc) or []
return init_policies + container_policies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This added test complexity, which can lead to not-so-straightforward debugging in case of failure. Maybe we could simplify the test cases a little?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed this helpers and to make more straightforward tests

return init_policies + container_policies


class TestWorkerImageDefault:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure where the images section tests are stored, but I think we should move them there to have all images test in one place.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Image tests are divided on a per-component basis. I removed the separate file for the worker image and moved the tests to the test_worker.py and test_worker_sets.py files.

assert image == "celery-custom/airflow@sha256:abcdef1234567890"


class TestWorkerImagePerSetOverride:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All of the tests for sets overwrite of celery, and the workers section is in the workers sets dedicated test file. Could we move these tests there?

@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 2, 2026

Are you still working ont it @sg-c0de ? can you please address @Miretpl comments and solve the issues

@sg-c0de
Copy link
Copy Markdown
Author

sg-c0de commented Apr 3, 2026

@potiuk Sorry for delay, I'll address @Miretpl questions in the near feature

@sg-c0de
Copy link
Copy Markdown
Author

sg-c0de commented Apr 7, 2026

@Miretpl, I’ve pushed a new commit with the changes resolving all the issues.

@Miretpl
Copy link
Copy Markdown
Contributor

Miretpl commented Apr 7, 2026

@sg-c0de thanks for addressing the comments. Could we get back to it when the situation regarding future of Helm Chart (basically how it will looks like) will be more clear (if you want to know more details you can take a look at #64037)?

@sg-c0de
Copy link
Copy Markdown
Author

sg-c0de commented Apr 8, 2026

@Miretpl OK, let's circle back once the Helm Chart direction is a bit clearer.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants