Skip to content

Commit b5623de

Browse files
committed
fix(tags): improve the error message when the combination of tags match no node labels
Fixes #486
1 parent 14b8527 commit b5623de

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

rootfs/api/models/config.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ def save(self, **kwargs):
6767
nodes = self._scheduler._get_nodes(labels=self.tags).json()
6868
if not nodes['items']:
6969
labels = ['{}={}'.format(key, value) for key, value in self.tags.items()]
70-
raise EnvironmentError(
71-
'These tags do not match labels on kubernetes nodes: {}'.format(
72-
', '.join(labels)
73-
)
74-
)
70+
message = 'No nodes matched the provided labels: {}'.format(', '.join(labels))
71+
72+
# Find out if there are any other tags around
73+
old_tags = getattr(previous_config, 'tags')
74+
if old_tags:
75+
old = ['{}={}'.format(key, value) for key, value in old_tags.items()]
76+
new = set(labels) - set(old)
77+
message += ' - Addition of {} is the cause'.format(', '.join(new))
78+
79+
raise EnvironmentError(message)
7580

7681
return super(Config, self).save(**kwargs)

rootfs/api/tests/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ def test_tags(self):
503503
response = self.client.post(url, json.dumps(body), content_type='application/json',
504504
HTTP_AUTHORIZATION='token {}'.format(self.token))
505505
self.assertEqual(response.status_code, 201)
506+
body = {'tags': json.dumps({'host.the-name.com/does.no.exist': 'valid'})}
507+
response = self.client.post(url, json.dumps(body), content_type='application/json',
508+
HTTP_AUTHORIZATION='token {}'.format(self.token))
509+
self.assertContains(
510+
response,
511+
'Addition of host.the-name.com/does.no.exist=valid is the cause',
512+
status_code=400
513+
)
506514
# set invalid values
507515
body = {'tags': json.dumps({'valid': 'in\nvalid'})}
508516
response = self.client.post(url, json.dumps(body), content_type='application/json',

0 commit comments

Comments
 (0)