Skip to content

Commit 903525a

Browse files
committed
feat(scheduler): add more functions to fetch on the global endpoints for various resources
1 parent 80cfc5b commit 903525a

1 file changed

Lines changed: 46 additions & 25 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def run(self, name, image, entrypoint, command):
461461
status, reason, data = self._get_pod(name, appname)
462462
parsed_json = json.loads(data)
463463
if parsed_json['status']['phase'] == 'Succeeded':
464-
status, data, reason = self._pod_log(name, appname)
464+
data = self._pod_log(appname, name).text
465465
self._delete_pod(name, appname)
466466
return 0, data
467467
if parsed_json['status']['phase'] == 'Running':
@@ -570,6 +570,14 @@ def _get_namespace_events(self, namespace, **kwargs):
570570

571571
return response
572572

573+
def _get_namespace(self, namespace):
574+
url = self._api("/namespaces/{}/", namespace)
575+
response = self.session.get(url)
576+
if unhealthy(response.status_code):
577+
error(response, 'get Namespace "{}"', namespace)
578+
579+
return response
580+
573581
def _create_namespace(self, app_name):
574582
url = self._api("/namespaces")
575583
data = {
@@ -600,8 +608,12 @@ def _get_old_rc(self, name, app_type):
600608
exists = False
601609
prev_rc = []
602610
for rc in resp.json()['items']:
603-
if('app' in rc['spec']['selector'] and name == rc['metadata']['labels']['app'] and
604-
'type' in rc['spec']['selector'] and app_type == rc['spec']['selector']['type']):
611+
if (
612+
'app' in rc['spec']['selector'] and
613+
name == rc['metadata']['labels']['app'] and
614+
'type' in rc['spec']['selector'] and
615+
app_type == rc['spec']['selector']['type']
616+
):
605617
exists = True
606618
prev_rc = rc
607619
break
@@ -623,6 +635,14 @@ def _get_rc(self, name, namespace):
623635

624636
return resp.json()
625637

638+
def _get_rcs(self, namespace, **kwargs):
639+
url = self._api("/namespaces/{}/replicationcontrollers/{}", namespace)
640+
response = self.session.get(url, params=self._selectors(**kwargs))
641+
if unhealthy(response.status_code):
642+
error(response, 'get ReplicationControllers in Namespace "{}"', namespace)
643+
644+
return response
645+
626646
def _get_schedule_status(self, namespace, name, current, desired, resource_version): # noqa
627647
if int(desired) > int(current):
628648
# new pods are going to be scheduled
@@ -969,6 +989,14 @@ def _get_secret(self, namespace, name):
969989

970990
return response
971991

992+
def _get_secrets(self, namespace, **kwargs):
993+
url = self._api('/namespaces/{}/secrets', namespace)
994+
response = self.session.get(url, params=self._selectors(**kwargs))
995+
if unhealthy(response.status_code):
996+
error(response, 'get Secrets in Namespace "{}"', namespace)
997+
998+
return response
999+
9721000
def _create_secret(self, namespace, name, data):
9731001
template = json.loads(string.Template(SECRET_TEMPLATE).substitute({
9741002
"version": self.apiversion,
@@ -1006,6 +1034,14 @@ def _get_service(self, name, namespace):
10061034

10071035
return response
10081036

1037+
def _get_services(self, namespace, **kwargs):
1038+
url = self._api('/namespaces/{}/services', namespace)
1039+
response = self.session.get(url, params=self._selectors(**kwargs))
1040+
if unhealthy(response.status_code):
1041+
error(response, 'get Services in Namespace "{}"', namespace)
1042+
1043+
return response
1044+
10091045
def _create_service(self, name, app_name, app_type, data={}, **kwargs):
10101046
docker_cli = Client(version="auto")
10111047
image = kwargs.get('image')
@@ -1089,13 +1125,13 @@ def _delete_pod(self, name, namespace):
10891125
if e.response.status_code != 404:
10901126
error(e.response, 'delete Pod "{}" in Namespace "{}"', name, namespace)
10911127

1092-
def _pod_log(self, name, namespace):
1128+
def _pod_log(self, namespace, name):
10931129
url = self._api("/namespaces/{}/pods/{}/log", namespace, name)
1094-
resp = self.session.get(url)
1095-
if unhealthy(resp.status_code):
1096-
error(resp, 'get logs for Pod "{}" in Namespace "{}"', name, namespace)
1130+
response = self.session.get(url)
1131+
if unhealthy(response.status_code):
1132+
error(response, 'get logs for Pod "{}" in Namespace "{}"', name, namespace)
10971133

1098-
return resp.status_code, resp.text, resp.reason
1134+
return response
10991135

11001136
def _pod_readiness_status(self, pod):
11011137
"""Check if the pod container have passed the readiness probes"""
@@ -1126,23 +1162,8 @@ def _pod_liveness_status(self, pod):
11261162
# NODES #
11271163

11281164
def _get_nodes(self, **kwargs):
1129-
path = '/nodes'
1130-
query = {}
1131-
1132-
# labels and fields are encoded slightly differently than python-requests can do
1133-
labels = kwargs.get('labels', {})
1134-
if labels:
1135-
# http://kubernetes.io/v1.1/docs/user-guide/labels.html#list-and-watch-filtering
1136-
labels = ['{}={}'.format(key, value) for key, value in labels.items()]
1137-
query['labelSelector'] = ','.join(labels)
1138-
1139-
fields = kwargs.get('fields', {})
1140-
if fields:
1141-
fields = ['{}={}'.format(key, value) for key, value in fields.items()]
1142-
query['fieldSelector'] = ','.join(fields)
1143-
1144-
url = self._api(path)
1145-
response = self.session.get(url, params=query)
1165+
url = self._api('/nodes')
1166+
response = self.session.get(url, params=self._selectors(**kwargs))
11461167
if unhealthy(response.status_code):
11471168
error(response, 'get Nodes')
11481169

0 commit comments

Comments
 (0)