You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/08/11 22:35:02 UTC
[airflow] 21/32: Add pre 1.10.11 Kubernetes Paths back with
Deprecation Warning (#10067)
This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit bfa089d4adff5a0892c7e2ef2c9639938e86cdb1
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Fri Jul 31 09:34:18 2020 +0100
Add pre 1.10.11 Kubernetes Paths back with Deprecation Warning (#10067)
---
airflow/contrib/kubernetes/__init__.py | 2 --
.../contrib/kubernetes/{__init__.py => kube_client.py} | 14 ++++++++++----
.../kubernetes}/pod.py | 17 +++++++++++++++--
.../kubernetes/{__init__.py => pod_runtime_info_env.py} | 14 ++++++++++----
.../kubernetes/{__init__.py => refresh_config.py} | 16 ++++++++++++----
.../__init__.py => contrib/kubernetes/secret.py} | 11 +++++++++++
airflow/contrib/kubernetes/{__init__.py => volume.py} | 14 ++++++++++----
.../contrib/kubernetes/{__init__.py => volume_mount.py} | 14 ++++++++++----
airflow/kubernetes/pod_launcher.py | 5 +++++
airflow/kubernetes/pod_launcher_helper.py | 2 +-
airflow/kubernetes/pod_runtime_info_env.py | 2 +-
airflow/kubernetes/secret.py | 4 +++-
airflow/kubernetes/volume_mount.py | 3 +--
tests/kubernetes/models/test_pod.py | 2 +-
tests/kubernetes/test_pod_launcher_helper.py | 5 +++--
15 files changed, 93 insertions(+), 32 deletions(-)
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/__init__.py
index ef7074c..b7f8352 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/__init__.py
@@ -17,5 +17,3 @@
# specific language governing permissions and limitations
# under the License.
#
-
-from airflow.kubernetes import * # noqa
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/kube_client.py
similarity index 71%
copy from airflow/contrib/kubernetes/__init__.py
copy to airflow/contrib/kubernetes/kube_client.py
index ef7074c..d785fac 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/kube_client.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -16,6 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
+"""This module is deprecated. Please use `airflow.kubernetes.kube_client`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.kube_client import * # noqa
-from airflow.kubernetes import * # noqa
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.kube_client`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/kubernetes_deprecated/pod.py b/airflow/contrib/kubernetes/pod.py
similarity index 92%
rename from airflow/kubernetes_deprecated/pod.py
rename to airflow/contrib/kubernetes/pod.py
index 22a8c12..0ab3616 100644
--- a/airflow/kubernetes_deprecated/pod.py
+++ b/airflow/contrib/kubernetes/pod.py
@@ -14,9 +14,17 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+"""This module is deprecated. Please use `airflow.kubernetes.pod`."""
-import kubernetes.client.models as k8s
-from airflow.kubernetes.pod import Resources
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.pod import Port, Resources # noqa
+
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.pod`.",
+ DeprecationWarning, stacklevel=2
+)
class Pod(object):
@@ -86,6 +94,10 @@ class Pod(object):
pod_runtime_info_envs=None,
dnspolicy=None
):
+ warnings.warn(
+ "Using `airflow.contrib.kubernetes.pod.Pod` is deprecated. Please use `k8s.V1Pod`.",
+ DeprecationWarning, stacklevel=2
+ )
self.image = image
self.envs = envs or {}
self.cmds = cmds
@@ -119,6 +131,7 @@ class Pod(object):
:return: k8s.V1Pod
"""
+ import kubernetes.client.models as k8s
meta = k8s.V1ObjectMeta(
labels=self.labels,
name=self.name,
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/pod_runtime_info_env.py
similarity index 68%
copy from airflow/contrib/kubernetes/__init__.py
copy to airflow/contrib/kubernetes/pod_runtime_info_env.py
index ef7074c..0dc8aed 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/pod_runtime_info_env.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -16,6 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
+"""This module is deprecated. Please use `airflow.kubernetes.pod_runtime_info_env`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.pod_runtime_info_env import PodRuntimeInfoEnv # noqa
-from airflow.kubernetes import * # noqa
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.pod_runtime_info_env`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/refresh_config.py
similarity index 66%
copy from airflow/contrib/kubernetes/__init__.py
copy to airflow/contrib/kubernetes/refresh_config.py
index ef7074c..f88069e 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/refresh_config.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -16,6 +14,16 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
+"""This module is deprecated. Please use `airflow.kubernetes.refresh_config`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.refresh_config import ( # noqa
+ RefreshConfiguration, RefreshKubeConfigLoader, load_kube_config
+)
-from airflow.kubernetes import * # noqa
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.refresh_config`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/kubernetes_deprecated/__init__.py b/airflow/contrib/kubernetes/secret.py
similarity index 71%
rename from airflow/kubernetes_deprecated/__init__.py
rename to airflow/contrib/kubernetes/secret.py
index 13a8339..ad41d4d 100644
--- a/airflow/kubernetes_deprecated/__init__.py
+++ b/airflow/contrib/kubernetes/secret.py
@@ -14,3 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+"""This module is deprecated. Please use `airflow.kubernetes.secret`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.secret import Secret # noqa
+
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.secret`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/volume.py
similarity index 72%
copy from airflow/contrib/kubernetes/__init__.py
copy to airflow/contrib/kubernetes/volume.py
index ef7074c..c72e208 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/volume.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -16,6 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
+"""This module is deprecated. Please use `airflow.kubernetes.volume`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.volume import Volume # noqa
-from airflow.kubernetes import * # noqa
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.volume`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/contrib/kubernetes/__init__.py b/airflow/contrib/kubernetes/volume_mount.py
similarity index 70%
copy from airflow/contrib/kubernetes/__init__.py
copy to airflow/contrib/kubernetes/volume_mount.py
index ef7074c..a474e3b 100644
--- a/airflow/contrib/kubernetes/__init__.py
+++ b/airflow/contrib/kubernetes/volume_mount.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -16,6 +14,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
+"""This module is deprecated. Please use `airflow.kubernetes.volume_mount`."""
+
+import warnings
+
+# pylint: disable=unused-import
+from airflow.kubernetes.volume_mount import VolumeMount # noqa
-from airflow.kubernetes import * # noqa
+warnings.warn(
+ "This module is deprecated. Please use `airflow.kubernetes.volume_mount`.",
+ DeprecationWarning, stacklevel=2
+)
diff --git a/airflow/kubernetes/pod_launcher.py b/airflow/kubernetes/pod_launcher.py
index 05df204..d6507df 100644
--- a/airflow/kubernetes/pod_launcher.py
+++ b/airflow/kubernetes/pod_launcher.py
@@ -17,6 +17,7 @@
"""Launches PODs"""
import json
import time
+import warnings
from datetime import datetime as dt
import tenacity
@@ -93,6 +94,10 @@ class PodLauncher(LoggingMixin):
# attempts to run pod_mutation_hook using k8s.V1Pod, if this
# fails we attempt to run by converting pod to Old Pod
except AttributeError:
+ warnings.warn(
+ "Using `airflow.contrib.kubernetes.pod.Pod` is deprecated. "
+ "Please use `k8s.V1Pod` instead.", DeprecationWarning, stacklevel=2
+ )
dummy_pod = convert_to_airflow_pod(pod)
settings.pod_mutation_hook(dummy_pod)
dummy_pod = dummy_pod.to_v1_kubernetes_pod()
diff --git a/airflow/kubernetes/pod_launcher_helper.py b/airflow/kubernetes/pod_launcher_helper.py
index d8b2698..8c9fc6e 100644
--- a/airflow/kubernetes/pod_launcher_helper.py
+++ b/airflow/kubernetes/pod_launcher_helper.py
@@ -21,7 +21,7 @@ import kubernetes.client.models as k8s # noqa
from airflow.kubernetes.volume import Volume
from airflow.kubernetes.volume_mount import VolumeMount
from airflow.kubernetes.pod import Port
-from airflow.kubernetes_deprecated.pod import Pod
+from airflow.contrib.kubernetes.pod import Pod
def convert_to_airflow_pod(pod):
diff --git a/airflow/kubernetes/pod_runtime_info_env.py b/airflow/kubernetes/pod_runtime_info_env.py
index 7d23a7e..72e2151 100644
--- a/airflow/kubernetes/pod_runtime_info_env.py
+++ b/airflow/kubernetes/pod_runtime_info_env.py
@@ -19,7 +19,6 @@ Classes for interacting with Kubernetes API
"""
import copy
-import kubernetes.client.models as k8s
from airflow.kubernetes.k8s_model import K8SModel
@@ -43,6 +42,7 @@ class PodRuntimeInfoEnv(K8SModel):
"""
:return: kubernetes.client.models.V1EnvVar
"""
+ import kubernetes.client.models as k8s
return k8s.V1EnvVar(
name=self.name,
value_from=k8s.V1EnvVarSource(
diff --git a/airflow/kubernetes/secret.py b/airflow/kubernetes/secret.py
index 8591a88..9ff1927 100644
--- a/airflow/kubernetes/secret.py
+++ b/airflow/kubernetes/secret.py
@@ -20,7 +20,6 @@ Classes for interacting with Kubernetes API
import uuid
import copy
-import kubernetes.client.models as k8s
from airflow.exceptions import AirflowConfigException
from airflow.kubernetes.k8s_model import K8SModel
@@ -65,6 +64,7 @@ class Secret(K8SModel):
self.key = key
def to_env_secret(self):
+ import kubernetes.client.models as k8s
return k8s.V1EnvVar(
name=self.deploy_target,
value_from=k8s.V1EnvVarSource(
@@ -76,11 +76,13 @@ class Secret(K8SModel):
)
def to_env_from_secret(self):
+ import kubernetes.client.models as k8s
return k8s.V1EnvFromSource(
secret_ref=k8s.V1SecretEnvSource(name=self.secret)
)
def to_volume_secret(self):
+ import kubernetes.client.models as k8s
vol_id = 'secretvol{}'.format(uuid.uuid4())
return (
k8s.V1Volume(
diff --git a/airflow/kubernetes/volume_mount.py b/airflow/kubernetes/volume_mount.py
index ab87ba9..ab9c34a 100644
--- a/airflow/kubernetes/volume_mount.py
+++ b/airflow/kubernetes/volume_mount.py
@@ -19,7 +19,6 @@ Classes for interacting with Kubernetes API
"""
import copy
-import kubernetes.client.models as k8s
from airflow.kubernetes.k8s_model import K8SModel
@@ -49,8 +48,8 @@ class VolumeMount(K8SModel):
Converts to k8s object.
:return Volume Mount k8s object
-
"""
+ import kubernetes.client.models as k8s
return k8s.V1VolumeMount(
name=self.name,
mount_path=self.mount_path,
diff --git a/tests/kubernetes/models/test_pod.py b/tests/kubernetes/models/test_pod.py
index 096b5f0..2e53d60 100644
--- a/tests/kubernetes/models/test_pod.py
+++ b/tests/kubernetes/models/test_pod.py
@@ -76,7 +76,7 @@ class TestPod(unittest.TestCase):
}, result)
def test_to_v1_pod(self):
- from airflow.kubernetes_deprecated.pod import Pod as DeprecatedPod
+ from airflow.contrib.kubernetes.pod import Pod as DeprecatedPod
from airflow.kubernetes.volume import Volume
from airflow.kubernetes.volume_mount import VolumeMount
from airflow.kubernetes.pod import Resources
diff --git a/tests/kubernetes/test_pod_launcher_helper.py b/tests/kubernetes/test_pod_launcher_helper.py
index a308ac3..761d138 100644
--- a/tests/kubernetes/test_pod_launcher_helper.py
+++ b/tests/kubernetes/test_pod_launcher_helper.py
@@ -20,7 +20,7 @@ from airflow.kubernetes.pod import Port
from airflow.kubernetes.volume_mount import VolumeMount
from airflow.kubernetes.volume import Volume
from airflow.kubernetes.pod_launcher_helper import convert_to_airflow_pod
-from airflow.kubernetes_deprecated.pod import Pod
+from airflow.contrib.kubernetes.pod import Pod
import kubernetes.client.models as k8s
@@ -84,7 +84,8 @@ class TestPodLauncherHelper(unittest.TestCase):
self.assertDictEqual(expected_dict, result_dict)
- def pull_out_volumes(self, result_dict):
+ @staticmethod
+ def pull_out_volumes(result_dict):
parsed_configs = []
for volume in result_dict['volumes']:
vol = {'name': volume['name']}