Skip to content

Commit

Permalink
Move exception check to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoriello authored and paolo-moriello committed May 1, 2024
1 parent 3316ff4 commit 5567b00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 1 addition & 6 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
PodNotFoundException,
PodOperatorHookProtocol,
PodPhase,
check_exception_is_kubernetes_api_unauthorized,
container_is_succeeded,
get_container_termination_message,
)
Expand All @@ -99,12 +100,6 @@
KUBE_CONFIG_ENV_VAR = "KUBECONFIG"


def check_exception_is_kubernetes_api_unauthorized(exc: BaseException):
return (
isinstance(exc, kubernetes.client.exceptions.ApiException) and exc.status and str(exc.status) == "401"
)


class PodEventType(Enum):
"""Type of Events emitted by kubernetes pod."""

Expand Down
4 changes: 4 additions & 0 deletions airflow/providers/cncf/kubernetes/utils/pod_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def get_container_termination_message(pod: V1Pod, container_name: str):
return container_status.state.terminated.message if container_status else None


def check_exception_is_kubernetes_api_unauthorized(exc: BaseException):
return isinstance(exc, ApiException) and exc.status and str(exc.status) == "401"


class PodLaunchTimeoutException(AirflowException):
"""When pod does not leave the ``Pending`` phase within specified timeout."""

Expand Down

0 comments on commit 5567b00

Please sign in to comment.