mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
helm - add support for repo location when running helm diff (#389)
helm - add support for repo location when running helm diff SUMMARY closes #174 ISSUE TYPE Feature Pull Request COMPONENT NAME helm Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: None <None> Reviewed-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- helm - support repo location for helm diff (https://github.com/ansible-collections/kubernetes.core/issues/174).
|
||||
@@ -9,6 +9,7 @@
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: present
|
||||
plugin_path: https://github.com/databus23/helm-diff
|
||||
plugin_version: 3.4.0
|
||||
|
||||
- name: Copy test chart
|
||||
copy:
|
||||
@@ -160,6 +161,79 @@
|
||||
that:
|
||||
- install is not changed
|
||||
|
||||
# Test helm diff with chart_repo_url
|
||||
- name: Define Redis chart values
|
||||
set_fact:
|
||||
redis_chart_values:
|
||||
commonLabels:
|
||||
phase: testing
|
||||
company: RedHat
|
||||
image:
|
||||
tag: 6.2.6-debian-10-r135
|
||||
architecture: standalone
|
||||
|
||||
- name: Install Redis chart
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_repo_url: https://charts.bitnami.com/bitnami
|
||||
chart_ref: redis
|
||||
namespace: "{{ helm_namespace }}"
|
||||
name: redis-chart
|
||||
chart_version: '16.0.0'
|
||||
release_values: "{{ redis_chart_values }}"
|
||||
|
||||
- name: Upgrade Redis chart
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_repo_url: https://charts.bitnami.com/bitnami
|
||||
chart_ref: redis
|
||||
namespace: "{{ helm_namespace }}"
|
||||
name: redis-chart
|
||||
chart_version: '16.0.0'
|
||||
release_values: "{{ redis_chart_values }}"
|
||||
check_mode: yes
|
||||
register: redis_upgrade
|
||||
|
||||
- name: Assert that module raised a warning
|
||||
assert:
|
||||
that:
|
||||
- not redis_upgrade.changed
|
||||
- redis_upgrade.warnings is defined
|
||||
- redis_upgrade.warnings | length == 1
|
||||
- redis_upgrade.warnings[0] == "The default idempotency check can fail to report changes in certain cases. Install helm diff >= 3.4.1 for better results."
|
||||
|
||||
- name: Uninstall helm diff
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: absent
|
||||
plugin_name: diff
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Install helm diff (version=3.4.1)
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
state: present
|
||||
plugin_path: https://github.com/databus23/helm-diff
|
||||
plugin_version: 3.4.1
|
||||
|
||||
- name: Upgrade Redis chart once again
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_repo_url: https://charts.bitnami.com/bitnami
|
||||
chart_ref: redis
|
||||
namespace: "{{ helm_namespace }}"
|
||||
name: redis-chart
|
||||
chart_version: '16.0.0'
|
||||
release_values: "{{ redis_chart_values }}"
|
||||
check_mode: yes
|
||||
register: redis_upgrade_2
|
||||
|
||||
- name: Assert that module raised a warning
|
||||
assert:
|
||||
that:
|
||||
- redis_upgrade_2.changed
|
||||
- redis_upgrade_2.warnings is not defined
|
||||
|
||||
always:
|
||||
- name: Remove chart directory
|
||||
file:
|
||||
|
||||
@@ -27,6 +27,10 @@ requirements:
|
||||
description:
|
||||
- Install, upgrade, delete packages with the Helm package manager.
|
||||
|
||||
notes:
|
||||
- The default idempotency check can fail to report changes when C(release_state) is set to C(present)
|
||||
and C(chart_repo_url) is defined. Install helm diff >= 3.4.1 for better results.
|
||||
|
||||
options:
|
||||
chart_ref:
|
||||
description:
|
||||
@@ -495,9 +499,9 @@ def load_values_files(values_files):
|
||||
return values
|
||||
|
||||
|
||||
def has_plugin(command, plugin):
|
||||
def get_plugin_version(command, plugin):
|
||||
"""
|
||||
Check if helm plugin is installed.
|
||||
Check if helm plugin is installed and return corresponding version
|
||||
"""
|
||||
|
||||
cmd = command + " plugin"
|
||||
@@ -505,12 +509,12 @@ def has_plugin(command, plugin):
|
||||
out = parse_helm_plugin_list(module, output=output.splitlines())
|
||||
|
||||
if not out:
|
||||
return False
|
||||
return None
|
||||
|
||||
for line in out:
|
||||
if line[0] == plugin:
|
||||
return True
|
||||
return False
|
||||
return line[1]
|
||||
return None
|
||||
|
||||
|
||||
def helmdiff_check(
|
||||
@@ -522,6 +526,7 @@ def helmdiff_check(
|
||||
values_files=None,
|
||||
chart_version=None,
|
||||
replace=False,
|
||||
chart_repo_url=None,
|
||||
):
|
||||
"""
|
||||
Use helm diff to determine if a release would change by upgrading a chart.
|
||||
@@ -530,6 +535,8 @@ def helmdiff_check(
|
||||
cmd += " " + release_name
|
||||
cmd += " " + chart_ref
|
||||
|
||||
if chart_repo_url is not None:
|
||||
cmd += " " + "--repo=" + chart_repo_url
|
||||
if chart_version is not None:
|
||||
cmd += " " + "--version=" + chart_version
|
||||
if not replace:
|
||||
@@ -733,7 +740,14 @@ def main():
|
||||
|
||||
else:
|
||||
|
||||
if has_plugin(helm_cmd_common, "diff") and not chart_repo_url:
|
||||
helm_diff_version = get_plugin_version(helm_cmd_common, "diff")
|
||||
if helm_diff_version and (
|
||||
not chart_repo_url
|
||||
or (
|
||||
chart_repo_url
|
||||
and LooseVersion(helm_diff_version) >= LooseVersion("3.4.1")
|
||||
)
|
||||
):
|
||||
(would_change, prepared) = helmdiff_check(
|
||||
module,
|
||||
helm_cmd_common,
|
||||
@@ -743,13 +757,14 @@ def main():
|
||||
values_files,
|
||||
chart_version,
|
||||
replace,
|
||||
chart_repo_url,
|
||||
)
|
||||
if would_change and module._diff:
|
||||
opt_result["diff"] = {"prepared": prepared}
|
||||
else:
|
||||
module.warn(
|
||||
"The default idempotency check can fail to report changes in certain cases. "
|
||||
"Install helm diff for better results."
|
||||
"Install helm diff >= 3.4.1 for better results."
|
||||
)
|
||||
would_change = default_check(
|
||||
release_status, chart_info, release_values, values_files
|
||||
|
||||
Reference in New Issue
Block a user