Skip to content

Commit

Permalink
Add tests cases for multiple executors in chart (apache#44424)
Browse files Browse the repository at this point in the history
* add examples for tests with multiple executors

* fix pod-launcher-rolebinding to handel multiple executors

* fix hpa tests

* remove deprecated test
  • Loading branch information
romsharon98 authored and HariGS-DB committed Jan 16, 2025
1 parent 5cf8090 commit ec731df
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 10 deletions.
19 changes: 13 additions & 6 deletions chart/templates/rbac/pod-launcher-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion chart/templates/workers/worker-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions helm_tests/airflow_aux/test_configmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions helm_tests/airflow_aux/test_pod_launcher_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions helm_tests/airflow_core/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions helm_tests/airflow_core/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down
2 changes: 2 additions & 0 deletions helm_tests/other/test_flower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
)
Expand Down
5 changes: 4 additions & 1 deletion helm_tests/other/test_hpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = {
Expand Down
7 changes: 6 additions & 1 deletion helm_tests/other/test_keda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = {
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion helm_tests/other/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ec731df

Please sign in to comment.