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 5, 2020
1 parent 0f33aaf commit de426a8
Show file tree
Hide file tree
Showing 3 changed files with 43 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"
35 changes: 35 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,45 @@
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/"

- name: Create test archives
block:
- name: "Package chart into archive with appVersion {{ item }}"
command: "{{ helm_binary }} package --app-version {{ item }} /tmp/helm_test_appversion/{{ chart_test }}"

- name: "Move appVersion {{ item }} chart archive"
copy:
remote_src: true
src: "test-chart-{{ chart_test_version }}.tgz"
dest: "/tmp/helm_test_appversion/{{ chart_test }}-{{ item }}-{{ chart_test_version }}.tgz"
with_items:
- "{{ chart_test_app_version }}"
- "{{ chart_test_upgrade_app_version }}"

- 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_repo_upgrade
3 changes: 2 additions & 1 deletion plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,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, atomic=atomic, create_namespace=create_namespace,
replace=replace)
Expand Down

0 comments on commit de426a8

Please sign in to comment.