From fd9de42babef226ae8bf67f316593fc422645318 Mon Sep 17 00:00:00 2001 From: micw523 Date: Tue, 24 Sep 2019 16:30:10 -0400 Subject: [PATCH] Fix deprecations introduced in v1.16 --- kubernetes/base | 2 +- .../{test_extensions.py => test_apps.py} | 24 ++++++++++++------- kubernetes/e2e_test/test_utils.py | 17 ++++++------- .../e2e_test/test_yaml/apps-deployment.yaml | 2 +- .../test_yaml/multi-resource-with-list.yaml | 2 +- 5 files changed, 27 insertions(+), 20 deletions(-) rename kubernetes/e2e_test/{test_extensions.py => test_apps.py} (84%) diff --git a/kubernetes/base b/kubernetes/base index 5092d96134..f2ae80b53a 160000 --- a/kubernetes/base +++ b/kubernetes/base @@ -1 +1 @@ -Subproject commit 5092d9613476673908fa9df7c55da83bc3be53d8 +Subproject commit f2ae80b53a9516474fb321926576755973785f4d diff --git a/kubernetes/e2e_test/test_extensions.py b/kubernetes/e2e_test/test_apps.py similarity index 84% rename from kubernetes/e2e_test/test_extensions.py rename to kubernetes/e2e_test/test_apps.py index b659910317..1908374a3e 100644 --- a/kubernetes/e2e_test/test_extensions.py +++ b/kubernetes/e2e_test/test_apps.py @@ -17,12 +17,12 @@ import yaml from kubernetes.client import api_client -from kubernetes.client.apis import extensions_v1beta1_api +from kubernetes.client.apis import apps_v1_api from kubernetes.client.models import v1_delete_options from kubernetes.e2e_test import base -class TestClientExtensions(unittest.TestCase): +class TestClientApps(unittest.TestCase): @classmethod def setUpClass(cls): @@ -30,14 +30,17 @@ def setUpClass(cls): def test_create_deployment(self): client = api_client.ApiClient(configuration=self.config) - api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) + api = apps_v1_api.AppsV1Api(client) name = 'nginx-deployment-' + str(uuid.uuid4()) - deployment = '''apiVersion: extensions/v1beta1 + deployment = '''apiVersion: apps/v1 kind: Deployment metadata: name: %s spec: replicas: 3 + selector: + matchLabels: + app: nginx template: metadata: labels: @@ -45,7 +48,7 @@ def test_create_deployment(self): spec: containers: - name: nginx - image: nginx:1.7.9 + image: nginx:1.15.4 ports: - containerPort: 80 ''' @@ -60,16 +63,19 @@ def test_create_deployment(self): def test_create_daemonset(self): client = api_client.ApiClient(configuration=self.config) - api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) + api = apps_v1_api.AppsV1Api(client) name = 'nginx-app-' + str(uuid.uuid4()) daemonset = { - 'apiVersion': 'extensions/v1beta1', + 'apiVersion': 'apps/v1', 'kind': 'DaemonSet', 'metadata': { 'labels': {'app': 'nginx'}, 'name': '%s' % name, }, 'spec': { + 'selector': { + 'matchLabels': {'app': 'nginx'}, + }, 'template': { 'metadata': { 'labels': {'app': 'nginx'}, @@ -77,7 +83,7 @@ def test_create_daemonset(self): 'spec': { 'containers': [ {'name': 'nginx-app', - 'image': 'nginx:1.10'}, + 'image': 'nginx:1.15.4'}, ], }, }, @@ -91,4 +97,4 @@ def test_create_daemonset(self): self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() - resp = api.delete_namespaced_daemon_set(name, 'default', body=options) \ No newline at end of file + resp = api.delete_namespaced_daemon_set(name, 'default', body=options) diff --git a/kubernetes/e2e_test/test_utils.py b/kubernetes/e2e_test/test_utils.py index 075a7baf27..ab752dff79 100644 --- a/kubernetes/e2e_test/test_utils.py +++ b/kubernetes/e2e_test/test_utils.py @@ -41,12 +41,12 @@ def tearDownClass(cls): def test_create_apps_deployment_from_yaml(self): """ - Should be able to create an apps/v1beta1 deployment. + Should be able to create an apps/v1 deployment. """ k8s_client = client.api_client.ApiClient(configuration=self.config) utils.create_from_yaml( k8s_client, self.path_prefix + "apps-deployment.yaml") - app_api = client.AppsV1beta1Api(k8s_client) + app_api = client.AppsV1Api(k8s_client) dep = app_api.read_namespaced_deployment(name="nginx-app", namespace="default") self.assertIsNotNone(dep) @@ -68,7 +68,7 @@ def test_create_apps_deployment_from_yaml_obj(self): utils.create_from_dict(k8s_client, yml_obj) - app_api = client.AppsV1beta1Api(k8s_client) + app_api = client.AppsV1Api(k8s_client) dep = app_api.read_namespaced_deployment(name="nginx-app-3", namespace="default") self.assertIsNotNone(dep) @@ -289,7 +289,7 @@ def test_create_from_list_in_multi_resource_yaml(self): utils.create_from_yaml( k8s_client, self.path_prefix + "multi-resource-with-list.yaml") core_api = client.CoreV1Api(k8s_client) - app_api = client.AppsV1beta1Api(k8s_client) + app_api = client.AppsV1Api(k8s_client) pod_0 = core_api.read_namespaced_pod( name="mock-pod-0", namespace="default") self.assertIsNotNone(pod_0) @@ -365,15 +365,16 @@ def test_create_from_multi_resource_yaml_with_multi_conflicts(self): name="triple-nginx", namespace="default", body={}) - def test_create_namespaces_apps_deployment_from_yaml(self): + def test_create_namespaced_apps_deployment_from_yaml(self): """ - Should be able to create an apps/v1beta1 deployment. + Should be able to create an apps/v1beta1 deployment + in a test namespace. """ k8s_client = client.api_client.ApiClient(configuration=self.config) utils.create_from_yaml( k8s_client, self.path_prefix + "apps-deployment.yaml", namespace=self.test_namespace) - app_api = client.AppsV1beta1Api(k8s_client) + app_api = client.AppsV1Api(k8s_client) dep = app_api.read_namespaced_deployment(name="nginx-app", namespace=self.test_namespace) self.assertIsNotNone(dep) @@ -391,7 +392,7 @@ def test_create_from_list_in_multi_resource_yaml_namespaced(self): k8s_client, self.path_prefix + "multi-resource-with-list.yaml", namespace=self.test_namespace) core_api = client.CoreV1Api(k8s_client) - app_api = client.AppsV1beta1Api(k8s_client) + app_api = client.AppsV1Api(k8s_client) pod_0 = core_api.read_namespaced_pod( name="mock-pod-0", namespace=self.test_namespace) self.assertIsNotNone(pod_0) diff --git a/kubernetes/e2e_test/test_yaml/apps-deployment.yaml b/kubernetes/e2e_test/test_yaml/apps-deployment.yaml index a2ffa6b996..eb33bbac55 100644 --- a/kubernetes/e2e_test/test_yaml/apps-deployment.yaml +++ b/kubernetes/e2e_test/test_yaml/apps-deployment.yaml @@ -1,4 +1,4 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: nginx-app diff --git a/kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml b/kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml index b3228b8cde..996e4b6961 100644 --- a/kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml +++ b/kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml @@ -24,7 +24,7 @@ items: image: busybox command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600'] --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: mock