From ec731df329760cb099a6554d60dceb6e26bdda33 Mon Sep 17 00:00:00 2001 From: rom sharon <33751805+romsharon98@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:26:05 +0200 Subject: [PATCH] Add tests cases for multiple executors in chart (#44424) * add examples for tests with multiple executors * fix pod-launcher-rolebinding to handel multiple executors * fix hpa tests * remove deprecated test --- .../rbac/pod-launcher-rolebinding.yaml | 19 +++++++++++++------ chart/templates/workers/worker-hpa.yaml | 2 +- helm_tests/airflow_aux/test_configmap.py | 2 ++ .../airflow_aux/test_pod_launcher_role.py | 1 + helm_tests/airflow_core/test_scheduler.py | 10 ++++++++++ helm_tests/airflow_core/test_worker.py | 1 + helm_tests/other/test_flower.py | 2 ++ helm_tests/other/test_hpa.py | 5 ++++- helm_tests/other/test_keda.py | 7 ++++++- helm_tests/other/test_redis.py | 2 +- 10 files changed, 41 insertions(+), 10 deletions(-) diff --git a/chart/templates/rbac/pod-launcher-rolebinding.yaml b/chart/templates/rbac/pod-launcher-rolebinding.yaml index e03c122cba2eb..2ff8f518a1d49 100644 --- a/chart/templates/rbac/pod-launcher-rolebinding.yaml +++ b/chart/templates/rbac/pod-launcher-rolebinding.yaml @@ -23,6 +23,7 @@ {{- if and .Values.rbac.create .Values.allowPodLaunching }} {{- $schedulerLaunchExecutors := list "LocalExecutor" "LocalKubernetesExecutor" "KubernetesExecutor" "CeleryKubernetesExecutor" }} {{- $workerLaunchExecutors := list "CeleryExecutor" "LocalKubernetesExecutor" "KubernetesExecutor" "CeleryKubernetesExecutor" }} +{{- $executors := split "," .Values.executor }} apiVersion: rbac.authorization.k8s.io/v1 {{- if .Values.multiNamespaceMode }} kind: ClusterRoleBinding @@ -57,14 +58,20 @@ roleRef: name: {{ include "airflow.fullname" . }}-pod-launcher-role {{- end }} subjects: - {{- if has .Values.executor $schedulerLaunchExecutors }} + {{- range $executor := $executors }} + {{- if has $executor $schedulerLaunchExecutors }} - kind: ServiceAccount - name: {{ include "scheduler.serviceAccountName" . }} - namespace: "{{ .Release.Namespace }}" + name: {{ include "scheduler.serviceAccountName" $ }} + namespace: "{{ $.Release.Namespace }}" + {{- break -}} + {{- end }} {{- end }} - {{- if has .Values.executor $workerLaunchExecutors }} + {{- range $executor := $executors }} + {{- if has $executor $workerLaunchExecutors }} - kind: ServiceAccount - name: {{ include "worker.serviceAccountName" . }} - namespace: "{{ .Release.Namespace }}" + name: {{ include "worker.serviceAccountName" $ }} + namespace: "{{ $.Release.Namespace }}" + {{- break -}} + {{- end }} {{- end }} {{- end }} diff --git a/chart/templates/workers/worker-hpa.yaml b/chart/templates/workers/worker-hpa.yaml index e6b1a9ae523ea..42cd6a6ff0619 100644 --- a/chart/templates/workers/worker-hpa.yaml +++ b/chart/templates/workers/worker-hpa.yaml @@ -20,7 +20,7 @@ ################################ ## Airflow Worker HPA ################################# -{{- if and (and (not .Values.workers.keda.enabled) .Values.workers.hpa.enabled) (has .Values.executor (list "CeleryExecutor" "CeleryKubernetesExecutor")) }} +{{- if and (and (not .Values.workers.keda.enabled) .Values.workers.hpa.enabled) (or (contains "CeleryExecutor" .Values.executor) (contains "CeleryKubernetesExecutor" .Values.executor)) }} apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: diff --git a/helm_tests/airflow_aux/test_configmap.py b/helm_tests/airflow_aux/test_configmap.py index 8cb88dc184ca9..c0f8d2409a26c 100644 --- a/helm_tests/airflow_aux/test_configmap.py +++ b/helm_tests/airflow_aux/test_configmap.py @@ -105,6 +105,8 @@ def test_kerberos_config_available_with_celery_executor(self): ("KubernetesExecutor", "2.0.0", True), ("CeleryExecutor", "1.10.11", False), ("CeleryExecutor", "2.0.0", False), + ("CeleryExecutor,KubernetesExecutor", "2.0.0", True), + ("CeleryExecutor,KubernetesExecutor", "1.10.11", False), ], ) def test_pod_template_created(self, executor, af_version, should_be_created): diff --git a/helm_tests/airflow_aux/test_pod_launcher_role.py b/helm_tests/airflow_aux/test_pod_launcher_role.py index 595f5ed591bcf..cd865d2d443cc 100644 --- a/helm_tests/airflow_aux/test_pod_launcher_role.py +++ b/helm_tests/airflow_aux/test_pod_launcher_role.py @@ -33,6 +33,7 @@ class TestPodLauncher: ("CeleryExecutor", True, True, ["worker"]), ("LocalExecutor", True, True, ["scheduler"]), ("LocalExecutor", False, False, []), + ("CeleryExecutor,KubernetesExecutor", True, True, ["scheduler", "worker"]), ], ) def test_pod_launcher_role(self, executor, rbac, allow, expected_accounts): diff --git a/helm_tests/airflow_core/test_scheduler.py b/helm_tests/airflow_core/test_scheduler.py index 7b3eae3fdada3..2c3fb0f65cdf2 100644 --- a/helm_tests/airflow_core/test_scheduler.py +++ b/helm_tests/airflow_core/test_scheduler.py @@ -32,10 +32,12 @@ class TestScheduler: ("CeleryExecutor", False, "Deployment"), ("CeleryExecutor", True, "Deployment"), ("CeleryKubernetesExecutor", True, "Deployment"), + ("CeleryExecutor,KubernetesExecutor", True, "Deployment"), ("KubernetesExecutor", True, "Deployment"), ("LocalKubernetesExecutor", False, "Deployment"), ("LocalKubernetesExecutor", True, "StatefulSet"), ("LocalExecutor", True, "StatefulSet"), + ("LocalExecutor,KubernetesExecutor", True, "StatefulSet"), ("LocalExecutor", False, "Deployment"), ], ) @@ -642,15 +644,23 @@ def test_airflow_local_settings(self): ("CeleryExecutor", False, {"rollingUpdate": {"partition": 0}}, None), ("CeleryExecutor", True, {"rollingUpdate": {"partition": 0}}, None), ("LocalKubernetesExecutor", False, {"rollingUpdate": {"partition": 0}}, None), + ("LocalExecutor,KubernetesExecutor", False, {"rollingUpdate": {"partition": 0}}, None), ( "LocalKubernetesExecutor", True, {"rollingUpdate": {"partition": 0}}, {"rollingUpdate": {"partition": 0}}, ), + ( + "LocalExecutor,KubernetesExecutor", + True, + {"rollingUpdate": {"partition": 0}}, + {"rollingUpdate": {"partition": 0}}, + ), ("LocalExecutor", False, {"rollingUpdate": {"partition": 0}}, None), ("LocalExecutor", True, {"rollingUpdate": {"partition": 0}}, {"rollingUpdate": {"partition": 0}}), ("LocalExecutor", True, None, None), + ("LocalExecutor,KubernetesExecutor", True, None, None), ], ) def test_scheduler_update_strategy( diff --git a/helm_tests/airflow_core/test_worker.py b/helm_tests/airflow_core/test_worker.py index 4a630b2b1562f..5630b421e3a2a 100644 --- a/helm_tests/airflow_core/test_worker.py +++ b/helm_tests/airflow_core/test_worker.py @@ -1262,6 +1262,7 @@ def test_should_add_component_specific_labels(self): ("LocalExecutor", False), ("CeleryExecutor", True), ("CeleryKubernetesExecutor", True), + ("CeleryExecutor,KubernetesExecutor", True), ("KubernetesExecutor", True), ("LocalKubernetesExecutor", True), ], diff --git a/helm_tests/other/test_flower.py b/helm_tests/other/test_flower.py index af4eaaa101a70..c589def1fdd4e 100644 --- a/helm_tests/other/test_flower.py +++ b/helm_tests/other/test_flower.py @@ -30,9 +30,11 @@ class TestFlowerDeployment: [ ("CeleryExecutor", False, False), ("CeleryKubernetesExecutor", False, False), + ("CeleryExecutor,KubernetesExecutor", False, False), ("KubernetesExecutor", False, False), ("CeleryExecutor", True, True), ("CeleryKubernetesExecutor", True, True), + ("CeleryExecutor,KubernetesExecutor", True, True), ("KubernetesExecutor", True, False), ], ) diff --git a/helm_tests/other/test_hpa.py b/helm_tests/other/test_hpa.py index dd71a970b12bd..a85f44c1c364b 100644 --- a/helm_tests/other/test_hpa.py +++ b/helm_tests/other/test_hpa.py @@ -38,6 +38,7 @@ def test_hpa_disabled_by_default(self): [ ("CeleryExecutor", True), ("CeleryKubernetesExecutor", True), + ("CeleryExecutor,KubernetesExecutor", True), ], ) def test_hpa_enabled(self, executor, is_created): @@ -78,7 +79,9 @@ def test_min_max_replicas(self, min_replicas, max_replicas): assert jmespath.search("spec.minReplicas", docs[0]) == 0 if min_replicas is None else min_replicas assert jmespath.search("spec.maxReplicas", docs[0]) == 5 if max_replicas is None else max_replicas - @pytest.mark.parametrize("executor", ["CeleryExecutor", "CeleryKubernetesExecutor"]) + @pytest.mark.parametrize( + "executor", ["CeleryExecutor", "CeleryKubernetesExecutor", "CeleryExecutor,KubernetesExecutor"] + ) def test_hpa_behavior(self, executor): """Verify HPA behavior.""" expected_behavior = { diff --git a/helm_tests/other/test_keda.py b/helm_tests/other/test_keda.py index 09fa4985f2864..22513ee82e5cf 100644 --- a/helm_tests/other/test_keda.py +++ b/helm_tests/other/test_keda.py @@ -38,6 +38,7 @@ def test_keda_disabled_by_default(self): [ ("CeleryExecutor", True), ("CeleryKubernetesExecutor", True), + ("CeleryExecutor,KubernetesExecutor", True), ], ) def test_keda_enabled(self, executor, is_created): @@ -54,7 +55,9 @@ def test_keda_enabled(self, executor, is_created): else: assert docs == [] - @pytest.mark.parametrize("executor", ["CeleryExecutor", "CeleryKubernetesExecutor"]) + @pytest.mark.parametrize( + "executor", ["CeleryExecutor", "CeleryKubernetesExecutor", "CeleryExecutor,KubernetesExecutor"] + ) def test_keda_advanced(self, executor): """Verify keda advanced config.""" expected_advanced = { @@ -99,6 +102,8 @@ def build_query(executor, concurrency=16, queue=None): ("CeleryExecutor", 16), ("CeleryKubernetesExecutor", 8), ("CeleryKubernetesExecutor", 16), + ("CeleryExecutor,KubernetesExecutor", 8), + ("CeleryExecutor,KubernetesExecutor", 16), ], ) def test_keda_concurrency(self, executor, concurrency): diff --git a/helm_tests/other/test_redis.py b/helm_tests/other/test_redis.py index 046d51e5237d7..a8fdcc3fa19e5 100644 --- a/helm_tests/other/test_redis.py +++ b/helm_tests/other/test_redis.py @@ -36,7 +36,7 @@ } SET_POSSIBLE_REDIS_OBJECT_KEYS = set(REDIS_OBJECTS.values()) -CELERY_EXECUTORS_PARAMS = ["CeleryExecutor", "CeleryKubernetesExecutor"] +CELERY_EXECUTORS_PARAMS = ["CeleryExecutor", "CeleryKubernetesExecutor", "CeleryExecutor,KubernetesExecutor"] class TestRedis: