Skip to content

Commit b3662b0

Browse files
committed
Merge pull request #437 from helgi/fetch_all
feat(scheduler): add more functions to fetch on the global endpoints for various resources
2 parents 85d711b + 903525a commit b3662b0

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
@@ -472,7 +472,7 @@ def run(self, name, image, entrypoint, command):
472472
status, reason, data = self._get_pod(name, appname)
473473
parsed_json = json.loads(data)
474474
if parsed_json['status']['phase'] == 'Succeeded':
475-
status, data, reason = self._pod_log(name, appname)
475+
data = self._pod_log(appname, name).text
476476
self._delete_pod(name, appname)
477477
return 0, data
478478
if parsed_json['status']['phase'] == 'Running':
@@ -596,6 +596,14 @@ def _get_namespace_events(self, namespace, **kwargs):
596596

597597
return response
598598

599+
def _get_namespace(self, namespace):
600+
url = self._api("/namespaces/{}/", namespace)
601+
response = self.session.get(url)
602+
if unhealthy(response.status_code):
603+
error(response, 'get Namespace "{}"', namespace)
604+
605+
return response
606+
599607
def _create_namespace(self, app_name):
600608
url = self._api("/namespaces")
601609
data = {
@@ -626,8 +634,12 @@ def _get_old_rc(self, name, app_type):
626634
exists = False
627635
prev_rc = []
628636
for rc in resp.json()['items']:
629-
if('app' in rc['spec']['selector'] and name == rc['metadata']['labels']['app'] and
630-
'type' in rc['spec']['selector'] and app_type == rc['spec']['selector']['type']):
637+
if (
638+
'app' in rc['spec']['selector'] and
639+
name == rc['metadata']['labels']['app'] and
640+
'type' in rc['spec']['selector'] and
641+
app_type == rc['spec']['selector']['type']
642+
):
631643
exists = True
632644
prev_rc = rc
633645
break
@@ -649,6 +661,14 @@ def _get_rc(self, name, namespace):
649661

650662
return resp.json()
651663

664+
def _get_rcs(self, namespace, **kwargs):
665+
url = self._api("/namespaces/{}/replicationcontrollers/{}", namespace)
666+
response = self.session.get(url, params=self._selectors(**kwargs))
667+
if unhealthy(response.status_code):
668+
error(response, 'get ReplicationControllers in Namespace "{}"', namespace)
669+
670+
return response
671+
652672
def _get_schedule_status(self, namespace, name, current, desired, resource_version): # noqa
653673
if int(desired) > int(current):
654674
# new pods are going to be scheduled
@@ -995,6 +1015,14 @@ def _get_secret(self, namespace, name):
9951015

9961016
return response
9971017

1018+
def _get_secrets(self, namespace, **kwargs):
1019+
url = self._api('/namespaces/{}/secrets', namespace)
1020+
response = self.session.get(url, params=self._selectors(**kwargs))
1021+
if unhealthy(response.status_code):
1022+
error(response, 'get Secrets in Namespace "{}"', namespace)
1023+
1024+
return response
1025+
9981026
def _create_secret(self, namespace, name, data):
9991027
template = json.loads(string.Template(SECRET_TEMPLATE).substitute({
10001028
"version": self.apiversion,
@@ -1032,6 +1060,14 @@ def _get_service(self, name, namespace):
10321060

10331061
return response
10341062

1063+
def _get_services(self, namespace, **kwargs):
1064+
url = self._api('/namespaces/{}/services', namespace)
1065+
response = self.session.get(url, params=self._selectors(**kwargs))
1066+
if unhealthy(response.status_code):
1067+
error(response, 'get Services in Namespace "{}"', namespace)
1068+
1069+
return response
1070+
10351071
def _create_service(self, name, app_name, app_type, data={}, **kwargs):
10361072
port = self._get_port(kwargs.get('image'))
10371073
l = {
@@ -1106,13 +1142,13 @@ def _delete_pod(self, name, namespace):
11061142
if e.response.status_code != 404:
11071143
error(e.response, 'delete Pod "{}" in Namespace "{}"', name, namespace)
11081144

1109-
def _pod_log(self, name, namespace):
1145+
def _pod_log(self, namespace, name):
11101146
url = self._api("/namespaces/{}/pods/{}/log", namespace, name)
1111-
resp = self.session.get(url)
1112-
if unhealthy(resp.status_code):
1113-
error(resp, 'get logs for Pod "{}" in Namespace "{}"', name, namespace)
1147+
response = self.session.get(url)
1148+
if unhealthy(response.status_code):
1149+
error(response, 'get logs for Pod "{}" in Namespace "{}"', name, namespace)
11141150

1115-
return resp.status_code, resp.text, resp.reason
1151+
return response
11161152

11171153
def _pod_readiness_status(self, pod):
11181154
"""Check if the pod container have passed the readiness probes"""
@@ -1143,23 +1179,8 @@ def _pod_liveness_status(self, pod):
11431179
# NODES #
11441180

11451181
def _get_nodes(self, **kwargs):
1146-
path = '/nodes'
1147-
query = {}
1148-
1149-
# labels and fields are encoded slightly differently than python-requests can do
1150-
labels = kwargs.get('labels', {})
1151-
if labels:
1152-
# http://kubernetes.io/v1.1/docs/user-guide/labels.html#list-and-watch-filtering
1153-
labels = ['{}={}'.format(key, value) for key, value in labels.items()]
1154-
query['labelSelector'] = ','.join(labels)
1155-
1156-
fields = kwargs.get('fields', {})
1157-
if fields:
1158-
fields = ['{}={}'.format(key, value) for key, value in fields.items()]
1159-
query['fieldSelector'] = ','.join(fields)
1160-
1161-
url = self._api(path)
1162-
response = self.session.get(url, params=query)
1182+
url = self._api('/nodes')
1183+
response = self.session.get(url, params=self._selectors(**kwargs))
11631184
if unhealthy(response.status_code):
11641185
error(response, 'get Nodes')
11651186

0 commit comments

Comments
 (0)