diff --git a/changelogs/fragments/332_helm_changed_flag_takes_values_in_consideration.yaml b/changelogs/fragments/332_helm_changed_flag_takes_values_in_consideration.yaml new file mode 100644 index 00000000..edf35b81 --- /dev/null +++ b/changelogs/fragments/332_helm_changed_flag_takes_values_in_consideration.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- helm - ``release_values`` makes ansible always show changed state (https://github.com/ansible-collections/community.kubernetes/issues/274) diff --git a/molecule/default/roles/helm/tasks/tests_chart.yml b/molecule/default/roles/helm/tasks/tests_chart.yml index a79e2a84..ae9275ef 100644 --- a/molecule/default/roles/helm/tasks/tests_chart.yml +++ b/molecule/default/roles/helm/tasks/tests_chart.yml @@ -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 diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index 5bdc18af..ec78a6af 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -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( @@ -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,