From b4449434a599063e758a854c6b55183f0adc8819 Mon Sep 17 00:00:00 2001 From: Mark Burnett Date: Wed, 14 Feb 2018 12:46:33 -0600 Subject: [PATCH] Fix DNS name list for kube services in certs * Also adds liveness and readiness probes for Prom deployment Change-Id: Id65d1e555e14478f2439c14dd6d6d7952411256d --- .../promenade/templates/deployment-api.yaml | 17 ++++++++++ promenade/generator.py | 25 ++++++--------- tests/unit/test_generator.py | 31 +++++++++++++++++++ tox.ini | 2 +- 4 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 tests/unit/test_generator.py diff --git a/charts/promenade/templates/deployment-api.yaml b/charts/promenade/templates/deployment-api.yaml index df627a6a..e218dadf 100644 --- a/charts/promenade/templates/deployment-api.yaml +++ b/charts/promenade/templates/deployment-api.yaml @@ -56,6 +56,23 @@ spec: ports: - name: api-public containerPort: {{ .Values.network.api.port }} + livenessProbe: + failureThreshold: 5 + httpGet: + path: /api/v1.0/health + port: {{ .Values.network.api.target_port }} + initialDelaySeconds: 15 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /api/v1.0/health + port: {{ .Values.network.api.target_port }} + initialDelaySeconds: 5 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 5 volumeMounts: - name: promenade-etc mountPath: /etc/promenade/api-paste.ini diff --git a/promenade/generator.py b/promenade/generator.py index b6422e92..2b8bad82 100644 --- a/promenade/generator.py +++ b/promenade/generator.py @@ -24,7 +24,7 @@ class Generator: for cert_def in ca_def.get('certificates', []): hosts = cert_def.get('hosts', []) hosts.extend( - self.get_host_list( + get_host_list( cert_def.get('kubernetes_service_names', []))) self.gen( 'certificate', @@ -37,26 +37,19 @@ class Generator: self.gen('keypair', keypair_def['name']) _write(output_dir, self.documents) - def get_host_list(self, service_names): - service_list = [] - for service in service_names: - parts = service.split('.') - for i in range(len(parts)): - service_list.append('.'.join(parts[:i])) - return service_list - def gen(self, kind, *args, **kwargs): method = getattr(self.keys, 'generate_' + kind) self.documents.extend(method(*args, **kwargs)) - def _service_dns(self, name, namespace): - return [ - name, - '.'.join([name, namespace]), - '.'.join([name, namespace, 'svc']), - '.'.join([name, namespace, 'svc', self.cluster_domain]), - ] + +def get_host_list(service_names): + service_list = [] + for service in service_names: + parts = service.split('.') + for i in range(len(parts)): + service_list.append('.'.join(parts[:i + 1])) + return service_list def _write(output_dir, docs): diff --git a/tests/unit/test_generator.py b/tests/unit/test_generator.py new file mode 100644 index 00000000..b1d997fa --- /dev/null +++ b/tests/unit/test_generator.py @@ -0,0 +1,31 @@ +# Copyright 2018 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from promenade import generator + + +def test_get_host_list(): + service_fqdns = [ + 'kubernetes.default.svc.cluster.local', + ] + expected_parts = [ + 'kubernetes', + 'kubernetes.default', + 'kubernetes.default.svc', + 'kubernetes.default.svc.cluster', + 'kubernetes.default.svc.cluster.local', + ] + + actual_parts = generator.get_host_list(service_fqdns) + assert actual_parts == expected_parts diff --git a/tox.ini b/tox.ini index 7a6771ea..a0e435ef 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = lint,unit,bandit,docs [testenv] -basepython=python3.5 +basepython=python3 [testenv:unit] setenv =