Skip to content

Commit

Permalink
Add appVersion check to Helm
Browse files Browse the repository at this point in the history
When upgrading a Helm release include the chart's appVersion in the idempotence check.

Fixes ansible-collections#246
  • Loading branch information
nat45928 committed Oct 6, 2020
1 parent fc1f4e5 commit 48574ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions molecule/default/roles/helm/files/test-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: test-chart
description: A chart used in molecule tests
type: application
version: 0.1.0
appVersion: "default"
39 changes: 39 additions & 0 deletions molecule/default/roles/helm/tasks/tests_chart/from_local_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,49 @@
chart_source: "/tmp/helm_test_repo/stable/{{ chart_test }}/"
chart_source_upgrade: "/tmp/helm_test_repo_upgrade/stable/{{ chart_test }}/"

- name: Test appVersion idempotence
vars:
chart_test: "test-chart"
chart_test_version: "0.1.0"
chart_test_version_upgrade: "0.1.0"
chart_test_app_version: "v1"
chart_test_upgrade_app_version: "v2"
block:
- name: Copy test chart
copy:
src: "{{ chart_test }}"
dest: "/tmp/helm_test_appversion/"

# create package with appVersion v1
- name: "Package chart into archive with appVersion {{ chart_test_app_version }}"
command: "{{ helm_binary }} package --app-version {{ chart_test_app_version }} /tmp/helm_test_appversion/{{ chart_test }}"
- name: "Move appVersion {{ chart_test_app_version }} chart archive"
copy:
remote_src: true
src: "test-chart-{{ chart_test_version }}.tgz"
dest: "/tmp/helm_test_appversion/{{ chart_test }}-{{ chart_test_app_version }}-{{ chart_test_version }}.tgz"

# create package with appVersion v2
- name: "Package chart into archive with appVersion {{ chart_test_upgrade_app_version }}"
command: "{{ helm_binary }} package --app-version {{ chart_test_upgrade_app_version }} /tmp/helm_test_appversion/{{ chart_test }}"
- name: "Move appVersion {{ chart_test_upgrade_app_version }} chart archive"
copy:
remote_src: true
src: "test-chart-{{ chart_test_version }}.tgz"
dest: "/tmp/helm_test_appversion/{{ chart_test }}-{{ chart_test_upgrade_app_version }}-{{ chart_test_version }}.tgz"

- name: Install Chart from local path
include_tasks: "../tests_chart.yml"
vars:
source: local_path
chart_source: "/tmp/helm_test_appversion/{{ chart_test }}-{{ chart_test_app_version }}-{{ chart_test_version }}.tgz"
chart_source_upgrade: "/tmp/helm_test_appversion/{{ chart_test }}-{{ chart_test_upgrade_app_version }}-{{ chart_test_version }}.tgz"

- name: Remove clone repos
file:
path: "{{ item }}"
state: absent
with_items:
- /tmp/helm_test_repo
- /tmp/helm_test_repo_upgrade
- /tmp/helm_test_appversion
3 changes: 2 additions & 1 deletion plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ def main():
changed = True

elif force or release_values != release_status['values'] \
or (chart_info['name'] + '-' + chart_info['version']) != release_status["chart"]:
or (chart_info['name'] + '-' + chart_info['version']) != release_status["chart"] \
or chart_info['appVersion'] != release_status["app_version"]:
helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout,
disable_hook, force, values_files=values_files, atomic=atomic,
create_namespace=create_namespace, replace=replace)
Expand Down

0 comments on commit 48574ee

Please sign in to comment.