Skip to content

Commit 286c61f

Browse files
authored
Merge pull request #961 from kmala/fix
fix(health):Add healthchecks only for routable apps or proctypes
2 parents b66948d + a4ee5a8 commit 286c61f

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,19 +585,23 @@ def _set_container(self, namespace, container_name, data, **kwargs):
585585
data["resources"]["limits"]["cpu"] = cpu.lower()
586586

587587
# add in healthchecks
588-
healthchecks = kwargs.get('healthcheck', None)
589-
if healthchecks and kwargs.get('routable', False):
590-
# check if a port is present. if not, auto-populate it
591-
# TODO: rip this out when we stop supporting deis config:set HEALTHCHECK_URL
592-
if (
593-
healthchecks.get('livenessProbe') is not None and
594-
healthchecks['livenessProbe'].get('httpGet') is not None and
595-
healthchecks['livenessProbe']['httpGet'].get('port') is None
596-
):
597-
healthchecks['livenessProbe']['httpGet']['port'] = env['PORT']
598-
data.update(healthchecks)
599-
else:
600-
self._default_readiness_probe(data, kwargs.get('build_type'), env.get('PORT', None))
588+
self._set_health_checks(data, env, kwargs)
589+
590+
def _set_health_checks(self, container, env, kwargs):
591+
if kwargs.get('routable', False):
592+
healthchecks = kwargs.get('healthcheck', None)
593+
if healthchecks:
594+
# check if a port is present. if not, auto-populate it
595+
# TODO: rip this out when we stop supporting deis config:set HEALTHCHECK_URL
596+
if (
597+
healthchecks.get('livenessProbe') is not None and
598+
healthchecks['livenessProbe'].get('httpGet') is not None and
599+
healthchecks['livenessProbe']['httpGet'].get('port') is None
600+
):
601+
healthchecks['livenessProbe']['httpGet']['port'] = env['PORT']
602+
container.update(healthchecks)
603+
else:
604+
self._default_readiness_probe(container, kwargs.get('build_type'), env.get('PORT', None)) # noqa
601605

602606
def _get_private_registry_config(self, registry, image):
603607
secret_name = settings.REGISTRY_SECRET_PREFIX

rootfs/scheduler/tests/test_scheduler.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,39 @@ def test_set_container_applies_healthcheck_with_routable(self):
3535
}
3636
}
3737
}
38+
readinessHealthCheck = {
39+
# an exec probe
40+
'exec': {
41+
"command": [
42+
"bash",
43+
"-c",
44+
"[[ '$(ps -p 1 -o args)' != *'bash /runner/init'* ]]"
45+
]
46+
},
47+
# length of time to wait for a pod to initialize
48+
# after pod startup, before applying health checking
49+
'initialDelaySeconds': 30,
50+
'timeoutSeconds': 5,
51+
'periodSeconds': 5,
52+
'successThreshold': 1,
53+
'failureThreshold': 1,
54+
}
55+
3856
self.scheduler_client._set_container('foo',
3957
'bar',
4058
data,
4159
routable=True,
4260
healthcheck=healthcheck)
4361
self.assertDictContainsSubset(healthcheck, data)
62+
data = {}
63+
self.scheduler_client._set_container('foo',
64+
'bar',
65+
data,
66+
routable=True,
67+
build_type="buildpack",
68+
healthcheck={})
69+
self.assertEqual(data.get('livenessProbe'), None)
70+
self.assertEqual(data.get('readinessProbe'), readinessHealthCheck)
4471
# clear the dict to call again with routable as false
4572
data = {}
4673
self.scheduler_client._set_container('foo',
@@ -49,13 +76,15 @@ def test_set_container_applies_healthcheck_with_routable(self):
4976
routable=False,
5077
healthcheck=healthcheck)
5178
self.assertEqual(data.get('livenessProbe'), None)
79+
self.assertEqual(data.get('readinessProbe'), None)
5280
# now call without setting 'routable', should default to False
5381
data = {}
5482
self.scheduler_client._set_container('foo',
5583
'bar',
5684
data,
5785
healthcheck=healthcheck)
5886
self.assertEqual(data.get('livenessProbe'), None)
87+
self.assertEqual(data.get('readinessProbe'), None)
5988

6089
def test_set_container_limits(self):
6190
"""

0 commit comments

Comments
 (0)