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
This commit is contained in:
Steve Wilkerson 2017-11-29 14:44:54 -06:00
parent 13c4199742
commit 2a915c4a15
2 changed files with 82 additions and 1 deletions

View File

@ -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:

View File

@ -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