You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/08 23:01:13 UTC
[GitHub] [airflow] jvstein opened a new issue #8792: KubernetesPodOperator does not return XCOM on pod failure
jvstein opened a new issue #8792:
URL: https://github.com/apache/airflow/issues/8792
**Apache Airflow version**: 1.10.9
**Kubernetes version (if you are using kubernetes)** (use `kubectl version`): 1.14.9
**Environment**:
- **Cloud provider or hardware configuration**: AWS EKS
- **OS** (e.g. from /etc/os-release): Linux (debian 9.12 inside docker image)
- **Kernel** (e.g. `uname -a`): 5.4.0 (on my host)
- **Install tools**:
- **Others**:
**What happened**:
I ran a new task using the `KubernetesPodOperator` on our k8s cluster. This pod is designed to write to the `/airflow/xcom/return.json` even in case of failures so we can send a user-friendly error message in a following task. The pod exits with a non-zero exit code, so Airflow appropriately updates the task as failed, but the XCOM values are not available.
**What you expected to happen**:
I expected XCOM variables to be available even on pod failure. We use this capability in other operators to signal error conditions and messages.
**How to reproduce it**:
Run a KubernetesPodOperator with a command like this in an alpine image.
```
/bin/bash -c 'echo "{'success': False}" > /airflow/xcom/return.json; echo 1'
```
Check the XCOM results, which should include the JSON dictionary.
**Anything else we need to know**:
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein edited a comment on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein edited a comment on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-699188062
@Shivarp1 - You're not allowed to pass `RUN` statements into the operator. You need to start with a pre-built image where those permissions are present, or just run a pod as `root`.
Try this task definition:
```
task = KubernetesPodOperator(
dag=dag,
task_id="xcom_test",
name="test_xcom_failure",
namespace="default",
in_cluster=False,
config_file="/path/to/kube/config",
is_delete_operator_pod=True,
image_pull_policy="IfNotPresent",
image="alpine:3.12",
do_xcom_push=True,
retries=0,
cmds=["/bin/sh", "-c"],
arguments=["mkdir -p /airflow/xcom; echo '{\"success\": false}' | tee /airflow/xcom/return.json; exit 1"],
)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] dstandish commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
dstandish commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-989049455
Yeah I think we should go ahead and make this with no option -- just make it push xcom in a `finally` or something. But have to check on timing. There's a refactor of KPO in progress and may make sense to include the change as part of that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein edited a comment on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein edited a comment on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696914010
@Shivarp1 - I have not tested in Airflow 1.10.12. Reading through the [relevant section on the 1.10.12 tag](https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/operators/kubernetes_pod_operator.py#L280-L288), I suspect the same issue exists.
I just noticed that my repro steps had a bug in the command. It should have been `exit 1` not `echo 1` at the end. I updated the description.
We're currently using 1.10.9, with the following patch.
```
diff --git c/airflow/contrib/operators/kubernetes_pod_operator.py i/airflow/contrib/operators/kubernetes_pod_operator.py
index f692599d7..f4b970d7e 100644
--- c/airflow/contrib/operators/kubernetes_pod_operator.py
+++ i/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -20,6 +20,7 @@ import warnings
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
+from airflow.models import XCOM_RETURN_KEY
from airflow.utils.decorators import apply_defaults
from airflow.contrib.kubernetes import kube_client, pod_generator, pod_launcher
from airflow.contrib.kubernetes.pod import Resources
@@ -253,12 +254,13 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
if self.is_delete_operator_pod:
launcher.delete_pod(pod)
+ if self.do_xcom_push:
+ self.xcom_push(context, XCOM_RETURN_KEY, result)
+
if final_state != State.SUCCESS:
raise AirflowException(
'Pod returned a failure: {state}'.format(state=final_state)
)
- if self.do_xcom_push:
- return result
except AirflowException as ex:
raise AirflowException('Pod Launching failed: {error}'.format(error=ex))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696914010
@Shivarp1 - I have not tested in Airflow 1.10.12. Reading through the [relevant section on the 1.10.12 tag](https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/operators/kubernetes_pod_operator.py#L280-L288), I suspect the same issue exists.
I just noticed that my repro steps had a bug in it the command. It should have been `exit 1` not `echo 1` at the end. I updated the description.
We're currently using 1.10.9, with the following patch.
```
diff --git c/airflow/contrib/operators/kubernetes_pod_operator.py i/airflow/contrib/operators/kubernetes_pod_operator.py
index f692599d7..f4b970d7e 100644
--- c/airflow/contrib/operators/kubernetes_pod_operator.py
+++ i/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -20,6 +20,7 @@ import warnings
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
+from airflow.models import XCOM_RETURN_KEY
from airflow.utils.decorators import apply_defaults
from airflow.contrib.kubernetes import kube_client, pod_generator, pod_launcher
from airflow.contrib.kubernetes.pod import Resources
@@ -253,12 +254,13 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
if self.is_delete_operator_pod:
launcher.delete_pod(pod)
+ if self.do_xcom_push:
+ self.xcom_push(context, XCOM_RETURN_KEY, result)
+
if final_state != State.SUCCESS:
raise AirflowException(
'Pod returned a failure: {state}'.format(state=final_state)
)
- if self.do_xcom_push:
- return result
except AirflowException as ex:
raise AirflowException('Pod Launching failed: {error}'.format(error=ex))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696914010
@Shivarp1 - I have not tested in Airflow 1.10.12. Reading through the [relevant section on the 1.10.12 tag](https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/operators/kubernetes_pod_operator.py#L280-L288), I suspect the same issue exists.
I just noticed that my repro steps had a bug in it the command. It should have been `exit 1` not `echo 1` at the end. I updated the description.
We're currently using 1.10.9, with the following patch.
```
diff --git c/airflow/contrib/operators/kubernetes_pod_operator.py i/airflow/contrib/operators/kubernetes_pod_operator.py
index f692599d7..f4b970d7e 100644
--- c/airflow/contrib/operators/kubernetes_pod_operator.py
+++ i/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -20,6 +20,7 @@ import warnings
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
+from airflow.models import XCOM_RETURN_KEY
from airflow.utils.decorators import apply_defaults
from airflow.contrib.kubernetes import kube_client, pod_generator, pod_launcher
from airflow.contrib.kubernetes.pod import Resources
@@ -253,12 +254,13 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
if self.is_delete_operator_pod:
launcher.delete_pod(pod)
+ if self.do_xcom_push:
+ self.xcom_push(context, XCOM_RETURN_KEY, result)
+
if final_state != State.SUCCESS:
raise AirflowException(
'Pod returned a failure: {state}'.format(state=final_state)
)
- if self.do_xcom_push:
- return result
except AirflowException as ex:
raise AirflowException('Pod Launching failed: {error}'.format(error=ex))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein edited a comment on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein edited a comment on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696914010
@Shivarp1 - I have not tested in Airflow 1.10.12. Reading through the [relevant section on the 1.10.12 tag](https://github.com/apache/airflow/blob/1.10.12/airflow/contrib/operators/kubernetes_pod_operator.py#L280-L288), I suspect the same issue exists.
I just noticed that my repro steps had a bug in the command. It should have been `exit 1` not `echo 1` at the end. I updated the description.
We're currently using 1.10.9, with the following patch.
```
diff --git c/airflow/contrib/operators/kubernetes_pod_operator.py i/airflow/contrib/operators/kubernetes_pod_operator.py
index f692599d7..f4b970d7e 100644
--- c/airflow/contrib/operators/kubernetes_pod_operator.py
+++ i/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -20,6 +20,7 @@ import warnings
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
+from airflow.models import XCOM_RETURN_KEY
from airflow.utils.decorators import apply_defaults
from airflow.contrib.kubernetes import kube_client, pod_generator, pod_launcher
from airflow.contrib.kubernetes.pod import Resources
@@ -253,12 +254,13 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
if self.is_delete_operator_pod:
launcher.delete_pod(pod)
+ if self.do_xcom_push:
+ self.xcom_push(context, XCOM_RETURN_KEY, result)
+
if final_state != State.SUCCESS:
raise AirflowException(
'Pod returned a failure: {state}'.format(state=final_state)
)
- if self.do_xcom_push:
- return result
except AirflowException as ex:
raise AirflowException('Pod Launching failed: {error}'.format(error=ex))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] kaxil commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
kaxil commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-989057143
Plus one to what Daniel said
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] SacredSkull commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
SacredSkull commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-989005605
The above is still true as of Airflow 2.2.2 - I would love to see this working!
Perhaps as an option `do_xcom_push_on_failure`?
As a work-around I've had to let the internal script pass and handle/check for the error in a downstream task and mark that as a failure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] Shivarp1 commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
Shivarp1 commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-698716278
@jvstein one question..
How can we create /airflow/xcom folder when the user for the new worker pod spawned does not have the root access?
when I try this ..
cmds=["RUN mkdir -p /airflow", "RUN chmod -R 777 /airflow", "/bin/bash", "-cx"],
arguments=['mkdir /airflow/xcom','echo \'{\"success\": True}\' > /airflow/xcom/return.json', 'exit 0'],
..
I get this error..
{{pod_launcher.py:156}} INFO - b'container_linux.go:235: starting container process caused "exec: \\"RUN mkdir -p /airflow\\": stat RUN mkdir -p /airflow: no such file or directory"\n'
Thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] Shivarp1 commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
Shivarp1 commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696863575
@jvstein Have you tried it in Airflow 1.10.12 version? ( k8s server version v1.17.4; k8s client version v1.15.3)
I am passing to KubernetesPodOperator
_cmds=["/bin/bash", "-cx"],
arguments=['echo \'{"success": True}\' > /airflow/xcom/return.json; echo 0'],_
the task returns success..and starts the dependent followup task however it still gets no value from /airflow/xcom/return.json
----- bash task log from the spawned k8spod
{{pod_launcher.py:173}} INFO - Event: secondary-bash-62564f5389134383924eae918edb8ef6 had an event of type Succeeded
{{pod_launcher.py:287}} INFO - Event with job id secondary-bash-62564f5389134383924eae918edb8ef6 Succeeded
{{pod_launcher.py:156}} INFO - b'+ echo \'{"success": True}\'\n'
{{pod_launcher.py:156}} INFO - b'/bin/bash: /airflow/xcom/return.json: No such file or directory\n'
{{pod_launcher.py:156}} INFO - b'+ echo 0\n'
{{pod_launcher.py:156}} INFO - b'0\n'
-- followup task code..
_retVal = task_instance.xcom_pull(task_ids='Secondary-bash-task')
print("Printing Secondary Task Return value. ")
print(retVal)_
--- followup task log..
{{logging_mixin.py:112}} INFO - Printing Secondary Task Return value.
{{logging_mixin.py:112}} INFO - None
{{python_operator.py:114}} INFO - Done. Returned value was: True
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] jvstein commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
jvstein commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-699188062
@Shivarp1 - You're not allowed to pass `RUN` statements into the operator. You need to start with a pre-built image.
Try this task definition:
```
task = KubernetesPodOperator(
dag=dag,
task_id="xcom_test",
name="test_xcom_failure",
namespace="default",
in_cluster=False,
config_file="/path/to/kube/config",
is_delete_operator_pod=True,
image_pull_policy="IfNotPresent",
image="alpine:3.12",
do_xcom_push=True,
retries=0,
cmds=["/bin/sh", "-c"],
arguments=["mkdir -p /airflow/xcom; echo '{\"success\": false}' | tee /airflow/xcom/return.json; exit 1"],
)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] Shivarp1 commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
Shivarp1 commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-696863575
@jvstein Have you tried it in Airflow 1.10.12 version? ( k8s server version v1.17.4; k8s client version v1.15.3)
I am passing to KubernetesPodOperator
_cmds=["/bin/bash", "-cx"],
arguments=['echo \'{"success": True}\' > /airflow/xcom/return.json; echo 0'],_
the task returns success..and starts the dependent followup task however it still gets no value from /airflow/xcom/return.json
----- bash task log from the spawned k8spod
{{pod_launcher.py:173}} INFO - Event: secondary-bash-62564f5389134383924eae918edb8ef6 had an event of type Succeeded
{{pod_launcher.py:287}} INFO - Event with job id secondary-bash-62564f5389134383924eae918edb8ef6 Succeeded
{{pod_launcher.py:156}} INFO - b'+ echo \'{"success": True}\'\n'
{{pod_launcher.py:156}} INFO - b'/bin/bash: /airflow/xcom/return.json: No such file or directory\n'
{{pod_launcher.py:156}} INFO - b'+ echo 0\n'
{{pod_launcher.py:156}} INFO - b'0\n'
-- followup task code..
_retVal = task_instance.xcom_pull(task_ids='Secondary-bash-task')
print("Printing Secondary Task Return value. ")
print(retVal)_
--- followup task log..
{{logging_mixin.py:112}} INFO - Printing Secondary Task Return value.
{{logging_mixin.py:112}} INFO - None
{{python_operator.py:114}} INFO - Done. Returned value was: True
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-626055393
Thanks for opening your first issue here! Be sure to follow the issue template!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] Shivarp1 commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
Shivarp1 commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-698716278
@jvstein one question..
How can we create /airflow/xcom folder when the user for the new worker pod spawned does not have the root access?
when I try this ..
cmds=["RUN mkdir -p /airflow", "RUN chmod -R 777 /airflow", "/bin/bash", "-cx"],
arguments=['mkdir /airflow/xcom','echo \'{\"success\": True}\' > /airflow/xcom/return.json', 'exit 0'],
..
I get this error..
{{pod_launcher.py:156}} INFO - b'container_linux.go:235: starting container process caused "exec: \\"RUN mkdir -p /airflow\\": stat RUN mkdir -p /airflow: no such file or directory"\n'
Thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] dstandish commented on issue #8792: KubernetesPodOperator does not return XCOM on pod failure
Posted by GitBox <gi...@apache.org>.
dstandish commented on issue #8792:
URL: https://github.com/apache/airflow/issues/8792#issuecomment-971912053
@kaxil @jedcunningham is this desired behavior? i.e. to attempt to push xcom even in the case of failure?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org