Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address API Changes Introduced in k8s v1.16 #966

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kubernetes/base
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,38 @@
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):
cls.config = base.get_e2e_configuration()

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:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
image: nginx:1.15.4
ports:
- containerPort: 80
'''
Expand All @@ -60,24 +63,27 @@ 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'},
'name': name},
'spec': {
'containers': [
{'name': 'nginx-app',
'image': 'nginx:1.10'},
'image': 'nginx:1.15.4'},
],
},
},
Expand All @@ -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)
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
17 changes: 9 additions & 8 deletions kubernetes/e2e_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/e2e_test/test_yaml/apps-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down