class_docstr: Execute a task in a Kubernetes Pod.
  
  .. seealso::
      For more information on how to use this operator, take a look at the guide:
      :ref:`howto/operator:KubernetesPodOperator`
  
  .. note::
      If you use `Google Kubernetes Engine <https://cloud.google.com/kubernetes-engine/>`__
      and Airflow is not running in the same cluster, consider using
      :class:`~airflow.providers.google.cloud.operators.kubernetes_engine.GKEStartPodOperator`, which
      simplifies the authorization process.
  
  :param kubernetes_conn_id: The :ref:`kubernetes connection id <howto/connection:kubernetes>`
      for the Kubernetes cluster.
  :param namespace: the namespace to run within kubernetes.
  :param image: Docker image you wish to launch. Defaults to hub.docker.com,
      but fully qualified URLS will point to custom repositories. (templated)
  :param name: name of the pod in which the task will run, will be used (plus a random
      suffix if random_name_suffix is True) to generate a pod id (DNS-1123 subdomain,
      containing only [a-z0-9.-]).
  :param random_name_suffix: if True, will generate a random suffix.
  :param cmds: entrypoint of the container. (templated)
      The docker images's entrypoint is used if this is not provided.
  :param arguments: arguments of the entrypoint. (templated)
      The docker image's CMD is used if this is not provided.
  :param ports: ports for the launched pod.
  :param volume_mounts: volumeMounts for the launched pod.
  :param volumes: volumes for the launched pod. Includes ConfigMaps and PersistentVolumes.
  :param env_vars: Environment variables initialized in the container. (templated)
  :param env_from: (Optional) List of sources to populate environment variables in the container.
  :param secrets: Kubernetes secrets to inject in the container.
      They can be exposed as environment vars or files in a volume.
  :param in_cluster: run kubernetes client with in_cluster configuration.
  :param cluster_context: context that points to kubernetes cluster.
      Ignored when in_cluster is True. If None, current-context is used. (templated)
  :param reattach_on_restart: if the worker dies while the pod is running, reattach and monitor
      during the next try. If False, always create a new pod for each try.
  :param labels: labels to apply to the Pod. (templated)
  :param startup_timeout_seconds: timeout in seconds to startup the pod.
  :param startup_check_interval_seconds: interval in seconds to check if the pod has already started
  :param get_logs: get the stdout of the base container as logs of the tasks.
  :param container_logs: list of containers whose logs will be published to stdout
      Takes a sequence of containers, a single container name or True. If True,
      all the containers logs are published. Works in conjunction with get_logs param.
      The default value is the base container.
  :param image_pull_policy: Specify a policy to cache or always pull an image.
  :param annotations: non-identifying metadata you can attach to the Pod.
      Can be a large range of data, and can include characters
      that are not permitted by labels. (templated)
  :param container_resources: resources for the launched pod. (templated)
  :param affinity: affinity scheduling rules for the launched pod.
  :param config_file: The path to the Kubernetes config file. (templated)
      If not specified, default value is ``~/.kube/config``
  :param node_selector: A dict containing a group of scheduling rules.
  :param image_pull_secrets: Any image pull secrets to be given to the pod.
      If more than one secret is required, provide a
      comma separated list: secret_a,secret_b
  :param service_account_name: Name of the service account
  :param hostnetwork: If True enable host networking on the pod.
  :param host_aliases: A list of host aliases to apply to the containers in the pod.
  :param tolerations: A list of kubernetes tolerations.
  :param security_context: security options the pod should run with (PodSecurityContext).
  :param container_security_context: security options the container should run with.
  :param dnspolicy: dnspolicy for the pod.
  :param dns_config: dns configuration (ip addresses, searches, options) for the pod.
  :param hostname: hostname for the pod.
  :param subdomain: subdomain for the pod.
  :param schedulername: Specify a schedulername for the pod
  :param full_pod_spec: The complete podSpec
  :param init_containers: init container for the launched Pod
  :param log_events_on_failure: Log the pod's events if a failure occurs
  :param do_xcom_push: If True, the content of the file
      /airflow/xcom/return.json in the container will also be pushed to an
      XCom when the container completes.
  :param pod_template_file: path to pod template file (templated)
  :param pod_template_dict: pod template dictionary (templated)
  :param priority_class_name: priority class name for the launched Pod
  :param pod_runtime_info_envs: (Optional) A list of environment variables,
      to be set in the container.
  :param termination_grace_period: Termination grace period if task killed in UI,
      defaults to kubernetes default
  :param configmaps: (Optional) A list of names of config maps from which it collects ConfigMaps
      to populate the environment variables with. The contents of the target
      ConfigMap's Data field will represent the key-value pairs as environment variables.
      Extends env_from.
  :param skip_on_exit_code: If task exits with this exit code, leave the task
      in ``skipped`` state (default: None). If set to ``None``, any non-zero
      exit code will be treated as a failure.
  :param base_container_name: The name of the base container in the pod. This container's logs
      will appear as part of this task's logs if get_logs is True. Defaults to None. If None,
      will consult the class variable BASE_CONTAINER_NAME (which defaults to "base") for the base
      container name to use.
  :param deferrable: Run operator in the deferrable mode.
  :param poll_interval: Polling period in seconds to check for the status. Used only in deferrable mode.
  :param log_pod_spec_on_failure: Log the pod's specification if a failure occurs
  :param on_finish_action: 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.
  :param is_delete_operator_pod: What to do when the pod reaches its final
      state, or the execution is interrupted. If True (default), delete the
      pod; if False, leave the pod.
      Deprecated - use `on_finish_action` instead.
  :param termination_message_policy: The termination message policy of the base container.
      Default value is "File"
  :param active_deadline_seconds: The active_deadline_seconds which translates to active_deadline_seconds
      in V1PodSpec.
  :param progress_callback: Callback function for receiving k8s container logs.
class_docstr_tok: ["Execute","a","task","in","a","Kubernetes","Pod",".","..","seealso",":",":","For","more","information","on","how","to","use","this","operator",",","take","a","look","at","the","guide",":",":","ref",":","`","howto\/operator",":","KubernetesPodOperator","`","..","note",":",":","If","you","use","`","Google","Kubernetes","Engine","<","https",":","\/\/cloud.google.com\/kubernetes-engine\/",">","`","__","and","Airflow","is","not","running","in","the","same","cluster",",","consider","using",":","class",":","`","~airflow.providers.google.cloud.operators.kubernetes_engine.GKEStartPodOperator","`",",","which","simplifies","the","authorization","process",".",":","param","kubernetes_conn_id",":","The",":","ref",":","`","kubernetes","connection","id","<","howto\/connection",":","kubernetes",">","`","for","the","Kubernetes","cluster",".",":","param","namespace",":","the","namespace","to","run","within","kubernetes",".",":","param","image",":","Docker","image","you","wish","to","launch",".","Defaults","to","hub.docker.com",",","but","fully","qualified","URLS","will","point","to","custom","repositories",".","(","templated",")",":","param","name",":","name","of","the","pod","in","which","the","task","will","run",",","will","be","used","(","plus","a","random","suffix","if","random_name_suffix","is","True",")","to","generate","a","pod","id","(","DNS-1123","subdomain",",","containing","only","[","a-z0-9.-","]",")",".",":","param","random_name_suffix",":","if","True",",","will","generate","a","random","suffix",".",":","param","cmds",":","entrypoint","of","the","container",".","(","templated",")","The","docker","images","'s","entrypoint","is","used","if","this","is","not","provided",".",":","param","arguments",":","arguments","of","the","entrypoint",".","(","templated",")","The","docker","image","'s","CMD","is","used","if","this","is","not","provided",".",":","param","ports",":","ports","for","the","launched","pod",".",":","param","volume_mounts",":","volumeMounts","for","the","launched","pod",".",":","param","volumes",":","volumes","for","the","launched","pod",".","Includes","ConfigMaps","and","PersistentVolumes",".",":","param","env_vars",":","Environment","variables","initialized","in","the","container",".","(","templated",")",":","param","env_from",":","(","Optional",")","List","of","sources","to","populate","environment","variables","in","the","container",".",":","param","secrets",":","Kubernetes","secrets","to","inject","in","the","container",".","They","can","be","exposed","as","environment","vars","or","files","in","a","volume",".",":","param","in_cluster",":","run","kubernetes","client","with","in_cluster","configuration",".",":","param","cluster_context",":","context","that","points","to","kubernetes","cluster",".","Ignored","when","in_cluster","is","True",".","If","None",",","current-context","is","used",".","(","templated",")",":","param","reattach_on_restart",":","if","the","worker","dies","while","the","pod","is","running",",","reattach","and","monitor","during","the","next","try",".","If","False",",","always","create","a","new","pod","for","each","try",".",":","param","labels",":","labels","to","apply","to","the","Pod",".","(","templated",")",":","param","startup_timeout_seconds",":","timeout","in","seconds","to","startup","the","pod",".",":","param","startup_check_interval_seconds",":","interval","in","seconds","to","check","if","the","pod","has","already","started",":","param","get_logs",":","get","the","stdout","of","the","base","container","as","logs","of","the","tasks",".",":","param","container_logs",":","list","of","containers","whose","logs","will","be","published","to","stdout","Takes","a","sequence","of","containers",",","a","single","container","name","or","True",".","If","True",",","all","the","containers","logs","are","published",".","Works","in","conjunction","with","get_logs","param",".","The","default","value","is","the","base","container",".",":","param","image_pull_policy",":","Specify","a","policy","to","cache","or","always","pull","an","image",".",":","param","annotations",":","non-identifying","metadata","you","can","attach","to","the","Pod",".","Can","be","a","large","range","of","data",",","and","can","include","characters","that","are","not","permitted","by","labels",".","(","templated",")",":","param","container_resources",":","resources","for","the","launched","pod",".","(","templated",")",":","param","affinity",":","affinity","scheduling","rules","for","the","launched","pod",".",":","param","config_file",":","The","path","to","the","Kubernetes","config","file",".","(","templated",")","If","not","specified",",","default","value","is","``","~\/.kube\/config","``",":","param","node_selector",":","A","dict","containing","a","group","of","scheduling","rules",".",":","param","image_pull_secrets",":","Any","image","pull","secrets","to","be","given","to","the","pod",".","If","more","than","one","secret","is","required",",","provide","a","comma","separated","list",":","secret_a",",","secret_b",":","param","service_account_name",":","Name","of","the","service","account",":","param","hostnetwork",":","If","True","enable","host","networking","on","the","pod",".",":","param","host_aliases",":","A","list","of","host","aliases","to","apply","to","the","containers","in","the","pod",".",":","param","tolerations",":","A","list","of","kubernetes","tolerations",".",":","param","security_context",":","security","options","the","pod","should","run","with","(","PodSecurityContext",")",".",":","param","container_security_context",":","security","options","the","container","should","run","with",".",":","param","dnspolicy",":","dnspolicy","for","the","pod",".",":","param","dns_config",":","dns","configuration","(","ip","addresses",",","searches",",","options",")","for","the","pod",".",":","param","hostname",":","hostname","for","the","pod",".",":","param","subdomain",":","subdomain","for","the","pod",".",":","param","schedulername",":","Specify","a","schedulername","for","the","pod",":","param","full_pod_spec",":","The","complete","podSpec",":","param","init_containers",":","init","container","for","the","launched","Pod",":","param","log_events_on_failure",":","Log","the","pod","'s","events","if","a","failure","occurs",":","param","do_xcom_push",":","If","True",",","the","content","of","the","file","\/airflow\/xcom\/return.json","in","the","container","will","also","be","pushed","to","an","XCom","when","the","container","completes",".",":","param","pod_template_file",":","path","to","pod","template","file","(","templated",")",":","param","pod_template_dict",":","pod","template","dictionary","(","templated",")",":","param","priority_class_name",":","priority","class","name","for","the","launched","Pod",":","param","pod_runtime_info_envs",":","(","Optional",")","A","list","of","environment","variables",",","to","be","set","in","the","container",".",":","param","termination_grace_period",":","Termination","grace","period","if","task","killed","in","UI",",","defaults","to","kubernetes","default",":","param","configmaps",":","(","Optional",")","A","list","of","names","of","config","maps","from","which","it","collects","ConfigMaps","to","populate","the","environment","variables","with",".","The","contents","of","the","target","ConfigMap","'s","Data","field","will","represent","the","key-value","pairs","as","environment","variables",".","Extends","env_from",".",":","param","skip_on_exit_code",":","If","task","exits","with","this","exit","code",",","leave","the","task","in","``","skipped","``","state","(","default",":","None",")",".","If","set","to","``","None","``",",","any","non-zero","exit","code","will","be","treated","as","a","failure",".",":","param","base_container_name",":","The","name","of","the","base","container","in","the","pod",".","This","container","'s","logs","will","appear","as","part","of","this","task","'s","logs","if","get_logs","is","True",".","Defaults","to","None",".","If","None",",","will","consult","the","class","variable","BASE_CONTAINER_NAME","(","which","defaults","to","``","base","''",")","for","the","base","container","name","to","use",".",":","param","deferrable",":","Run","operator","in","the","deferrable","mode",".",":","param","poll_interval",":","Polling","period","in","seconds","to","check","for","the","status",".","Used","only","in","deferrable","mode",".",":","param","log_pod_spec_on_failure",":","Log","the","pod","'s","specification","if","a","failure","occurs",":","param","on_finish_action",":","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",".",":","param","is_delete_operator_pod",":","What","to","do","when","the","pod","reaches","its","final","state",",","or","the","execution","is","interrupted",".","If","True","(","default",")",",","delete","the","pod",";","if","False",",","leave","the","pod",".","Deprecated","-","use","`","on_finish_action","`","instead",".",":","param","termination_message_policy",":","The","termination","message","policy","of","the","base","container",".","Default","value","is","``","File","''",":","param","active_deadline_seconds",":","The","active_deadline_seconds","which","translates","to","active_deadline_seconds","in","V1PodSpec",".",":","param","progress_callback",":","Callback","function","for","receiving","k8s","container","logs","."]
docstr: Retrieve xcom value and kill xcom sidecar container.
docstr_tok: ["Retrieve","xcom","value","and","kill","xcom","sidecar","container","."]
code: def extract_xcom(self, pod: k8s.V1Pod):
      """Retrieve xcom value and kill xcom sidecar container."""
      result = self.pod_manager.extract_xcom(pod)
      if (
          isinstance(result, str)
          and result.rstrip() == EMPTY_XCOM_RESULT
      ):
          self.log.info("xcom result file is empty.")
          return None
      else:
          self.log.info("xcom result: \n%s", result)
          return json.loads(result)
  
imports: from __future__ import annotations
  import json
  import logging
  import re
  import shlex
  import string
  import warnings
  from collections.abc import Container
  from contextlib import AbstractContextManager
  from functools import cached_property
  from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence
  from kubernetes.client import CoreV1Api, V1Pod, models
  from kubernetes.stream import stream
  from urllib3.exceptions import HTTPError
  from airflow.configuration import conf
  from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning, AirflowSkipException
  from airflow.models import BaseOperator
  from airflow.providers.cncf.kubernetes import pod_generator
  from airflow.providers.cncf.kubernetes.backcompat.backwards_compat_converters import convert_affinity, convert_configmap, convert_env_vars, convert_image_pull_secrets, convert_pod_runtime_info_env, convert_port, convert_toleration, convert_volume, convert_volume_mount
  from airflow.providers.cncf.kubernetes.hooks.kubernetes import KubernetesHook
  from airflow.providers.cncf.kubernetes.kubernetes_helper_functions import POD_NAME_MAX_LENGTH, add_pod_suffix, create_pod_id
  from airflow.providers.cncf.kubernetes.pod_generator import PodGenerator
  from airflow.providers.cncf.kubernetes.triggers.pod import KubernetesPodTrigger
  from airflow.providers.cncf.kubernetes.utils import xcom_sidecar
  from airflow.providers.cncf.kubernetes.utils.pod_manager import EMPTY_XCOM_RESULT, OnFinishAction, PodLaunchFailedException, PodManager, PodOperatorHookProtocol, PodPhase, container_is_succeeded, get_container_termination_message
  from airflow.settings import pod_mutation_hook
  from airflow.utils import yaml
  from airflow.utils.helpers import prune_dict, validate_key
  from airflow.utils.timezone import utcnow
  from airflow.version import version
label_desc: Use image node_id 11 for calling the KubernetesPodOperator obj's underlying member method code with example usage: obj.extract_xcom(pod) and returns: None, json