sg-c0de commented on code in PR #63514: URL: https://github.com/apache/airflow/pull/63514#discussion_r3044905950
########## helm-tests/tests/helm_tests/airflow_core/test_worker_image.py: ########## @@ -0,0 +1,693 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import jmespath +import pytest +import yaml +from chart_utils.helm_template_generator import CHART_DIR, render_chart + + +def _get_default_airflow_image() -> tuple[str, str]: + """Read the default airflow image and tag from chart/values.yaml.""" + values = yaml.safe_load((CHART_DIR / "values.yaml").read_text()) + repo = values["defaultAirflowRepository"] + tag = values["defaultAirflowTag"] + return f"{repo}:{tag}", tag + + +DEFAULT_AIRFLOW_IMAGE, DEFAULT_AIRFLOW_TAG = _get_default_airflow_image() + + +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 + + +class TestWorkerImageDefault: + """Tests that workers use the default airflow image when no override is set.""" + + def test_default_image_used_when_no_override(self): + """When no worker image override is set, all worker containers use the global default image.""" + docs = render_chart( + values={"executor": "CeleryExecutor"}, + show_only=["templates/workers/worker-deployment.yaml"], + ) + assert len(docs) == 1 + images = _all_airflow_images(docs[0]) + assert len(images) > 0 + for image in images: + assert image == DEFAULT_AIRFLOW_IMAGE + + def test_default_image_with_global_override(self): + """When images.airflow is set, workers use it (no worker-specific override).""" + docs = render_chart( + values={ + "executor": "CeleryExecutor", + "images": { + "airflow": { + "repository": "my-registry/my-airflow", + "tag": "custom-v1", + }, + }, + }, + show_only=["templates/workers/worker-deployment.yaml"], + ) + images = _all_airflow_images(docs[0]) + for image in images: + assert image == "my-registry/my-airflow:custom-v1" + + +class TestWorkerImageCeleryOverride: Review Comment: OK, I removed the separate file for the worker image and moved the tests to the test_worker.py and test_worker_sets.py files." -- 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]
