Skip to content

Commit

Permalink
Move pod_mutation_hook call from PodManager to KubernetesPodOperator (#…
Browse files Browse the repository at this point in the history
…20596)

Previously, in KubernetesPodOperator, the invocation of the pod mutation hook occurred
within the call to PodManager.run_pod_async.  So, `run_pod_async` would not quite run
the pod you asked it to run, but would mutate it first.

With this change, `run_pod_async` runs exactly the pod you request, and the pod returned
by `build_pod_request_obj` is actually the pod you request.
  • Loading branch information
dstandish committed Dec 30, 2021
1 parent 41dbe2c commit e634175
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions airflow/providers/cncf/kubernetes/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Breaking changes

* ``Simplify KubernetesPodOperator (#19572)``
* Class ``pod_launcher.PodLauncher`` renamed to ``pod_manager.PodManager``
* :func:`airflow.settings.pod_mutation_hook` is no longer called in :meth:`~cncf.kubernetes.utils.pod_manager.PodManager.run_pod_async``. For ``KubernetesPodOperator``, mutation now occurs in ``build_pod_request_obj``.


.. warning:: Many methods in :class:`~.KubernetesPodOperator` and class:`~.PodManager` (formerly named ``PodLauncher``)
have been renamed. If you have subclassed :class:`~.KubernetesPodOperator` you will need to update your subclass to
Expand Down
2 changes: 2 additions & 0 deletions airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from kubernetes.client import CoreV1Api, models as k8s

from airflow.providers.cncf.kubernetes.utils.pod_manager import PodLaunchFailedException, PodManager, PodPhase
from airflow.settings import pod_mutation_hook

try:
import airflow.utils.yaml as yaml
Expand Down Expand Up @@ -574,6 +575,7 @@ def build_pod_request_obj(self, context=None):
'kubernetes_pod_operator': 'True',
}
)
pod_mutation_hook(pod)
return pod


Expand Down
3 changes: 0 additions & 3 deletions airflow/providers/cncf/kubernetes/utils/pod_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from airflow.exceptions import AirflowException
from airflow.kubernetes.kube_client import get_kube_client
from airflow.kubernetes.pod_generator import PodDefaults
from airflow.settings import pod_mutation_hook
from airflow.utils.log.logging_mixin import LoggingMixin


Expand Down Expand Up @@ -104,8 +103,6 @@ def __init__(

def run_pod_async(self, pod: V1Pod, **kwargs) -> V1Pod:
"""Runs POD asynchronously"""
pod_mutation_hook(pod)

sanitized_pod = self._client.api_client.sanitize_for_serialization(pod)
json_pod = json.dumps(sanitized_pod, indent=2)

Expand Down

0 comments on commit e634175

Please sign in to comment.