-
-
Notifications
You must be signed in to change notification settings - Fork 6
fix: scheduler container supervises scheduler instead of dag-processor #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
984b3b9
chore: reproduce that killed scheduler does not terminate the pod
sweb 7f5553c
fix: scheduler container supervises scheduler instead of dag-processor
sweb dafc53a
chore: cleanups
sweb 993d5ae
Merge branch 'main' into fix/supervise-scheduler
sweb fc6a653
refactor: move health check logic into commons and apply to tests
sweb 59b7dc7
docs: add recommendation to configure dag processor explicitly
sweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| # The scheduler process was killed in the previous step. The start script ends in | ||
| # `wait_for_termination $!`, so the container must exit and be restarted by Kubernetes. | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| metadata: | ||
| name: test-scheduler-is-supervised | ||
| timeout: 120 | ||
| {% if test_scenario['values']['airflow-latest'].find(",") > 0 %} | ||
| {% set airflow_version = test_scenario['values']['airflow-latest'].split(',')[0] %} | ||
| {% else %} | ||
| {% set airflow_version = test_scenario['values']['airflow-latest'] %} | ||
| {% endif %} | ||
| commands: | ||
| - script: | | ||
| for _ in $(seq 15); do | ||
| restart_count=$(kubectl -n $NAMESPACE get pod airflow-scheduler-default-0 \ | ||
| -o jsonpath='{.status.containerStatuses[?(@.name=="airflow")].restartCount}') | ||
|
|
||
| if [ "${restart_count:-0}" -ge 1 ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| sleep 2 | ||
| done | ||
|
|
||
| echo "The scheduler died but its container was not restarted." | ||
| echo "Kubernetes considers the Pod healthy:" | ||
| kubectl -n $NAMESPACE get pod airflow-scheduler-default-0 | ||
|
|
||
| echo "Airflow does not:" | ||
| kubectl -n $NAMESPACE exec -i airflow-webserver-default-0 -c airflow -- python - \ | ||
| --airflow-version "{{ airflow_version }}" \ | ||
| --component scheduler \ | ||
| --component dag_processor \ | ||
| --timeout 1 \ | ||
| < ../../../../templates/kuttl/commons/health.py || true | ||
|
|
||
| exit 1 | ||
|
|
||
| # The restarted container must bring both processes back. Requiring a | ||
| # heartbeat that differs from the first one observed rules out a scheduler or | ||
| # dag-processor that reports healthy on a stale heartbeat. | ||
| - script: | | ||
| kubectl -n $NAMESPACE exec -i airflow-webserver-default-0 -c airflow -- python - \ | ||
| --airflow-version "{{ airflow_version }}" \ | ||
| --component scheduler \ | ||
| --component dag_processor \ | ||
| --heartbeat-changed \ | ||
| --timeout 60 \ | ||
| < ../../../../templates/kuttl/commons/health.py |
56 changes: 56 additions & 0 deletions
56
tests/templates/kuttl/cluster-operation/11-kill-scheduler.yaml.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| metadata: | ||
| name: kill-scheduler | ||
| timeout: 120 | ||
| {% if test_scenario['values']['airflow-latest'].find(",") > 0 %} | ||
| {% set airflow_version = test_scenario['values']['airflow-latest'].split(',')[0] %} | ||
| {% else %} | ||
| {% set airflow_version = test_scenario['values']['airflow-latest'] %} | ||
| {% endif %} | ||
| commands: | ||
| - script: | | ||
| restart_count=$(kubectl -n $NAMESPACE get pod airflow-scheduler-default-0 \ | ||
| -o jsonpath='{.status.containerStatuses[?(@.name=="airflow")].restartCount}') | ||
|
|
||
| if [ "${restart_count:-0}" -ne 0 ]; then | ||
| echo "The airflow container already restarted ${restart_count} times before the" \ | ||
| "kill, so a restart afterwards would not prove that the scheduler is" \ | ||
| "supervised." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Killing an already dead scheduler would not prove anything, so wait for it | ||
| # to be up. The script is piped in rather than copied with `kubectl cp`, which | ||
| # would need `tar` in the Airflow image. | ||
| - script: | | ||
| kubectl -n $NAMESPACE exec -i airflow-scheduler-default-0 -c airflow -- python - \ | ||
| --airflow-version "{{ airflow_version }}" \ | ||
| --component scheduler \ | ||
| --timeout 60 \ | ||
| < ../../../../templates/kuttl/commons/health.py | ||
|
|
||
| - script: | | ||
| kubectl -n $NAMESPACE exec -i airflow-scheduler-default-0 -c airflow -- bash <<'EOF' | ||
| set -euo pipefail | ||
|
|
||
| scheduler_killed=false | ||
|
|
||
| for pid in $(cat /proc/1/task/1/children); do | ||
| command_line=$(tr '\0' ' ' < "/proc/$pid/cmdline") | ||
|
|
||
| case "$command_line" in | ||
| *"airflow scheduler"*) | ||
| echo "Killing the scheduler (PID $pid)" | ||
| kill -9 "$pid" | ||
| scheduler_killed=true | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ "$scheduler_killed" = false ]; then | ||
| echo "No scheduler process found" >&2 | ||
| exit 1 | ||
| fi | ||
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.