Skip to content

Commit 8578db8

Browse files
committed
feat(controller): remove deprecated api
1 parent 1fed91a commit 8578db8

11 files changed

Lines changed: 37 additions & 46 deletions

File tree

charts/controller/templates/controller-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: extensions/v1beta1
1+
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: drycc-controller

charts/controller/templates/controller-ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: extensions/v1beta1
1+
apiVersion: networking.k8s.io/v1beta1
22
kind: Ingress
33
metadata:
44
namespace: "{{ .Release.Namespace }}"

rootfs/api/models/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def autoscale(self, proc_type, autoscale):
10231023
name = '{}-{}'.format(self.id, proc_type)
10241024
# basically fake out a Deployment object (only thing we use) to assign to the HPA
10251025
target = {
1026-
'apiVersion': 'extensions/v1beta1',
1026+
'apiVersion': 'apps/v1',
10271027
'kind': 'Deployment',
10281028
'metadata': {'name': name}}
10291029

rootfs/scheduler/mock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,9 @@ def post(request, context):
687687

688688
# don't bother adding it to those two resources since they live outside namespace
689689
if resource_type not in ['nodes', 'namespaces']:
690-
namespace = request.url.replace(settings.SCHEDULER_URL + '/api/v1/namespaces/', '')
691-
namespace = namespace.replace(settings.SCHEDULER_URL + '/apis/extensions/v1beta1/namespaces/', '') # noqa
690+
namespace = request.url.replace(settings.SCHEDULER_URL, '')
691+
namespace = namespace.replace('/api/v1/namespaces/', '')
692+
namespace = re.sub(r'/apis/.{1,}/.{1,}/namespaces/', '', namespace)
692693
namespace = namespace.split('/')[0]
693694
data['metadata']['namespace'] = namespace
694695

rootfs/scheduler/resources/deployment.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
class Deployment(Resource):
1010
api_prefix = 'apis'
11+
api_version = 'apps/v1'
1112

12-
@property
13-
def api_version(self):
14-
if self.version() >= parse("1.9.0"):
15-
return 'extensions/v1beta1'
16-
return 'extensions/v1beta1'
1713

1814
def get(self, namespace, name=None, **kwargs):
1915
"""

rootfs/scheduler/resources/horizontalpodautoscaler.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@
77

88
class HorizontalPodAutoscaler(Resource):
99
api_prefix = 'apis'
10+
api_version = 'autoscaling/v1'
1011
short_name = 'hpa'
1112

12-
@property
13-
def api_version(self):
14-
# API location changes between versions
15-
# http://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/#api-object
16-
if self.version() >= parse("1.3.0"):
17-
return 'autoscaling/v1'
18-
19-
# 1.2 and older
20-
return 'extensions/v1beta1'
2113

2214
def get(self, namespace, name=None, **kwargs):
2315
"""

rootfs/scheduler/resources/ingress.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66

77
class BaseManifest(object):
88

9-
def manifest(self, ingress, ingress_class, namespace, **kwargs):
9+
def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
1010
path = "/*" if ingress_class in ("gce", "alb") else "/"
1111
hosts, tls = kwargs.pop("hosts", None), kwargs.pop("tls", None)
1212
version = kwargs.pop("version", None)
1313
data = {
1414
"kind": "Ingress",
15-
"apiVersion": "extensions/v1beta1",
15+
"apiVersion": api_version,
1616
"metadata": {
1717
"name": ingress,
1818
"annotations": {
1919
"kubernetes.io/tls-acme": "true",
2020
}
2121
},
22-
"spec": {}
23-
}
22+
"spec": {} }
2423
if hosts:
2524
data["spec"]["rules"] = [{
2625
"host": host,
@@ -49,9 +48,9 @@ def manifest(self, ingress, ingress_class, namespace, **kwargs):
4948

5049
class NginxManifest(BaseManifest):
5150

52-
def manifest(self, ingress, ingress_class, namespace, **kwargs):
51+
def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
5352
data = BaseManifest.manifest(
54-
self, ingress, ingress_class, namespace, **kwargs)
53+
self, api_version, ingress, ingress_class, namespace, **kwargs)
5554
if "whitelist" in kwargs:
5655
whitelist = ", ".join(kwargs.pop("whitelist"))
5756
data["metadata"]["annotations"].update({
@@ -70,9 +69,9 @@ def manifest(self, ingress, ingress_class, namespace, **kwargs):
7069

7170
class TraefikManifest(BaseManifest):
7271

73-
def manifest(self, ingress, ingress_class, namespace, **kwargs):
72+
def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
7473
data = BaseManifest.manifest(
75-
self, ingress, ingress_class, namespace, **kwargs)
74+
self, api_version, ingress, ingress_class, namespace, **kwargs)
7675
if "whitelist" in kwargs:
7776
whitelist = ", ".join(kwargs.pop("whitelist"))
7877
data["metadata"]["annotations"].update({
@@ -91,22 +90,25 @@ def manifest(self, ingress, ingress_class, namespace, **kwargs):
9190

9291

9392
class Ingress(Resource):
93+
94+
api_version = 'networking.k8s.io/v1beta1'
95+
api_prefix = 'apis'
9496
short_name = 'ingress'
9597

96-
def manifest(self, ingress, ingress_class, namespace, **kwargs):
98+
def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
9799
return MANIFEAT_CLASSES.get(ingress_class, BaseManifest)().manifest(
98-
ingress, ingress_class, namespace, **kwargs
100+
api_version, ingress, ingress_class, namespace, **kwargs
99101
)
100102

101-
def get(self, namespace, name=None, **kwargs):
103+
def get(self, namespace, ingress=None, **kwargs):
102104
"""
103105
Fetch a single Ingress or a list of Ingresses
104106
"""
105-
if name is not None:
106-
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (namespace, name)
107-
message = 'get Ingress ' + name
107+
if ingress is not None:
108+
url = self.api("/namespaces/{}/ingresses/{}", namespace, ingress)
109+
message = 'get Ingress ' + ingress
108110
else:
109-
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses" % namespace
111+
url = self.api("/namespaces/{}/ingresses", namespace)
110112
message = 'get Ingresses'
111113

112114
response = self.http_get(url, params=self.query_params(**kwargs))
@@ -116,8 +118,8 @@ def get(self, namespace, name=None, **kwargs):
116118
return response
117119

118120
def create(self, ingress, ingress_class, namespace, **kwargs):
119-
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses" % namespace
120-
data = self.manifest(ingress, ingress_class, namespace, **kwargs)
121+
url = self.api("/namespaces/{}/ingresses", namespace)
122+
data = self.manifest(self.api_version, ingress, ingress_class, namespace, **kwargs)
121123
response = self.http_post(url, json=data)
122124

123125
if not response.status_code == 201:
@@ -126,9 +128,9 @@ def create(self, ingress, ingress_class, namespace, **kwargs):
126128
return response
127129

128130
def put(self, ingress, ingress_class, namespace, version, **kwargs):
129-
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (namespace, ingress)
131+
url = self.api("/namespaces/{}/ingresses/{}", namespace, ingress)
130132
kwargs["version"] = version
131-
data = self.manifest(ingress, ingress_class, namespace, **kwargs)
133+
data = self.manifest(self.api_version, ingress, ingress_class, namespace, **kwargs)
132134
response = self.http_put(url, json=data)
133135

134136
if self.unhealthy(response.status_code):
@@ -137,7 +139,7 @@ def put(self, ingress, ingress_class, namespace, version, **kwargs):
137139
return response
138140

139141
def delete(self, namespace, ingress):
140-
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (namespace, ingress)
142+
url = self.api("/namespaces/{}/ingresses/{}", namespace, ingress)
141143
response = self.http_delete(url)
142144
if self.unhealthy(response.status_code):
143145
raise KubeHTTPException(response, 'delete Ingress "{}"', namespace)

rootfs/scheduler/resources/replicaset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ReplicaSet(Resource):
66
api_prefix = 'apis'
7-
api_version = 'extensions/v1beta1'
7+
api_version = 'apps/v1'
88
short_name = 'rs'
99

1010
def get(self, namespace, name=None, **kwargs):

rootfs/scheduler/tests/test_deployments.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_deployment_api_version_1_9_and_up(self):
9696

9797
deployment = copy.copy(self.scheduler.deployment)
9898

99-
expected = 'extensions/v1beta1'
99+
expected = 'apps/v1'
100100

101101
for canonical in cases:
102102
deployment.version = mock.MagicMock(return_value=parse(canonical))
@@ -114,7 +114,7 @@ def test_deployment_api_version_1_8_and_lower(self):
114114

115115
deployment = copy.copy(self.scheduler.deployment)
116116

117-
expected = 'extensions/v1beta1'
117+
expected = 'apps/v1'
118118

119119
for canonical in cases:
120120
deployment.version = mock.MagicMock(return_value=parse(canonical))
@@ -210,7 +210,7 @@ def test_get_deployment(self):
210210
response = self.scheduler.deployment.get(self.namespace, name)
211211
data = response.json()
212212
self.assertEqual(response.status_code, 200, data)
213-
self.assertEqual(data['apiVersion'], 'extensions/v1beta1')
213+
self.assertEqual(data['apiVersion'], 'apps/v1')
214214
self.assertEqual(data['kind'], 'Deployment')
215215
self.assertEqual(data['metadata']['name'], name)
216216
self.assertDictContainsSubset(
@@ -285,7 +285,7 @@ def test_get_deployment_replicaset(self):
285285
data = response.json()
286286

287287
self.assertEqual(response.status_code, 200, data)
288-
self.assertEqual(data['apiVersion'], 'extensions/v1beta1', data)
288+
self.assertEqual(data['apiVersion'], 'apps/v1', data)
289289
self.assertEqual(data['kind'], 'ReplicaSet', data)
290290
self.assertEqual(data['metadata']['name'], replica_name, data)
291291
self.assertDictContainsSubset(

rootfs/scheduler/tests/test_horizontalpodautoscaler_12_lower.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_get_horizontalpodautoscaler(self):
212212
response = self.scheduler.hpa.get(self.namespace, name)
213213
data = response.json()
214214
self.assertEqual(response.status_code, 200, data)
215-
self.assertEqual(data['apiVersion'], 'extensions/v1beta1')
215+
self.assertEqual(data['apiVersion'], 'autoscaling/v1')
216216
self.assertEqual(data['kind'], 'HorizontalPodAutoscaler')
217217
self.assertEqual(data['metadata']['name'], name)
218218
self.assertDictContainsSubset(

0 commit comments

Comments
 (0)