Skip to content

Commit 2bb7724

Browse files
author
Matthew Fisher
authored
fix(scheduler): only attach healthcheck if app is routable (#880)
1 parent a2d55f8 commit 2bb7724

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ test-style:
6767

6868
test-unit:
6969
cd rootfs \
70-
&& coverage run manage.py test --settings=api.settings.testing --noinput registry api \
70+
&& coverage run manage.py test --settings=api.settings.testing --noinput registry api scheduler.tests \
7171
&& coverage report -m
7272

7373
test-unit-quick:
7474
cd rootfs \
75-
&& ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api
75+
&& ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api scheduler.tests
7676

7777
test-functional:
7878
@echo "Implement functional tests in _tests directory"

rootfs/scheduler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def _set_container(self, namespace, container_name, data, **kwargs): # noqa
590590

591591
# add in healthchecks
592592
healthchecks = kwargs.get('healthcheck', None)
593-
if healthchecks:
593+
if healthchecks and kwargs.get('routable', False):
594594
# check if a port is present. if not, auto-populate it
595595
# TODO: rip this out when we stop supporting deis config:set HEALTHCHECK_URL
596596
if (
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Unit tests for the Deis scheduler module.
3+
4+
Run the tests with "./manage.py test scheduler"
5+
"""
6+
from django.core.cache import cache
7+
from django.test import TestCase
8+
9+
from scheduler import mock
10+
11+
12+
class SchedulerTest(TestCase):
13+
"""Tests scheduler calls"""
14+
15+
def setUp(self):
16+
self.scheduler_client = mock.MockSchedulerClient()
17+
18+
def tearDown(self):
19+
# make sure every test has a clean slate for k8s mocking
20+
cache.clear()
21+
22+
def test_set_container_applies_healthcheck_with_routable(self):
23+
"""
24+
Test that when _set_container is called with the 'routable' kwarg set to True,
25+
a healthcheck is attached to the dictionary.
26+
"""
27+
data = {}
28+
healthcheck = {
29+
'livenessProbe': {
30+
'httpGet': {
31+
'port': 80,
32+
}
33+
}
34+
}
35+
self.scheduler_client._set_container('foo',
36+
'bar',
37+
data,
38+
routable=True,
39+
healthcheck=healthcheck)
40+
self.assertDictContainsSubset(healthcheck, data)
41+
# clear the dict to call again with routable as false
42+
data = {}
43+
self.scheduler_client._set_container('foo',
44+
'bar',
45+
data,
46+
routable=False,
47+
healthcheck=healthcheck)
48+
self.assertEqual(data.get('livenessProbe'), None)
49+
# now call without setting 'routable', should default to False
50+
data = {}
51+
self.scheduler_client._set_container('foo',
52+
'bar',
53+
data,
54+
healthcheck=healthcheck)
55+
self.assertEqual(data.get('livenessProbe'), None)

0 commit comments

Comments
 (0)