Skip to content

Commit c310289

Browse files
authored
Merge pull request kubernetes-client#966 from micw523/testfix116
Address API Changes Introduced in k8s v1.16
2 parents a05c331 + fd9de42 commit c310289

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

kubernetes/e2e_test/test_extensions.py kubernetes/e2e_test/test_apps.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,38 @@
1717
import yaml
1818

1919
from kubernetes.client import api_client
20-
from kubernetes.client.apis import extensions_v1beta1_api
20+
from kubernetes.client.apis import apps_v1_api
2121
from kubernetes.client.models import v1_delete_options
2222
from kubernetes.e2e_test import base
2323

2424

25-
class TestClientExtensions(unittest.TestCase):
25+
class TestClientApps(unittest.TestCase):
2626

2727
@classmethod
2828
def setUpClass(cls):
2929
cls.config = base.get_e2e_configuration()
3030

3131
def test_create_deployment(self):
3232
client = api_client.ApiClient(configuration=self.config)
33-
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
33+
api = apps_v1_api.AppsV1Api(client)
3434
name = 'nginx-deployment-' + str(uuid.uuid4())
35-
deployment = '''apiVersion: extensions/v1beta1
35+
deployment = '''apiVersion: apps/v1
3636
kind: Deployment
3737
metadata:
3838
name: %s
3939
spec:
4040
replicas: 3
41+
selector:
42+
matchLabels:
43+
app: nginx
4144
template:
4245
metadata:
4346
labels:
4447
app: nginx
4548
spec:
4649
containers:
4750
- name: nginx
48-
image: nginx:1.7.9
51+
image: nginx:1.15.4
4952
ports:
5053
- containerPort: 80
5154
'''
@@ -60,24 +63,27 @@ def test_create_deployment(self):
6063

6164
def test_create_daemonset(self):
6265
client = api_client.ApiClient(configuration=self.config)
63-
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
66+
api = apps_v1_api.AppsV1Api(client)
6467
name = 'nginx-app-' + str(uuid.uuid4())
6568
daemonset = {
66-
'apiVersion': 'extensions/v1beta1',
69+
'apiVersion': 'apps/v1',
6770
'kind': 'DaemonSet',
6871
'metadata': {
6972
'labels': {'app': 'nginx'},
7073
'name': '%s' % name,
7174
},
7275
'spec': {
76+
'selector': {
77+
'matchLabels': {'app': 'nginx'},
78+
},
7379
'template': {
7480
'metadata': {
7581
'labels': {'app': 'nginx'},
7682
'name': name},
7783
'spec': {
7884
'containers': [
7985
{'name': 'nginx-app',
80-
'image': 'nginx:1.10'},
86+
'image': 'nginx:1.15.4'},
8187
],
8288
},
8389
},
@@ -91,4 +97,4 @@ def test_create_daemonset(self):
9197
self.assertIsNotNone(resp)
9298

9399
options = v1_delete_options.V1DeleteOptions()
94-
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
100+
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)

kubernetes/e2e_test/test_utils.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def tearDownClass(cls):
4141

4242
def test_create_apps_deployment_from_yaml(self):
4343
"""
44-
Should be able to create an apps/v1beta1 deployment.
44+
Should be able to create an apps/v1 deployment.
4545
"""
4646
k8s_client = client.api_client.ApiClient(configuration=self.config)
4747
utils.create_from_yaml(
4848
k8s_client, self.path_prefix + "apps-deployment.yaml")
49-
app_api = client.AppsV1beta1Api(k8s_client)
49+
app_api = client.AppsV1Api(k8s_client)
5050
dep = app_api.read_namespaced_deployment(name="nginx-app",
5151
namespace="default")
5252
self.assertIsNotNone(dep)
@@ -68,7 +68,7 @@ def test_create_apps_deployment_from_yaml_obj(self):
6868

6969
utils.create_from_dict(k8s_client, yml_obj)
7070

71-
app_api = client.AppsV1beta1Api(k8s_client)
71+
app_api = client.AppsV1Api(k8s_client)
7272
dep = app_api.read_namespaced_deployment(name="nginx-app-3",
7373
namespace="default")
7474
self.assertIsNotNone(dep)
@@ -289,7 +289,7 @@ def test_create_from_list_in_multi_resource_yaml(self):
289289
utils.create_from_yaml(
290290
k8s_client, self.path_prefix + "multi-resource-with-list.yaml")
291291
core_api = client.CoreV1Api(k8s_client)
292-
app_api = client.AppsV1beta1Api(k8s_client)
292+
app_api = client.AppsV1Api(k8s_client)
293293
pod_0 = core_api.read_namespaced_pod(
294294
name="mock-pod-0", namespace="default")
295295
self.assertIsNotNone(pod_0)
@@ -365,15 +365,16 @@ def test_create_from_multi_resource_yaml_with_multi_conflicts(self):
365365
name="triple-nginx", namespace="default",
366366
body={})
367367

368-
def test_create_namespaces_apps_deployment_from_yaml(self):
368+
def test_create_namespaced_apps_deployment_from_yaml(self):
369369
"""
370-
Should be able to create an apps/v1beta1 deployment.
370+
Should be able to create an apps/v1beta1 deployment
371+
in a test namespace.
371372
"""
372373
k8s_client = client.api_client.ApiClient(configuration=self.config)
373374
utils.create_from_yaml(
374375
k8s_client, self.path_prefix + "apps-deployment.yaml",
375376
namespace=self.test_namespace)
376-
app_api = client.AppsV1beta1Api(k8s_client)
377+
app_api = client.AppsV1Api(k8s_client)
377378
dep = app_api.read_namespaced_deployment(name="nginx-app",
378379
namespace=self.test_namespace)
379380
self.assertIsNotNone(dep)
@@ -391,7 +392,7 @@ def test_create_from_list_in_multi_resource_yaml_namespaced(self):
391392
k8s_client, self.path_prefix + "multi-resource-with-list.yaml",
392393
namespace=self.test_namespace)
393394
core_api = client.CoreV1Api(k8s_client)
394-
app_api = client.AppsV1beta1Api(k8s_client)
395+
app_api = client.AppsV1Api(k8s_client)
395396
pod_0 = core_api.read_namespaced_pod(
396397
name="mock-pod-0", namespace=self.test_namespace)
397398
self.assertIsNotNone(pod_0)

kubernetes/e2e_test/test_yaml/apps-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: apps/v1beta1
1+
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: nginx-app

kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ items:
2424
image: busybox
2525
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
2626
---
27-
apiVersion: apps/v1beta1
27+
apiVersion: apps/v1
2828
kind: Deployment
2929
metadata:
3030
name: mock

0 commit comments

Comments
 (0)