Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 63fff81

Browse files
authored
Merge pull request #1036 from kmala/bug
fix(healthcheck): check if the healthchecks are failing on a new deploy
2 parents a303f25 + ffc9f8c commit 63fff81

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

rootfs/scheduler/resources/deployment.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,8 @@ def wait_until_ready(self, namespace, name, **kwargs):
346346

347347
waited += 1
348348
time.sleep(1)
349+
350+
# check if the replicas are still not ready because of healthcheck failures
351+
ready, _ = self.are_replicas_ready(namespace, name)
352+
if not ready:
353+
self.pod._handle_not_ready_pods(namespace, labels)

rootfs/scheduler/resources/pod.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,26 @@ def wait_until_ready(self, namespace, containers, labels, desired, timeout): #
654654
self.log(namespace, 'timed out ({}s) waiting for pods to come up in namespace {}'.format(timeout, namespace)) # noqa
655655

656656
self.log(namespace, "{} out of {} pods are in service".format(count, desired)) # noqa
657+
658+
def _handle_not_ready_pods(self, namespace, labels):
659+
"""
660+
Detects if any pod is in the Running phase but not Ready and handles
661+
any potential issues around that mainly failed healthcheks
662+
"""
663+
pods = self.get(namespace, labels=labels).json()
664+
for pod in pods['items']:
665+
# only care about pods that are in running phase
666+
if pod['status']['phase'] != 'Running':
667+
continue
668+
name = '{}-{}'.format(pod['metadata']['labels']['app'], pod['metadata']['labels']['type']) # noqa
669+
# find the right container in case there are many on the pod
670+
container = self.pod.find_container(name, pod['status']['containerStatuses'])
671+
if container is None or container['ready'] == 'true':
672+
continue
673+
674+
for event in self.events(pod):
675+
if event['reason'] == 'Unhealthy':
676+
# strip out whitespaces on either side
677+
message = "\n".join([x.strip() for x in event['message'].split("\n")])
678+
raise KubeException(message)
679+
return None

0 commit comments

Comments
 (0)