Skip to content

Commit

Permalink
helm: 'changed' flag takes 'values' in consideration
Browse files Browse the repository at this point in the history
Return `changed` `False` is the `values_files` match the `values` of
the existing deployment.

Closes: ansible-collections#274
  • Loading branch information
goneri committed Jan 5, 2021
1 parent 221631c commit adba3bf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- helm - ``release_values`` makes ansible always show changed state (https://github.com/ansible-collections/community.kubernetes/issues/274)
16 changes: 16 additions & 0 deletions molecule/default/roles/helm/tasks/tests_chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@
- install.status.chart == "{{ chart_test }}-{{ chart_test_version }}"
- "install.status['values'].revisionHistoryLimit == 0"

- name: "Install {{ chart_test }} from {{ source }} with values_files (again)"
helm:
binary_path: "{{ helm_binary }}"
name: test
chart_ref: "{{ chart_source }}"
chart_version: "{{ chart_source_version | default(omit) }}"
namespace: "{{ helm_namespace }}"
values_files:
- "{{ role_path }}/files/values.yaml"
register: install

- name: "Assert the result is consistent"
assert:
that:
- not (install is changed)

- name: Remove helm namespace
k8s:
api_version: v1
Expand Down
19 changes: 18 additions & 1 deletion plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ def delete(command, release_name, purge, disable_hook):
return delete_command


def load_values_files(values_files):
values = {}
for values_file in values_files or []:
with open(values_file, 'r') as fd:
content = yaml.safe_load(fd)
if not isinstance(content, dict):
continue
for k, v in content.items():
values[k] = v
return values


def main():
global module
module = AnsibleModule(
Expand Down Expand Up @@ -502,7 +514,12 @@ def main():
# when deployed without an 'appVersion' chart value the 'helm list' command will return the entry `app_version: ""`
appversion_is_same = (chart_app_version == released_app_version) or (chart_app_version is None and released_app_version == "")

if force or release_values != release_status['values'] \
if values_files:
values_match = release_status['values'] == load_values_files(values_files)
else:
values_match = release_status['values'] == release_values

if force or not values_match \
or (chart_info['name'] + '-' + chart_info['version']) != release_status["chart"] \
or not appversion_is_same:
helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout,
Expand Down

0 comments on commit adba3bf

Please sign in to comment.