airflow.providers.cncf.kubernetes.kubernetes_helper_functions

Attributes

log

alphanum_lower

POD_NAME_MAX_LENGTH

API_RETRIES

API_RETRY_WAIT_MIN

API_RETRY_WAIT_MAX

TRANSIENT_STATUS_CODES

Exceptions

PodLaunchFailedException

When pod launching fails in KubernetesPodOperator.

KubernetesApiException

When communication with kubernetes API fails.

Classes

WaitRetryAfterOrExponential

Wait strategy that honors Retry-After header on 429, else falls back to exponential backoff.

Functions

generic_api_retry(func)

Retry to Kubernetes API calls.

rand_str(num)

Generate random lowercase alphanumeric string of length num.

add_unique_suffix(*, name[, rand_len, max_len])

Add random string to pod or job name while staying under max length.

create_unique_id([dag_id, task_id, max_length, unique])

Generate unique pod or job ID given a dag_id and / or task_id.

annotations_to_key(annotations)

Build a TaskInstanceKey based on pod annotations.

get_logs_task_metadata()

annotations_for_logging_task_metadata(annotation_set)

Module Contents

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.log[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.alphanum_lower = 'abcdefghijklmnopqrstuvwxyz0123456789'[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.POD_NAME_MAX_LENGTH = 63[source]
exception airflow.providers.cncf.kubernetes.kubernetes_helper_functions.PodLaunchFailedException[source]

Bases: airflow.exceptions.AirflowException

When pod launching fails in KubernetesPodOperator.

exception airflow.providers.cncf.kubernetes.kubernetes_helper_functions.KubernetesApiException[source]

Bases: airflow.exceptions.AirflowException

When communication with kubernetes API fails.

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.API_RETRIES[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.API_RETRY_WAIT_MIN[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.API_RETRY_WAIT_MAX[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.TRANSIENT_STATUS_CODES[source]
class airflow.providers.cncf.kubernetes.kubernetes_helper_functions.WaitRetryAfterOrExponential[source]

Bases: tenacity.wait.wait_base

Wait strategy that honors Retry-After header on 429, else falls back to exponential backoff.

__call__(retry_state)[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.generic_api_retry(func)[source]

Retry to Kubernetes API calls.

  • Retries only transient ApiException status codes.

  • Honors Retry-After on 429.

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.rand_str(num)[source]

Generate random lowercase alphanumeric string of length num.

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.add_unique_suffix(*, name, rand_len=8, max_len=POD_NAME_MAX_LENGTH)[source]

Add random string to pod or job name while staying under max length.

Parameters:
  • name (str) – name of the pod or job

  • rand_len (int) – length of the random string to append

  • max_len (int) – maximum length of the pod name

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.create_unique_id(dag_id=None, task_id=None, *, max_length=POD_NAME_MAX_LENGTH, unique=True)[source]

Generate unique pod or job ID given a dag_id and / or task_id.

Parameters:
  • dag_id (str | None) – DAG ID

  • task_id (str | None) – Task ID

  • max_length (int) – max number of characters

  • unique (bool) – whether a random string suffix should be added

Returns:

A valid identifier for a kubernetes pod name

Return type:

str

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.annotations_to_key(annotations)[source]

Build a TaskInstanceKey based on pod annotations.

airflow.providers.cncf.kubernetes.kubernetes_helper_functions.get_logs_task_metadata()[source]
airflow.providers.cncf.kubernetes.kubernetes_helper_functions.annotations_for_logging_task_metadata(annotation_set)[source]

Was this entry helpful?