Skip to content

Commit cc32c4e

Browse files
committed
fix(controller): test pass
1 parent 5ce5499 commit cc32c4e

7 files changed

Lines changed: 22 additions & 18 deletions

File tree

rootfs/api/models/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ def _refresh_tls(self, certs_auto_enabled, hosts):
171171
if data:
172172
version = data["metadata"]["resourceVersion"]
173173
self._scheduler.certificate.put(
174-
namespace, name, settings.INGRESS_CLASS, hosts, version)
174+
namespace, name, hosts, version)
175175
else:
176176
self._scheduler.certificate.create(
177-
namespace, name, settings.INGRESS_CLASS, hosts)
177+
namespace, name, hosts)
178178
elif data:
179179
self._scheduler.certificate.delete(namespace, name)
180180

rootfs/api/tests/test_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_app_name_length(self, mock_requests):
7878
name = 'a' * 64
7979
body = {'id': name}
8080
response = self.client.post('/v2/apps', body)
81-
print(response)
8281
self.assertEqual(
8382
response.data,
8483
{'id': ['Ensure this field has no more than 63 characters.']}

rootfs/scheduler/mock.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ def get_type(key):
119119
return 'unknown'
120120

121121

122+
def replace_api_version(old, new='api_v1'):
123+
return old.replace('apis_autoscaling_v1', new)\
124+
.replace('apis_apps_v1', new)\
125+
.replace('apis_networking.k8s.io_v1beta1', new)
126+
127+
122128
def get_namespace(url, resource_type):
123129
"""Inspects the URL and gets namespace from it if there is any"""
124130
# correct back to proper namespace API
125-
url = url.replace('apis_autoscaling_v1', 'api_v1')
126-
url = url.replace('apis_extensions_v1beta1', 'api_v1')
131+
url = replace_api_version(url)
127132
# check if this is a subresource
128133
subresource, resource_type, url = is_subresource(resource_type, url)
129134
# get namespace name
@@ -391,7 +396,8 @@ def upsert_pods(controller, url):
391396
# turn RC / RS (which a Deployment creates) url into pods one
392397
url = url.replace(cache_key(controller['metadata']['name']), '')
393398
if '_replicasets_' in url:
394-
url = url.replace('_replicasets_', '_pods').replace('apis_extensions_v1beta1', 'api_v1') # noqa
399+
url = url.replace('_replicasets_', '_pods')
400+
url = replace_api_version(url)
395401
else:
396402
url = url.replace('_replicationcontrollers_', '_pods')
397403
# make sure url only has up to "_pods"
@@ -512,7 +518,8 @@ def manage_replicasets(deployment, url):
512518

513519
def update_deployment_status(namespaced_url, url, deployment, rs):
514520
# Fill out deployment.status for success as pods transition to running state
515-
pod_url = namespaced_url.replace('_replicasets', '_pods').replace('apis_extensions_v1beta1', 'api_v1') # noqa
521+
pod_url = namespaced_url.replace('_replicasets', '_pods')
522+
pod_url = replace_api_version(pod_url)
516523
while True:
517524
# The below needs to be done to emulate Deployment handling things
518525
# always cleanup pods
@@ -689,7 +696,7 @@ def post(request, context):
689696
if resource_type not in ['nodes', 'namespaces']:
690697
namespace = request.url.replace(settings.SCHEDULER_URL, '')
691698
namespace = namespace.replace('/api/v1/namespaces/', '')
692-
namespace = re.sub(r'/apis/.{1,}/.{1,}/namespaces/', '', namespace)
699+
namespace = re.sub(r'/apis/.+/.+/namespaces/', '', namespace)
693700
namespace = namespace.split('/')[0]
694701
data['metadata']['namespace'] = namespace
695702

rootfs/scheduler/resources/certificate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Certificate(Resource):
77
api_prefix = 'apis'
88

99
@staticmethod
10-
def manifest(api_version, namespace, name, ingress_class, hosts, version=None):
10+
def manifest(api_version, namespace, name, hosts, version=None):
1111
data = {
1212
"apiVersion": api_version,
1313
"kind": "Certificate",
@@ -44,20 +44,20 @@ def get(self, namespace, name=None, **kwargs):
4444

4545
return response
4646

47-
def create(self, namespace, name, ingress_class, hosts):
47+
def create(self, namespace, name, hosts):
4848

4949
url = self.api('/namespaces/{}/certificates', namespace)
50-
data = self.manifest(self.api_version, namespace, name, ingress_class, hosts)
50+
data = self.manifest(self.api_version, namespace, name, hosts)
5151
response = self.http_post(url, json=data)
5252

5353
if not response.status_code == 201:
5454
raise KubeHTTPException(response, "create certificate {}".format(namespace))
5555

5656
return response
5757

58-
def put(self, namespace, name, ingress_class, hosts, version):
58+
def put(self, namespace, name, hosts, version):
5959
url = self.api('/namespaces/{}/certificates/{}', namespace, name)
60-
data = self.manifest(self.api_version, namespace, name, ingress_class, hosts, version)
60+
data = self.manifest(self.api_version, namespace, name, hosts, version)
6161
response = self.http_put(url, json=data)
6262

6363
if self.unhealthy(response.status_code):

rootfs/scheduler/resources/deployment.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime, timedelta
22
import json
33
import time
4-
from packaging.version import parse
54
from scheduler.resources import Resource
65
from scheduler.exceptions import KubeException, KubeHTTPException
76

@@ -10,7 +9,6 @@ class Deployment(Resource):
109
api_prefix = 'apis'
1110
api_version = 'apps/v1'
1211

13-
1412
def get(self, namespace, name=None, **kwargs):
1513
"""
1614
Fetch a single Deployment or a list

rootfs/scheduler/resources/horizontalpodautoscaler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class HorizontalPodAutoscaler(Resource):
1010
api_version = 'autoscaling/v1'
1111
short_name = 'hpa'
1212

13-
1413
def get(self, namespace, name=None, **kwargs):
1514
"""
1615
Fetch a single HorizontalPodAutoscaler or a list

rootfs/scheduler/resources/ingress.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
1919
"kubernetes.io/tls-acme": "true",
2020
}
2121
},
22-
"spec": {} }
22+
"spec": {}
23+
}
2324
if hosts:
2425
data["spec"]["rules"] = [{
2526
"host": host,
@@ -90,7 +91,7 @@ def manifest(self, api_version, ingress, ingress_class, namespace, **kwargs):
9091

9192

9293
class Ingress(Resource):
93-
94+
9495
api_version = 'networking.k8s.io/v1beta1'
9596
api_prefix = 'apis'
9697
short_name = 'ingress'

0 commit comments

Comments
 (0)