From 2a915c4a157b5d4c255943435319608268f76fb5 Mon Sep 17 00:00:00 2001 From: Steve Wilkerson Date: Wed, 29 Nov 2017 14:44:54 -0600 Subject: [PATCH] Add support for running helm tests for charts Adds a common-helm-test task executed as part of the deploy-helm-packages playbook. It allows the ability to run helm tests against a chart by including a helm_test key in the chart definition Change-Id: I52bd5ca2fafa4eb704369590f7903c127133b090 --- .../tasks/util-common-helm-chart.yaml | 18 ++++- .../tasks/util-common-helm-test.yaml | 65 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-test.yaml diff --git a/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-chart.yaml b/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-chart.yaml index e3f4865f9..b95c7f1f5 100644 --- a/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-chart.yaml +++ b/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-chart.yaml @@ -49,7 +49,12 @@ var: out.stdout_lines - name: "pre-upgrade, delete jobs for {{ chart_def['release'] }} release" - when: (check_deployed_result | succeeded) and ( 'upgrade' in chart_def ) and ( 'pre' in chart_def['upgrade'] ) and ( 'delete' in chart_def['upgrade']['pre'] ) and (chart_def.upgrade.pre.delete is not none) + when: + - check_deployed_result | succeeded + - "'upgrade' in chart_def" + - "'pre' in chart_def['upgrade']" + - "'delete' in chart_def['upgrade']['pre']" + - "chart_def.upgrade.pre.delete is not none" with_items: "{{ chart_def.upgrade.pre.delete }}" loop_control: loop_var: helm_upgrade_delete_job @@ -69,6 +74,17 @@ namespace: "{{ chart_def['namespace'] }}" timeout: "{{ chart_def['timeout'] }}" + - include: util-common-helm-test.yaml + when: + - "'test' in chart_def" + - "chart_def.test is not none" + - "'enabled' in chart_def['test']" + - "chart_def.test.enabled|bool == true" + vars: + release: "{{ chart_def['release'] }}" + namespace: "{{ chart_def['namespace'] }}" + test_settings: "{{ chart_def.test }}" + always: - name: "remove values.yaml for {{ chart_def['release'] }}" file: diff --git a/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-test.yaml b/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-test.yaml new file mode 100644 index 000000000..b6f264da6 --- /dev/null +++ b/tools/gate/playbooks/deploy-helm-packages/tasks/util-common-helm-test.yaml @@ -0,0 +1,65 @@ +# 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. + +- name: Helm test common block + vars: + release: null + namespace: null + test_settings: null + + block: + - name: "remove any expired helm test pods for {{ release }}" + command: "kubectl delete pod {{ release }}-test -n {{ namespace }}" + ignore_errors: True + + - name: "run helm tests for the {{ release }} release" + when: + - "'timeout' in test_settings" + - "'timeout' is none" + command: "helm test {{ release }}" + register: test_result + + - name: "run helm tests for the {{ release }} release with timeout" + when: + - "'timeout' in test_settings" + - "'timeout' is not none" + command: " helm test --timeout {{ test_settings.timeout }} {{ release }}" + register: test_result + + - name: "display status for {{ release }} helm tests" + debug: + var: test_result.stdout_lines + + - name: "gathering logs for successful helm tests for {{ release }}" + when: + - test_result | succeeded + - "'output' in test_settings" + - "test_settings.output|bool == true" + command: "kubectl logs {{ release }}-test -n {{ namespace }}" + register: test_logs + + - name: "displaying logs for successful helm tests for {{ release }}" + when: + - test_result | succeeded + - "'output' in test_settings" + - "test_settings.output|bool == true" + debug: + var: test_logs.stdout_lines + rescue: + - name: "gathering logs for failed helm tests for {{ release }}" + command: "kubectl logs {{ release }}-test -n {{ namespace }}" + register: out + - name: "displaying logs for failed helm tests for {{ release }}" + debug: + var: out.stdout_lines + - name: "helm tests for {{ release }} failed, stopping execution" + command: exit 1