Skip to content

Commit c2b6e44

Browse files
committed
Updating integration test mount-dags-gitsync to use two git-syncs
1 parent c5befaf commit c2b6e44

3 files changed

Lines changed: 39 additions & 22 deletions

File tree

tests/templates/kuttl/mount-dags-gitsync/30-install-airflow-cluster.yaml.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ spec:
7777
dagsGitSync:
7878
{% if test_scenario['values']['access'] == 'ssh' %}
7979
- repo: ssh://git@github.com/stackable-airflow/dags.git
80+
branch: test/git-sync-0
8081
credentials:
8182
sshPrivateKeySecretName: git-sync-ssh
83+
- repo: ssh://git@github.com/stackable-airflow/dags.git
84+
branch: test/git-sync-1
8285
{% endif %}
8386
{% if test_scenario['values']['access'] == 'https' %}
8487
- repo: https://github.com/stackable-airflow/dags
88+
branch: test/git-sync-0
8589
credentials:
8690
basicAuthSecretName: git-credentials
91+
- repo: https://github.com/stackable-airflow/dags
92+
branch: test/git-sync-1
8793
{% endif %}
8894
{% if test_scenario['values']['executor'] == 'celery' %}
8995
# Just setting some values to increase the test coverage (defaults should work just fine)
90-
branch: main
9196
wait: 5s
9297
{% endif %}
9398
gitSyncConf:

tests/templates/kuttl/mount-dags-gitsync/31-assert.yaml.j2

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ commands:
66

77
{% if test_scenario['values']['executor'] == 'kubernetes' %}
88
# check that the executor template configmap contains mounts and envs
9-
# will expect 4 (2 from from the volume declaration + mounts to two containers, base and gitsync)
10-
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "test-cm-gitsync" | wc -l | grep 4
11-
# will expect 2 (two containers, base and gitsync)
12-
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "AIRFLOW_TEST_VAR" | wc -l | grep 2
13-
# will expect 1 (one container, gitsync)
9+
# will expect 6 (2 from from the volume declaration + mounts to four containers, base and gitsync-0, gitsync-1 and multi-gitsync)
10+
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "test-cm-gitsync" | wc -l | grep 6
11+
# will expect 4 (two containers, base and gitsync-0, gitsync-1 and multi-gitsync)
12+
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "AIRFLOW_TEST_VAR" | wc -l | grep 4
13+
# will expect 2 (three container, gitsync-0, gitsync-1)
1414
{% if test_scenario['values']['access'] == 'https' %}
15-
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "GITSYNC_USERNAME" | wc -l | grep 1
16-
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "GITSYNC_PASSWORD" | wc -l | grep 1
15+
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "GITSYNC_USERNAME" | wc -l | grep 2
16+
- script: kubectl -n $NAMESPACE get cm airflow-executor-pod-template -o json | jq -r '.data."airflow_executor_pod_template.yaml"' | grep "GITSYNC_PASSWORD" | wc -l | grep 2
1717
{% endif %}
1818
{% else %}
1919
# check that the statefulset contains mounts and envs
20-
# will expect 6 (2 from from the volume declaration + mounts to 3 containers, base and 2 gitsyncs, plus configmap restarter)
21-
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "test-cm-gitsync" | wc -l | grep 6
22-
# will expect 3 (two containers, base and gitsync-1, and one initContainer gitsync-0)
23-
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "AIRFLOW_TEST_VAR" | wc -l | grep 3
24-
# will expect 2 (one container, gitsync-1, and one initContainer gitsync-0)
20+
# will expect 6 (2 from from the volume declaration + mounts to 5 containers, base and 2 gitsyncs plus configmap restarter)
21+
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "test-cm-gitsync" | wc -l | grep 7
22+
# will expect 5 (three containers, base, gitsyinc-0 and gitsync-1, and two initContainer gitsync-0 and gitsync-1)
23+
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "AIRFLOW_TEST_VAR" | wc -l | grep 5
24+
# will expect 4 (two container, gitsync-0, gitsync-1, and two initContainer gitsync-0 and gitsync-1)
2525
{% if test_scenario['values']['access'] == 'https' %}
26-
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "GITSYNC_USERNAME" | wc -l | grep 2
27-
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "GITSYNC_PASSWORD" | wc -l | grep 2
26+
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "GITSYNC_USERNAME" | wc -l | grep 4
27+
- script: kubectl -n $NAMESPACE get sts airflow-worker-default -o json | grep "GITSYNC_PASSWORD" | wc -l | grep 4
2828
{% endif %}
2929
{% endif %}

tests/templates/kuttl/mount-dags-gitsync/dag_metrics.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def assert_metric(role, metric):
2121
ts = now.strftime("%Y-%m-%dT%H:%M:%S.%f") + now.strftime("%z")
2222

2323
# Trigger a DAG run to create metrics
24-
dag_id = "sparkapp_dag"
24+
dag_id_0 = "sparkapp_dag_0"
25+
dag_id_1 = "sparkapp_dag_1"
2526
dag_data = {"logical_date": f"{ts}"}
2627

2728
print(f"DAG-Data: {dag_data}")
@@ -51,13 +52,20 @@ def assert_metric(role, metric):
5152
"Content-Type": "application/json",
5253
}
5354

55+
# Two DAGs from two different repos/branches will need to be triggered and activated
5456
# activate DAG
55-
response = requests.patch(
56-
f"{rest_url}/dags/{dag_id}", headers=headers, json={"is_paused": False}
57+
response_0 = requests.patch(
58+
f"{rest_url}/dags/{dag_id_0}", headers=headers, json={"is_paused": False}
59+
)
60+
response_1 = requests.patch(
61+
f"{rest_url}/dags/{dag_id_1}", headers=headers, json={"is_paused": False}
5762
)
5863
# trigger DAG
59-
response = requests.post(
60-
f"{rest_url}/dags/{dag_id}/dagRuns", headers=headers, json=dag_data
64+
response_0 = requests.post(
65+
f"{rest_url}/dags/{dag_id_0}/dagRuns", headers=headers, json=dag_data
66+
)
67+
response_1 = requests.post(
68+
f"{rest_url}/dags/{dag_id_1}/dagRuns", headers=headers, json=dag_data
6169
)
6270

6371
# Wait for the metrics to be consumed by the statsd-exporter
@@ -69,12 +77,16 @@ def assert_metric(role, metric):
6977
while True:
7078
try:
7179
logging.info(f"Response code: {response.status_code}")
72-
assert response.status_code == 200, "DAG run could not be triggered."
80+
assert response_0.status_code == 200, f"DAG from git-sync 0 run could not be triggered because of status code: {response_0.status_code}"
81+
assert response_1.status_code == 200, f"DAG from git-sync 1 run could not be triggered. {response_1.status_code}"
7382
# Worker is not deployed with the kubernetes executor so retrieve success metric from scheduler
7483
# (disable line-break flake checks)
7584
if (assert_metric("scheduler", "airflow_scheduler_heartbeat")) and (
7685
assert_metric(
77-
"scheduler", "airflow_dagrun_duration_success_sparkapp_dag_count"
86+
"scheduler", "airflow_dagrun_duration_success_sparkapp_dag_0_count"
87+
)) and (
88+
assert_metric(
89+
"scheduler", "airflow_dagrun_duration_success_sparkapp_dag_1_count"
7890
)
7991
): # noqa: W503, W504
8092
break

0 commit comments

Comments
 (0)