Skip to content

Commit

Permalink
Align helmdiff_check behavior with the deploy function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Smolkin committed Jan 15, 2024
1 parent 8d15489 commit 2a69517
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
23 changes: 12 additions & 11 deletions plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ def helmdiff_check(
replace=False,
chart_repo_url=None,
post_renderer=False,
set_value_args=None,
):
"""
Use helm diff to determine if a release would change by upgrading a chart.
Expand All @@ -656,16 +657,19 @@ def helmdiff_check(
if post_renderer:
cmd += " --post-renderer=" + post_renderer

if values_files:
for value_file in values_files:
cmd += " --values=" + value_file

if release_values != {}:
fd, path = tempfile.mkstemp(suffix=".yml")
with open(path, "w") as yaml_file:
yaml.dump(release_values, yaml_file, default_flow_style=False)
cmd += " -f=" + path
module.add_cleanup_file(path)

if values_files:
for values_file in values_files:
cmd += " -f=" + values_file
if set_value_args:
cmd += " " + set_value_args

rc, out, err = module.run_helm_command(cmd)
return (len(out.strip()) > 0, out.strip())
Expand Down Expand Up @@ -847,11 +851,11 @@ def main():
"Please consider add dependencies block or disable dependency_update to remove this warning."
)

if release_status is None: # Not installed
set_value_args = None
if set_values:
set_value_args = module.get_helm_set_values_args(set_values)
set_value_args = None
if set_values:
set_value_args = module.get_helm_set_values_args(set_values)

if release_status is None: # Not installed
helm_cmd = deploy(
module,
helm_cmd,
Expand Down Expand Up @@ -896,6 +900,7 @@ def main():
replace,
chart_repo_url,
post_renderer,
set_value_args,
)
if would_change and module._diff:
opt_result["diff"] = {"prepared": prepared}
Expand All @@ -909,10 +914,6 @@ def main():
)

if force or would_change:
set_value_args = None
if set_values:
set_value_args = module.get_helm_set_values_args(set_values)

helm_cmd = deploy(
module,
helm_cmd,
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/targets/helm_diff/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
chart_ref: "{{ test_chart_ref }}"
values:
foo: gaz
values_files:
- "{{ test_chart_ref }}/values.yml"
register: install

- assert:
Expand All @@ -157,6 +159,46 @@
chart_ref: "{{ test_chart_ref }}"
values:
foo: gaz
values_files:
- "{{ test_chart_ref }}/values.yml"
register: install

- assert:
that:
- install is not changed

- name: Upgrade with set_values
helm:
binary_path: "{{ helm_binary }}"
name: test-chart
namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}"
values:
foo: gaz
values_files:
- "{{ test_chart_ref }}/values.yml"
set_values:
- value: foo=qux
value_type: string
register: install

- assert:
that:
- install is changed

- name: Upgrade with set_values idempotency check
helm:
binary_path: "{{ helm_binary }}"
name: test-chart
namespace: "{{ helm_namespace }}"
chart_ref: "{{ test_chart_ref }}"
values:
foo: gaz
values_files:
- "{{ test_chart_ref }}/values.yml"
set_values:
- value: foo=qux
value_type: string
register: install

- assert:
Expand Down

0 comments on commit 2a69517

Please sign in to comment.