diff --git a/airflow/providers/cncf/kubernetes/utils/pod_manager.py b/airflow/providers/cncf/kubernetes/utils/pod_manager.py index 4221ac2afd95e..eab45fabb4bab 100644 --- a/airflow/providers/cncf/kubernetes/utils/pod_manager.py +++ b/airflow/providers/cncf/kubernetes/utils/pod_manager.py @@ -40,7 +40,11 @@ from airflow.utils.log.logging_mixin import LoggingMixin if TYPE_CHECKING: - from kubernetes.client.models.core_v1_event_list import CoreV1EventList + try: + # Kube >= 19 + from kubernetes.client.models.core_v1_event_list import CoreV1EventList as V1EventList + except ImportError: + from kubernetes.client.models.v1_event_list import V1EventList class PodLaunchFailedException(AirflowException): @@ -317,7 +321,7 @@ def read_pod_logs( raise @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True) - def read_pod_events(self, pod: V1Pod) -> "CoreV1EventList": + def read_pod_events(self, pod: V1Pod) -> "V1EventList": """Reads events from the POD""" try: return self._client.list_namespaced_event( diff --git a/tests/kubernetes/test_client.py b/tests/kubernetes/test_client.py index b3f41fa9427bc..ce040cf3ed8f2 100644 --- a/tests/kubernetes/test_client.py +++ b/tests/kubernetes/test_client.py @@ -59,5 +59,9 @@ def test_disable_verify_ssl(self): _disable_verify_ssl() - configuration = Configuration() + # Support wide range of kube client libraries + if hasattr(Configuration, 'get_default_copy'): + configuration = Configuration.get_default_copy() + else: + configuration = Configuration() self.assertFalse(configuration.verify_ssl)