Skip to content

Commit cb9cdf5

Browse files
ashbephraimbuddy
authored andcommitted
Update Kubernetes library version (#18797)
Previously we pinned this version as v12 as a change to Kube library internals meant v1.Pod objects now have a logger object inside them, and couldn't be pickled on Python 3.6. To fix that we have "backported" the change in Python 3.7 to make Logger objects be pickled "by name". (In Python 3.7 the change adds `__reduce__` methods on to the Logger and RootLogger objects, but here we achieve it `copyreg` stdlib module so we don't monkeypatch anything.) This fix is also applied in to airflow core in a separate commit, but we also apply it here in the provider so that cncf.kubernetes client library can be updated but still used with older versions of Airflow that don't have this fix in. (cherry picked from commit 7222f68)
1 parent 24c84f0 commit cb9cdf5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

airflow/providers/cncf/kubernetes/utils/pod_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
from airflow.utils.log.logging_mixin import LoggingMixin
4141

4242
if TYPE_CHECKING:
43-
from kubernetes.client.models.core_v1_event_list import CoreV1EventList
43+
try:
44+
# Kube >= 19
45+
from kubernetes.client.models.core_v1_event_list import CoreV1EventList as V1EventList
46+
except ImportError:
47+
from kubernetes.client.models.v1_event_list import V1EventList
4448

4549

4650
class PodLaunchFailedException(AirflowException):
@@ -317,7 +321,7 @@ def read_pod_logs(
317321
raise
318322

319323
@tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
320-
def read_pod_events(self, pod: V1Pod) -> "CoreV1EventList":
324+
def read_pod_events(self, pod: V1Pod) -> "V1EventList":
321325
"""Reads events from the POD"""
322326
try:
323327
return self._client.list_namespaced_event(

tests/kubernetes/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ def test_disable_verify_ssl(self):
5959

6060
_disable_verify_ssl()
6161

62-
configuration = Configuration()
62+
# Support wide range of kube client libraries
63+
if hasattr(Configuration, 'get_default_copy'):
64+
configuration = Configuration.get_default_copy()
65+
else:
66+
configuration = Configuration()
6367
self.assertFalse(configuration.verify_ssl)

0 commit comments

Comments
 (0)