Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align helmdiff_check behavior with the deploy function #670

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- align `helmdiff_check()` function commandline rendering with the `deploy()` function (https://github.com/ansible-collections/kubernetes.core/pull/670).
- integrations test helm_kubeconfig - set helm version to v3.10.3 to avoid incompatability with new bitnami charts (https://github.com/ansible-collections/kubernetes.core/pull/670).
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
8 changes: 5 additions & 3 deletions tests/integration/targets/helm_kubeconfig/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
- name: Test helm with in-memory kubeconfig
include_tasks: "from_in_memory_kubeconfig.yml"
loop_control:
loop_var: test_helm_version
with_items:
- "v3.10.3"

- name: Test helm with custom kubeconfig and validate_certs=false
include_tasks: "from_kubeconfig_with_validate_certs.yml"
loop_control:
loop_var: test_helm_version
with_items:
- "v3.10.3"
- "v3.8.2"

- name: Test helm with custom kubeconfig and ca_cert
include_tasks: "from_kubeconfig_with_cacert.yml"
loop_control:
loop_var: test_helm_version
with_items:
- "v3.5.1"
- "v3.4.2"
- "v3.10.3"
Loading