Skip to content

Commit e7a908b

Browse files
committed
Merge pull request #411 from helgi/scale_ready
feat(pods): wait until pod / container has reported success on readiness / liveness probe during scale event
2 parents d36ba7a + c0c2afa commit e7a908b

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def deploy(self, name, image, command, **kwargs):
335335
new_rc["metadata"]["name"], desired)
336336
)
337337
self._scale_rc(new_rc["metadata"]["name"], app_name, 0)
338-
self._delete_rc(new_rc["metadata"]["name"], app_name)
338+
self._delete_rc(app_name, new_rc["metadata"]["name"])
339339
if old_rc:
340340
self._scale_rc(old_rc["metadata"]["name"], app_name, desired)
341341

@@ -389,7 +389,7 @@ def create(self, name, image, command, **kwargs):
389389
# TODO check if RC exists first
390390
self._scale_rc(name, app_name, 0)
391391
# TODO check if RC exists first
392-
self._delete_rc(name, app_name)
392+
self._delete_rc(app_name, name)
393393
raise
394394

395395
def start(self, name):
@@ -643,11 +643,17 @@ def _scale_rc(self, name, namespace, num):
643643
self._get_schedule_status(name, num, namespace)
644644
for _ in range(120):
645645
count = 0
646-
pods = self._get_pods(namespace)
647-
parsed_json = pods.json()
648-
for pod in parsed_json['items']:
649-
if(pod['metadata']['generateName'] == name+'-' and
650-
pod['status']['phase'] == 'Running'):
646+
pods = self._get_pods(namespace).json()
647+
for pod in pods['items']:
648+
# now that state is running time to see if probes are passing
649+
if (
650+
pod['metadata']['generateName'] == name+'-' and
651+
pod['status']['phase'] == 'Running' and
652+
# is the readiness probe passing?
653+
self._pod_readiness_status(pod, name) and
654+
# is the pod ready to serve requests?
655+
self._pod_liveness_status(pod)
656+
):
651657
count += 1
652658

653659
if count == num:
@@ -964,6 +970,24 @@ def _pod_log(self, name, namespace):
964970

965971
return resp.status_code, resp.text, resp.reason
966972

973+
def _pod_readiness_status(self, pod, name):
974+
"""Check if the pod container have passed the readiness probes"""
975+
for container in pod['status']['containerStatuses']:
976+
# find the right container in case there are many on the pod
977+
if container['name'] == name and not container['ready']:
978+
return False
979+
980+
return True
981+
982+
def _pod_liveness_status(self, pod):
983+
"""Check if the pods liveness probe status has passed all checks"""
984+
for condition in pod['status']['conditions']:
985+
# type = Ready is the only binary type right now
986+
if condition['type'] == 'Ready' and condition['status'] != 'True':
987+
return False
988+
989+
return True
990+
967991
# NODES #
968992

969993
def _get_nodes(self, **kwargs):

0 commit comments

Comments
 (0)