airflow.providers.cncf.kubernetes.triggers.pod

Classes

ContainerState

Possible container states.

KubernetesPodTrigger

KubernetesPodTrigger run on the trigger worker to check the state of Pod.

Module Contents

class airflow.providers.cncf.kubernetes.triggers.pod.ContainerState[source]

Bases: str, enum.Enum

Possible container states.

See https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase.

WAITING = 'waiting'[source]
RUNNING = 'running'[source]
TERMINATED = 'terminated'[source]
FAILED = 'failed'[source]
UNDEFINED = 'undefined'[source]
class airflow.providers.cncf.kubernetes.triggers.pod.KubernetesPodTrigger(pod_name, pod_namespace, trigger_start_time, base_container_name, kubernetes_conn_id=None, connection_extras=None, poll_interval=2, cluster_context=None, config_dict=None, in_cluster=None, get_logs=True, startup_timeout=120, startup_check_interval=5, schedule_timeout=120, on_finish_action='delete_pod', on_kill_action='delete_pod', termination_grace_period=None, last_log_time=None, logging_interval=None, trigger_kwargs=None)[source]

Bases: airflow.triggers.base.BaseTrigger

KubernetesPodTrigger run on the trigger worker to check the state of Pod.

Parameters:
  • pod_name (str) – The name of the pod.

  • pod_namespace (str) – The namespace of the pod.

  • kubernetes_conn_id (str | None) – The kubernetes connection id for the Kubernetes cluster.

  • cluster_context (str | None) – Context that points to kubernetes cluster.

  • config_dict (dict | None) – Content of kubeconfig file in dict format.

  • poll_interval (float) – Polling period in seconds to check for the status.

  • trigger_start_time (datetime.datetime) – time in Datetime format when the trigger was started

  • in_cluster (bool | None) – run kubernetes client with in_cluster configuration.

  • get_logs (bool) – get the stdout of the container as logs of the tasks.

  • startup_timeout (int) – timeout in seconds to start up the pod.

  • startup_check_interval (float) – interval in seconds to check if the pod has already started.

  • schedule_timeout (int) – timeout in seconds to schedule pod in cluster.

  • on_finish_action (str) – What to do when the pod reaches its final state, or the execution is interrupted. If “delete_pod”, the pod will be deleted regardless its state; if “delete_succeeded_pod”, only succeeded pod will be deleted. You can set to “keep_pod” to keep the pod.

  • on_kill_action (str) – What to do when the trigger is cancelled (e.g. when a deferred task is manually marked as success/failed). If “delete_pod” (default), the pod will be deleted. If “keep_pod”, the pod will not be deleted.

  • termination_grace_period (int | None) – Optional grace period in seconds for pod termination during cleanup.

  • logging_interval (int | None) – number of seconds to wait before kicking it back to the operator to print latest logs. If None will wait until container done.

  • last_log_time (pendulum.DateTime | None) – where to resume logs from

  • trigger_kwargs (dict | None) – additional keyword parameters to send in the event

pod_name[source]
pod_namespace[source]
trigger_start_time[source]
base_container_name[source]
kubernetes_conn_id = None[source]
connection_extras = None[source]
poll_interval = 2[source]
cluster_context = None[source]
config_dict = None[source]
in_cluster = None[source]
get_logs = True[source]
startup_timeout = 120[source]
startup_check_interval = 5[source]
schedule_timeout = 120[source]
last_log_time = None[source]
logging_interval = None[source]
on_finish_action[source]
on_kill_action[source]
termination_grace_period = None[source]
trigger_kwargs[source]
serialize()[source]

Serialize KubernetesCreatePodTrigger arguments and classpath.

async run()[source]

Get current pod status and yield a TriggerEvent.

property hook: airflow.providers.cncf.kubernetes.hooks.kubernetes.AsyncKubernetesHook[source]
property pod_manager: airflow.providers.cncf.kubernetes.utils.pod_manager.AsyncPodManager[source]
get_task_instance(session)[source]

Get the task instance for this trigger from the database (Airflow 2.x only).

async get_task_state()[source]

Get the current state of the task instance.

async safe_to_cancel()[source]

Whether it is safe to cancel the external job which is being executed by this trigger.

Cancel is NOT safe when the task is still in DEFERRED state, because it means the triggerer is redistributing triggers and the trigger will be recreated on another triggerer. Cancel IS safe when the task state has changed (e.g. user marked it as success/failed).

async cleanup()[source]

Clean up the pod when the trigger is cancelled.

define_container_state(pod)[source]
static should_wait(pod_phase, container_state)[source]

Was this entry helpful?