mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 05:22:39 +00:00
Add helm dependency update (#208)
Add helm dependency update SUMMARY Execute the helm dependency update under the hood when found dependencies block in Chart.yaml file. Support the execution of: Standalone dependency update by executing: helm dependency update CHART Inline dependency update when specifying the helm chart_repo_url by adding --dependency-update to the helm install command. ISSUE TYPE Feature Pull Request #191 COMPONENT NAME helm, helm_template ADDITIONAL INFORMATION There is a doc generated for history_max option for the helm module. I think that is not generated in the previous PR #164. There is others changes affect the docs/ folder when I run the collection_prep_add_docs -p . command. These changes are added in the last commit 64eab40. I let you decide rather we keep the commit or remove it. The --dependency-update insertion option is tested used a local helm chart repository create via docker. So here are the tasks that test this feature. Maybe if we create a GitHub repository for the helm chart, we can add this test code in the CI pipeline. # Test The update dependency with chart_repo_url - name: "Test chart without dependencies block and chart_repo_url defined" block: - name: "Test chart without dependencies block and chart_repo_url defined" helm: binary_path: "{{ helm_binary }}" name: test chart_ref: "ingress-nginx" chart_repo_url: https://kubernetes.github.io/ingress-nginx chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" create_namespace: yes register: release - assert: that: - "'--dependency-update' not in release.command" - "'upgrade' in release.command" success_msg: "Command does not contains '--dependency-update' options" fail_msg: "Command contains '--dependency-update' options" - name: "Test chart with dependencies block and chart_repo_url defined and replace True" block: - name: "Test chart with dependencies block and chart_repo_url defined and replace True" helm: binary_path: "{{ helm_binary }}" name: test1 chart_ref: "dep_up" chart_repo_url: http://repo:8080/charts chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" create_namespace: yes replace: true register: release - debug: var=release - assert: that: - "'--dependency-update' in release.command" - "'install' in release.command" success_msg: "Command contains '--dependency-update' options with helm install command" fail_msg: "Command not contains '--dependency-update' with helm install command" - name: "Test chart with dependencies block and chart_repo_url defined and replace False fails" block: - name: "Test chart with dependencies block and chart_repo_url defined and replace False fails" helm: binary_path: "{{ helm_binary }}" name: test2 chart_ref: "dep_up" chart_repo_url: http://repo:8080/charts chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" create_namespace: yes replace: false register: release ignore_errors: true - assert: that: - release.failed - release.msg == "'--dependency-update' hasn't been supported yet with 'helm upgrade'. Please use 'helm install' instead by adding 'replace' option" success_msg: "Command build fail when adding '--dependency-update' with the helm upgrade command" Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: Wissem BEN CHAABANE <benchaaben.wissem@gmail.com> Reviewed-by: Bikouo Aubin <None>
This commit is contained in:
committed by
GitHub
parent
f2f4b66d77
commit
4fa1fb966b
@@ -25,3 +25,4 @@ test_namespace:
|
||||
- "helm-local-path-001"
|
||||
- "helm-local-path-002"
|
||||
- "helm-local-path-003"
|
||||
- "helm-dep"
|
||||
|
||||
10
tests/integration/targets/helm/files/dep-up/Chart.yaml
Normal file
10
tests/integration/targets/helm/files/dep-up/Chart.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
apiVersion: v2
|
||||
name: dep_up
|
||||
description: A Helm chart for molecule test
|
||||
type: application
|
||||
version: 0.1.0
|
||||
appVersion: "default"
|
||||
dependencies:
|
||||
- name: test-chart
|
||||
repository: file://../test-chart
|
||||
version: "0.1.0"
|
||||
2
tests/integration/targets/helm/files/dep-up/values.yaml
Normal file
2
tests/integration/targets/helm/files/dep-up/values.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
chart-test:
|
||||
myValue: helm update dependency test
|
||||
@@ -27,6 +27,9 @@
|
||||
- from_repository
|
||||
- from_url
|
||||
|
||||
- name: test helm dependency update
|
||||
include_tasks: test_up_dep.yml
|
||||
|
||||
- name: Test helm plugin
|
||||
include_tasks: tests_helm_plugin.yml
|
||||
|
||||
|
||||
171
tests/integration/targets/helm/tasks/test_up_dep.yml
Normal file
171
tests/integration/targets/helm/tasks/test_up_dep.yml
Normal file
@@ -0,0 +1,171 @@
|
||||
# Helm module
|
||||
- name: "Test dependency update for helm module"
|
||||
block:
|
||||
- name: copy chart
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /tmp
|
||||
loop:
|
||||
- test-chart
|
||||
- dep-up
|
||||
|
||||
- set_fact:
|
||||
helm_namespace: "{{ test_namespace[10] }}"
|
||||
|
||||
- name: "Test chart with dependency_update false"
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test
|
||||
chart_ref: "/tmp/test-chart"
|
||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
dependency_update: false
|
||||
create_namespace: yes
|
||||
register: release
|
||||
|
||||
- name: "Get stats of the subchart"
|
||||
stat:
|
||||
path: "/tmp/test-chart/Chart.lock"
|
||||
register: stat_result
|
||||
|
||||
- name: "Check if the subchart not exist in chart"
|
||||
assert:
|
||||
that:
|
||||
- not stat_result.stat.exists
|
||||
success_msg: "subchart not exist in the chart directory"
|
||||
fail_msg: "subchart exist in the charts directory"
|
||||
|
||||
- name: "Test chart without dependencies block and dependency_update true"
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test
|
||||
chart_ref: "/tmp/test-chart"
|
||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
create_namespace: yes
|
||||
dependency_update: true
|
||||
ignore_errors: true
|
||||
register: release
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- release.warnings[0] == "There is no dependencies block defined in Chart.yaml. Dependency update will not be performed. Please consider add dependencies block or disable dependency_update to remove this warning."
|
||||
success_msg: "warning when there is no dependencies block with dependency_update enabled"
|
||||
|
||||
- name: "Test chart with dependencies block and dependency_update true"
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test
|
||||
chart_ref: "/tmp/dep-up"
|
||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
dependency_update: true
|
||||
create_namespace: yes
|
||||
register: release
|
||||
|
||||
- name: "Get stats of the subchart"
|
||||
stat:
|
||||
path: "/tmp/dep-up/Chart.lock"
|
||||
register: stat_result
|
||||
|
||||
- name: "Check if the subchart exists in chart"
|
||||
assert:
|
||||
that:
|
||||
- stat_result.stat.exists
|
||||
success_msg: "subchart exist in the chart directory"
|
||||
fail_msg: "subchart not exist in the charts directory"
|
||||
always:
|
||||
- name: Remove helm namespace
|
||||
k8s:
|
||||
api_version: v1
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
state: absent
|
||||
wait: true
|
||||
wait_timeout: 180
|
||||
|
||||
- name: "Remove charts"
|
||||
file:
|
||||
state: absent
|
||||
path: "/tmp/{{ item }}"
|
||||
loop:
|
||||
- test-chart
|
||||
- dep-up
|
||||
|
||||
# Helm_template module
|
||||
- name: "Test dependency update for helm_template module"
|
||||
block:
|
||||
- name: copy chart
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /tmp
|
||||
loop:
|
||||
- test-chart
|
||||
- dep-up
|
||||
|
||||
- name: Test Helm dependency update true
|
||||
helm_template:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_ref: "/tmp/dep-up"
|
||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
||||
dependency_update: true
|
||||
output_dir: "/tmp"
|
||||
register: result
|
||||
|
||||
- name: "Get stats of the subchart"
|
||||
stat:
|
||||
path: "{{ item }}"
|
||||
register: stat_result
|
||||
loop:
|
||||
- /tmp/dep-up/Chart.lock
|
||||
- /tmp/dep_up/charts/test-chart/templates/configmap.yaml
|
||||
|
||||
- name: "Check if the subchart exist in chart"
|
||||
assert:
|
||||
that:
|
||||
- stat_result.results[0].stat.exists
|
||||
- stat_result.results[1].stat.exists
|
||||
success_msg: "subchart exist in the charts directory"
|
||||
fail_msg: "There is no Subchart pulled"
|
||||
|
||||
- name: Test Helm subchart not pulled when dependency_update false for helm_template
|
||||
helm_template:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_ref: "/tmp/test-chart"
|
||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
||||
dependency_update: false
|
||||
output_dir: "/tmp"
|
||||
register: result
|
||||
|
||||
- name: "Get stats of the subchart"
|
||||
stat:
|
||||
path: "{{ item }}"
|
||||
register: stat_result
|
||||
loop:
|
||||
- /tmp/test-chart/Chart.lock
|
||||
- /tmp/test-chart/templates/configmap.yaml
|
||||
|
||||
- name: "Check if the subchart not exist in chart"
|
||||
assert:
|
||||
that:
|
||||
- not stat_result.results[0].stat.exists
|
||||
- stat_result.results[1].stat.exists
|
||||
success_msg: "subchart not exist in the charts directory"
|
||||
fail_msg: "There is no Subchart pulled"
|
||||
always:
|
||||
- name: Remove helm namespace
|
||||
k8s:
|
||||
api_version: v1
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
state: absent
|
||||
wait: true
|
||||
wait_timeout: 180
|
||||
|
||||
- name: "Remove charts"
|
||||
file:
|
||||
state: absent
|
||||
path: "/tmp/{{ item }}"
|
||||
loop:
|
||||
- test-chart
|
||||
- dep-up
|
||||
Reference in New Issue
Block a user