Skip to content

Commit

Permalink
helm: return correct information in check mode
Browse files Browse the repository at this point in the history
Fixes: ansible-collections#280

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Oct 22, 2020
1 parent 9a2e29a commit 391b6d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/280_helm_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- helm - return values in check mode when release is not present (https://github.com/ansible-collections/community.kubernetes/issues/280).
18 changes: 18 additions & 0 deletions molecule/default/roles/helm/tasks/tests_chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
- install_fail is failed
- "'Error: create: failed to create: namespaces \"' + helm_namespace + '\" not found' in install_fail.stderr"

- name: "Install {{ chart_test }} from {{ source }} in check mode"
helm:
binary_path: "{{ helm_binary }}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit) }}"
namespace: "{{ helm_namespace }}"
create_namespace: true
register: install_check_mode
check_mode: true

- name: "Assert that {{ chart_test }} chart is installed from {{ source }} in check mode"
assert:
that:
- install_check_mode is changed
- install_check_mode.status is defined
- install_check_mode.status.values is defined

- name: "Install {{ chart_test }} from {{ source }}"
helm:
binary_path: "{{ helm_binary }}"
Expand Down
13 changes: 9 additions & 4 deletions plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,15 @@ def main():
changed = True

if module.check_mode:
check_status = {'values': {
"current": release_status['values'],
"declared": release_values
}}
check_status = {
'values': {
"current": {},
"declared": {},
}
}
if release_status:
check_status['values']['current'] = release_status['values']
check_status['values']['declared'] = release_status

module.exit_json(
changed=changed,
Expand Down

0 comments on commit 391b6d9

Please sign in to comment.