generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 141
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
add reset_then_reuse_values support to helm module #802
Open
b0z02003
wants to merge
5
commits into
ansible-collections:main
Choose a base branch
from
b0z02003:helm_reset_then_reuse_values
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6486e64
add reset_then_reuse_values support to helm module
b0z02003 71cf8ca
fix: helm tests (based on #827)
b0z02003 ac2052a
fix: check helm version before using --reset-then-reuse-values
b0z02003 847d64a
fix: improves tests
bidorffOL aaee3dd
fix: improve versions checks
bidorffOL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/800-helm-add-reset_then_reuse_values-support.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- helm - add reset_then_reuse_values support to helm module (https://github.com/ansible-collections/kubernetes.core/issues/803). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -145,6 +145,16 @@ | |||||||||
required: false | ||||||||||
default: True | ||||||||||
version_added: 2.5.0 | ||||||||||
reset_then_reuse_values: | ||||||||||
description: | ||||||||||
- When upgrading package, reset the values to the ones built into the chart, apply the last release's values and merge in any overrides from | ||||||||||
parameters O(release_values), O(values_files) or O(set_values). | ||||||||||
- If O(reset_values) or O(reuse_values) is set to V(True), this is ignored. | ||||||||||
- This feature requires helm diff >= 3.9.12. | ||||||||||
type: bool | ||||||||||
required: false | ||||||||||
default: False | ||||||||||
version_added: 5.1.0 | ||||||||||
|
||||||||||
#Helm options | ||||||||||
disable_hook: | ||||||||||
|
@@ -509,6 +519,7 @@ def deploy( | |||||||||
set_value_args=None, | ||||||||||
reuse_values=None, | ||||||||||
reset_values=True, | ||||||||||
reset_then_reuse_values=False, | ||||||||||
): | ||||||||||
""" | ||||||||||
Install/upgrade/rollback release chart | ||||||||||
|
@@ -526,6 +537,13 @@ def deploy( | |||||||||
if reuse_values is not None: | ||||||||||
deploy_command += " --reuse-values=" + str(reuse_values) | ||||||||||
|
||||||||||
if reset_then_reuse_values: | ||||||||||
helm_version = module.get_helm_version() | ||||||||||
if LooseVersion(helm_version) < LooseVersion("3.14.0"): | ||||||||||
module.warn("helm support option --reset-then-reuse-values starting release >= 3.14.0") | ||||||||||
else: | ||||||||||
deploy_command += " --reset-then-reuse-values" | ||||||||||
|
||||||||||
if wait: | ||||||||||
deploy_command += " --wait" | ||||||||||
if wait_timeout is not None: | ||||||||||
|
@@ -642,6 +660,7 @@ def helmdiff_check( | |||||||||
set_value_args=None, | ||||||||||
reuse_values=None, | ||||||||||
reset_values=True, | ||||||||||
reset_then_reuse_values=False, | ||||||||||
): | ||||||||||
""" | ||||||||||
Use helm diff to determine if a release would change by upgrading a chart. | ||||||||||
|
@@ -676,6 +695,16 @@ def helmdiff_check( | |||||||||
if reuse_values: | ||||||||||
cmd += " --reuse-values" | ||||||||||
|
||||||||||
if reset_then_reuse_values: | ||||||||||
helm_diff_version = get_plugin_version("diff") | ||||||||||
helm_version = module.get_helm_version() | ||||||||||
if LooseVersion(helm_diff_version) < LooseVersion("3.9.12"): | ||||||||||
module.warn("helm diff support option --reset-then-reuse-values starting release >= 3.9.12") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
elif LooseVersion(helm_version) < LooseVersion("3.14.0"): | ||||||||||
module.warn("helm support option --reset-then-reuse-values starting release >= 3.14.0") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
else: | ||||||||||
cmd += " --reset-then-reuse-values" | ||||||||||
|
||||||||||
rc, out, err = module.run_helm_command(cmd) | ||||||||||
return (len(out.strip()) > 0, out.strip()) | ||||||||||
|
||||||||||
|
@@ -735,6 +764,7 @@ def argument_spec(): | |||||||||
set_values=dict(type="list", elements="dict"), | ||||||||||
reuse_values=dict(type="bool"), | ||||||||||
reset_values=dict(type="bool", default=True), | ||||||||||
reset_then_reuse_values=dict(type="bool", default=False), | ||||||||||
) | ||||||||||
) | ||||||||||
return arg_spec | ||||||||||
|
@@ -787,6 +817,7 @@ def main(): | |||||||||
set_values = module.params.get("set_values") | ||||||||||
reuse_values = module.params.get("reuse_values") | ||||||||||
reset_values = module.params.get("reset_values") | ||||||||||
reset_then_reuse_values = module.params.get("reset_then_reuse_values") | ||||||||||
|
||||||||||
if update_repo_cache: | ||||||||||
run_repo_update(module) | ||||||||||
|
@@ -883,6 +914,7 @@ def main(): | |||||||||
set_value_args=set_value_args, | ||||||||||
reuse_values=reuse_values, | ||||||||||
reset_values=reset_values, | ||||||||||
reset_then_reuse_values=reset_then_reuse_values, | ||||||||||
) | ||||||||||
changed = True | ||||||||||
|
||||||||||
|
@@ -908,6 +940,7 @@ def main(): | |||||||||
set_value_args, | ||||||||||
reuse_values=reuse_values, | ||||||||||
reset_values=reset_values, | ||||||||||
reset_then_reuse_values=reset_then_reuse_values, | ||||||||||
) | ||||||||||
if would_change and module._diff: | ||||||||||
opt_result["diff"] = {"prepared": prepared} | ||||||||||
|
@@ -943,6 +976,7 @@ def main(): | |||||||||
set_value_args=set_value_args, | ||||||||||
reuse_values=reuse_values, | ||||||||||
reset_values=reset_values, | ||||||||||
reset_then_reuse_values=reset_then_reuse_values, | ||||||||||
) | ||||||||||
changed = True | ||||||||||
|
||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
- name: Test helm reset_then_reuse_values | ||
vars: | ||
helm_namespace: "{{ test_namespace[9] }}" | ||
chart_release_values: | ||
replica: | ||
replicaCount: 3 | ||
master: | ||
count: 1 | ||
kind: Deployment | ||
chart_reset_then_reuse_values: | ||
replica: | ||
replicaCount: 1 | ||
master: | ||
count: 3 | ||
block: | ||
- name: Initial chart installation | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis | ||
release_name: test-redis | ||
release_namespace: "{{ helm_namespace }}" | ||
create_namespace: true | ||
release_values: "{{ chart_release_values }}" | ||
register: install | ||
|
||
- name: Get value set as string | ||
helm_info: | ||
binary_path: "{{ helm_binary }}" | ||
release_name: test-redis | ||
release_namespace: "{{ helm_namespace }}" | ||
register: release_value | ||
|
||
- name: Validate that chart values are as expected | ||
assert: | ||
that: | ||
- install is changed | ||
- '"--reset-then-reuse-values" not in install.command' | ||
- release_value["status"]["values"] == chart_release_values | ||
|
||
- name: Upgrade chart using reset_then_reuse_values=true | ||
helm: | ||
binary_path: "{{ helm_binary }}" | ||
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis | ||
release_name: test-redis | ||
release_namespace: "{{ helm_namespace }}" | ||
reuse_values: false | ||
reset_values: false | ||
reset_then_reuse_values: true | ||
release_values: "{{ chart_reset_then_reuse_values }}" | ||
register: upgrade | ||
|
||
- name: Get value set as string | ||
helm_info: | ||
binary_path: "{{ helm_binary }}" | ||
release_name: test-redis | ||
release_namespace: "{{ helm_namespace }}" | ||
register: release_value | ||
|
||
- name: Validate that chart values are as expected | ||
assert: | ||
that: | ||
- upgrade is changed | ||
- '"--reset-then-reuse-values" in upgrade.command' | ||
- '"--reuse-values" not in upgrade.command' | ||
- '"--reset-values" not in upgrade.command' | ||
- release_value["status"]["values"] == chart_release_values | combine(chart_reset_then_reuse_values, recursive=true) | ||
|
||
always: | ||
- name: Remove helm namespace | ||
k8s: | ||
api_version: v1 | ||
kind: Namespace | ||
name: "{{ helm_namespace }}" | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,3 +302,5 @@ | |
ignore_errors: yes | ||
|
||
- include_tasks: reuse_values.yml | ||
|
||
- include_tasks: reset_then_reuse_values.yml |
94 changes: 94 additions & 0 deletions
94
tests/integration/targets/helm_diff/tasks/reset_then_reuse_values.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
- name: Create temporary directory for helm chart | ||
tempfile: | ||
suffix: .helm | ||
state: directory | ||
register: helm_dir | ||
|
||
- name: Test helm diff functionality | ||
vars: | ||
test_chart_path: "{{ helm_dir.path }}/test-chart-reuse-values" | ||
test_release_name: "myrelease" | ||
|
||
block: | ||
- name: Install helm diff | ||
kubernetes.core.helm_plugin: | ||
binary_path: "{{ helm_binary }}" | ||
state: present | ||
plugin_path: https://github.com/databus23/helm-diff | ||
plugin_version: 3.9.4 | ||
|
||
- name: Copy test chart | ||
ansible.builtin.copy: | ||
src: "test-chart-reuse-values" | ||
dest: "{{ helm_dir.path }}" | ||
|
||
- name: Create helm release | ||
kubernetes.core.helm: | ||
state: present | ||
binary_path: "{{ helm_binary }}" | ||
chart_ref: "{{ test_chart_path }}" | ||
release_name: "{{ test_release_name }}" | ||
release_namespace: "{{ helm_namespace }}" | ||
create_namespace: true | ||
release_values: | ||
ansible_version: devel | ||
phase: ci | ||
wait: true | ||
|
||
- name: Upgrade helm release (reset_values=false and reuse_values=false and reset_then_reuse_values=true) | ||
kubernetes.core.helm: | ||
binary_path: "{{ helm_binary }}" | ||
chart_ref: "{{ test_chart_path }}" | ||
reset_values: false | ||
reuse_values: false | ||
reset_then_reuse_values: true | ||
release_name: "{{ test_release_name }}" | ||
release_namespace: "{{ helm_namespace }}" | ||
values: | ||
ansible_version: devel | ||
register: helm_upgrade | ||
|
||
- name: Ensure task did not reported change | ||
assert: | ||
that: | ||
- helm_upgrade is not changed | ||
|
||
- name: Upgrade helm release (reset_then_reuse_values=true with default value for reset_values and reuse_values=false) | ||
kubernetes.core.helm: | ||
binary_path: "{{ helm_binary }}" | ||
chart_ref: "{{ test_chart_path }}" | ||
reuse_values: false | ||
reset_then_reuse_values: true | ||
release_name: "{{ test_release_name }}" | ||
release_namespace: "{{ helm_namespace }}" | ||
values: | ||
ansible_version: devel | ||
register: helm_upgrade | ||
|
||
- name: Ensure task reported change | ||
assert: | ||
that: | ||
- helm_upgrade is changed | ||
|
||
always: | ||
- name: Remove temporary directory | ||
file: | ||
path: "{{ helm_dir.path }}" | ||
state: absent | ||
ignore_errors: true | ||
|
||
- name: Uninstall helm diff | ||
kubernetes.core.helm_plugin: | ||
binary_path: "{{ helm_binary }}" | ||
state: absent | ||
plugin_name: diff | ||
ignore_errors: true | ||
|
||
- name: Remove helm namespace | ||
kubernetes.core.k8s: | ||
api_version: v1 | ||
kind: Namespace | ||
name: "{{ helm_namespace }}" | ||
state: absent | ||
ignore_errors: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.