Airflow BashOperator return exit code 0 even when task failed and return exit code 1

1/6/2020

I am trying to run a spark job from airflow's bash operator with Kubernetes, I have configured callback_failure to some function, however even though spark job failed with exit code 1, my task is always marked as a success and function is not called( callbcak failure ). Following are snippets of airflow log:

[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO - 20/01/03 13:22:46 INFO LoggingPodStatusWatcherImpl: Container final statuses:
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO - 
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO - 
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO -    Container name: spark-kubernetes-driver
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO -    Container image: XXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/spark-py:XX_XX
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO -    Container state: Terminated
[2020-01-03 13:22:46,730] {{bash_operator.py:128}} INFO -    Exit code: 1
[2020-01-03 13:22:46,731] {{bash_operator.py:128}} INFO - 20/01/03 13:22:46 INFO Client: Application run_report_generator finished.
[2020-01-03 13:22:46,736] {{bash_operator.py:128}} INFO - 20/01/03 13:22:46 INFO ShutdownHookManager: Shutdown hook called
[2020-01-03 13:22:46,737] {{bash_operator.py:128}} INFO - 20/01/03 13:22:46 INFO ShutdownHookManager: Deleting directory /tmp/spark-adb99a7e-ce6c-49f6-8307-a17c28448043
[2020-01-03 13:22:46,761] {{bash_operator.py:132}} INFO - Command exited with return code 0
[2020-01-03 13:22:49,994] {{logging_mixin.py:95}} INFO - [ [34m2020-01-03 13:22:49,994 [0m] {{ [34mlocal_task_job.py: [0m105}} INFO [0m - Task exited with return code 0 
-- vkSinha
airflow
airflow-operator
amazon-eks
apache-spark
kubernetes

1 Answer

1/13/2020

You need to use set -e to ensure the BashOperator to stop execution and return error for any non-zero code.

-- Duy Nguyen
Source: StackOverflow