mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 21:12:37 +00:00
add reset_then_reuse_values support to helm module (#802)
SUMMARY Starting with version 3.14.0, Helm supports --reset-then-reuse-values. As discussed on the original PR. This greatly improves on --reuse-values as it allows to avoid templates errors when new features are added to an upgraded chart. Closes #803 ISSUE TYPE Feature Pull Request COMPONENT NAME helm ADDITIONAL INFORMATION This PR is greatly 'inspired' by #575 and because I wasn't sure how I could provide additional tests for it, I actually copied those build previously for --reuse-values (as it is an improvement on this feature. Reviewed-by: Bikouo Aubin Reviewed-by: Yuriy Novostavskiy Reviewed-by: b0z02003 Reviewed-by: Bianca Henderson <beeankha@gmail.com>
This commit is contained in:
@@ -26,3 +26,4 @@ test_namespace:
|
||||
- "helm-from-url"
|
||||
- "helm-reuse-values"
|
||||
- "helm-chart-with-space-into-name"
|
||||
- "helm-reset-then-reuse-values"
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
loop_control:
|
||||
loop_var: helm_version
|
||||
with_items:
|
||||
- "v3.8.0"
|
||||
- "v3.16.0"
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
- name: test helm upgrade with reuse_values
|
||||
include_tasks: test_helm_reuse_values.yml
|
||||
|
||||
- name: test helm upgrade with reset_then_reuse_values
|
||||
include_tasks: test_helm_reset_then_reuse_values.yml
|
||||
|
||||
- name: test helm dependency update
|
||||
include_tasks: test_up_dep.yml
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
- name: Test helm reset_then_reuse_values
|
||||
vars:
|
||||
helm_namespace: "{{ test_namespace[11] }}"
|
||||
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
|
||||
@@ -10,7 +10,7 @@
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: present
|
||||
plugin_path: https://github.com/databus23/helm-diff
|
||||
plugin_version: 3.4.0
|
||||
plugin_version: 3.9.13
|
||||
|
||||
- name: Copy test chart
|
||||
copy:
|
||||
@@ -324,3 +324,5 @@
|
||||
ignore_errors: true
|
||||
|
||||
- include_tasks: reuse_values.yml
|
||||
|
||||
- include_tasks: reset_then_reuse_values.yml
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
---
|
||||
- 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.14
|
||||
|
||||
- name: Copy test chart
|
||||
ansible.builtin.copy:
|
||||
src: "test-chart-reuse-values"
|
||||
dest: "{{ helm_dir.path }}"
|
||||
|
||||
- name: Delete existing namespace
|
||||
kubernetes.core.k8s:
|
||||
state: absent
|
||||
wait: true
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
ignore_errors: true
|
||||
|
||||
- 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
|
||||
|
||||
# Delete helm and helm diff to install older version
|
||||
- name: Uninstall helm diff
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: absent
|
||||
plugin_name: diff
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete Helm folders
|
||||
file:
|
||||
path: /tmp/helm/
|
||||
state: absent
|
||||
|
||||
- name: Init Helm folders
|
||||
file:
|
||||
path: /tmp/helm
|
||||
state: directory
|
||||
|
||||
- name: Set Helm old version
|
||||
set_fact:
|
||||
helm_archive_name: "helm-v3.8.0-linux-amd64.tar.gz"
|
||||
helm_diff_old_version: "3.8.0"
|
||||
|
||||
- name: Unarchive Helm binary
|
||||
unarchive:
|
||||
src: "https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}"
|
||||
dest: /tmp/helm/
|
||||
remote_src: yes
|
||||
retries: 10
|
||||
delay: 5
|
||||
register: result
|
||||
until: result is not failed
|
||||
|
||||
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
||||
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: test
|
||||
register: helm_upgrade
|
||||
ignore_errors: true
|
||||
|
||||
- name: Debug
|
||||
debug:
|
||||
var: helm_upgrade
|
||||
|
||||
- name: Ensure warning for Helm version
|
||||
assert:
|
||||
that:
|
||||
- helm_upgrade is failed
|
||||
- '"reset_then_reuse_values requires helm >= 3.14.0, current version is" in helm_upgrade.msg'
|
||||
|
||||
- name: Install helm diff
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: present
|
||||
plugin_path: https://github.com/databus23/helm-diff
|
||||
plugin_version: "{{ helm_diff_old_version }}"
|
||||
|
||||
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
||||
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
|
||||
ignore_errors: true
|
||||
|
||||
- name: Debug
|
||||
debug:
|
||||
var: helm_upgrade
|
||||
|
||||
- name: Ensure warning for Helm Diff version
|
||||
assert:
|
||||
that:
|
||||
- helm_upgrade is failed
|
||||
- '"reset_then_reuse_values requires helm diff >= 3.9.12, current version is" in helm_upgrade.msg'
|
||||
|
||||
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
|
||||
wait: true
|
||||
ignore_errors: true
|
||||
@@ -90,4 +90,5 @@
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
state: absent
|
||||
wait: true
|
||||
ignore_errors: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---
|
||||
helm_version: v3.8.0
|
||||
helm_version: v3.16.4
|
||||
helm_install_path: /tmp/helm
|
||||
helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"
|
||||
|
||||
Reference in New Issue
Block a user