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

Remove deprecated extensions/v1beta1 API #46

Merged
merged 1 commit into from
Nov 28, 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
47 changes: 32 additions & 15 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,9 @@ class ReplicaSetServiceTestCase(KubernetesServiceTestCase):
def setUp(self):
super(ReplicaSetServiceTestCase, self).setUp()

from kubernetes.client.apis import extensions_v1beta1_api
from kubernetes.client.apis import apps_v1_api

p_mock_client = mock.patch.object(extensions_v1beta1_api,
"ExtensionsV1beta1Api")
p_mock_client = mock.patch.object(apps_v1_api, "AppsV1Api")
self.client_cls = p_mock_client.start()
self.client = self.client_cls.return_value
self.addCleanup(p_mock_client.stop)
Expand All @@ -1123,7 +1122,7 @@ def test_create_replicaset(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"metadata": {
"name": "name",
Expand Down Expand Up @@ -1177,7 +1176,7 @@ def test_create_replicaset_with_command(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"metadata": {
"name": "name",
Expand Down Expand Up @@ -1841,10 +1840,9 @@ class DeploymentServiceTestCase(KubernetesServiceTestCase):
def setUp(self):
super(DeploymentServiceTestCase, self).setUp()

from kubernetes.client.apis import extensions_v1beta1_api
from kubernetes.client.apis import apps_v1_api

p_mock_client = mock.patch.object(extensions_v1beta1_api,
"ExtensionsV1beta1Api")
p_mock_client = mock.patch.object(apps_v1_api, "AppsV1Api")
self.client_cls = p_mock_client.start()
self.client = self.client_cls.return_value
self.addCleanup(p_mock_client.stop)
Expand All @@ -1863,7 +1861,7 @@ def test_create_deployment(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "name",
Expand All @@ -1872,6 +1870,11 @@ def test_create_deployment(self):
}
},
"spec": {
"selector": {
"matchLabels": {
"app": mock.ANY
}
},
"replicas": 2,
"template": {
"metadata": {
Expand Down Expand Up @@ -1912,7 +1915,7 @@ def test_create_deployment_with_command(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "name",
Expand All @@ -1921,6 +1924,11 @@ def test_create_deployment_with_command(self):
}
},
"spec": {
"selector": {
"matchLabels": {
"app": mock.ANY
}
},
"replicas": 2,
"template": {
"metadata": {
Expand Down Expand Up @@ -3165,11 +3173,10 @@ class DaemonSetServiceTestCase(KubernetesServiceTestCase):
def setUp(self):
super(DaemonSetServiceTestCase, self).setUp()

from kubernetes.client.apis import apps_v1_api
from kubernetes.client.apis import core_v1_api
from kubernetes.client.apis import extensions_v1beta1_api

p_mock_client = mock.patch.object(extensions_v1beta1_api,
"ExtensionsV1beta1Api")
p_mock_client = mock.patch.object(apps_v1_api, "AppsV1Api")
self.client_cls = p_mock_client.start()
self.client = self.client_cls.return_value
self.addCleanup(p_mock_client.stop)
Expand All @@ -3193,12 +3200,17 @@ def test_create_daemonset(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "DaemonSet",
"metadata": {
"name": "name"
},
"spec": {
"selector": {
"matchLabels": {
"app": mock.ANY
}
},
"template": {
"metadata": {
"name": "name",
Expand Down Expand Up @@ -3238,12 +3250,17 @@ def test_create_daemonset_with_command(self):
status_wait=False)

expected = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "DaemonSet",
"metadata": {
"name": "name"
},
"spec": {
"selector": {
"matchLabels": {
"app": mock.ANY
}
},
"template": {
"metadata": {
"name": "name",
Expand Down
40 changes: 24 additions & 16 deletions xrally_kubernetes/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from kubernetes.client.apis import apps_v1_api
from kubernetes.client.apis import batch_v1_api
from kubernetes.client.apis import core_v1_api
from kubernetes.client.apis import extensions_v1beta1_api
from kubernetes.client.apis import storage_v1_api
from kubernetes.client.apis import version_api
from kubernetes.client import rest
Expand Down Expand Up @@ -204,7 +203,6 @@ def __init__(self, spec, name_generator=None, atomic_inst=None):

self.api = api
self.v1_client = core_v1_api.CoreV1Api(api)
self.v1beta1_ext = extensions_v1beta1_api.ExtensionsV1beta1Api(api)
self.v1_batch = batch_v1_api.BatchV1Api(api)
self.v1_apps = apps_v1_api.AppsV1Api(api)
self.v1_storage = storage_v1_api.StorageV1Api(api)
Expand Down Expand Up @@ -609,7 +607,7 @@ def delete_rc(self, name, namespace, status_wait=True):

@atomic.action_timer("kubernetes.get_replicaset")
def get_replicaset(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_replica_set(
return self.v1_apps.read_namespaced_replica_set(
name,
namespace=namespace
)
Expand Down Expand Up @@ -639,7 +637,7 @@ def create_replicaset(self, namespace, replicas, image, command=None,
container_spec["command"] = list(command)

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"metadata": {
"name": name,
Expand Down Expand Up @@ -672,7 +670,7 @@ def create_replicaset(self, namespace, replicas, image, command=None,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_replica_set(
self.v1_apps.create_namespaced_replica_set(
namespace=namespace,
body=manifest
)
Expand All @@ -690,7 +688,7 @@ def create_replicaset(self, namespace, replicas, image, command=None,

@atomic.action_timer("kubernetes.scale_replicaset")
def scale_replicaset(self, name, namespace, replicas, status_wait=True):
self.v1beta1_ext.patch_namespaced_replica_set(
self.v1_apps.patch_namespaced_replica_set(
name,
namespace=namespace,
body={"spec": {"replicas": replicas}}
Expand All @@ -713,7 +711,7 @@ def delete_replicaset(self, name, namespace, status_wait=True):
:param namespace: replicaset namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_replica_set(
self.v1_apps.delete_namespaced_replica_set(
name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand All @@ -729,7 +727,7 @@ def delete_replicaset(self, name, namespace, status_wait=True):

@atomic.action_timer("kubernetes.get_deployment")
def get_deployment(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_deployment_status(
return self.v1_apps.read_namespaced_deployment_status(
name=name,
namespace=namespace
)
Expand Down Expand Up @@ -771,7 +769,7 @@ def create_deployment(self, namespace, replicas, image, resources=None,
container_spec["resources"] = resources

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": name,
Expand All @@ -780,6 +778,11 @@ def create_deployment(self, namespace, replicas, image, resources=None,
}
},
"spec": {
"selector": {
"matchLabels": {
"app": app
}
},
"replicas": replicas,
"template": {
"metadata": {
Expand All @@ -799,7 +802,7 @@ def create_deployment(self, namespace, replicas, image, resources=None,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_deployment(
self.v1_apps.create_namespaced_deployment(
namespace=namespace,
body=manifest
)
Expand Down Expand Up @@ -843,7 +846,7 @@ def rollout_deployment(self, name, namespace, changes, replicas,
"exclusive keys: image, env, resources."
)

self.v1beta1_ext.patch_namespaced_deployment(
self.v1_apps.patch_namespaced_deployment(
name=name,
namespace=namespace,
body=deployment
Expand All @@ -866,7 +869,7 @@ def delete_deployment(self, name, namespace, status_wait=True):
:param namespace: deployment namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_deployment(
self.v1_apps.delete_namespaced_deployment(
name=name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand Down Expand Up @@ -1164,7 +1167,7 @@ def list_nodes(self, node_labels=None):

@atomic.action_timer("kubernetes.get_daemonset")
def get_daemonset(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_daemon_set(
return self.v1_apps.read_namespaced_daemon_set(
name,
namespace=namespace
)
Expand Down Expand Up @@ -1195,12 +1198,17 @@ def create_daemonset(self, image, namespace, command=None,
container_spec["command"] = list(command)

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "DaemonSet",
"metadata": {
"name": name
},
"spec": {
"selector": {
"matchLabels": {
"app": app
}
},
"template": {
"metadata": {
"name": name,
Expand All @@ -1219,7 +1227,7 @@ def create_daemonset(self, image, namespace, command=None,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_daemon_set(
self.v1_apps.create_namespaced_daemon_set(
namespace=namespace,
body=manifest
)
Expand Down Expand Up @@ -1280,7 +1288,7 @@ def delete_daemonset(self, name, namespace, status_wait=True):
:param namespace: daemon set namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_daemon_set(
self.v1_apps.delete_namespaced_daemon_set(
name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand Down