mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-30 03:14:40 +00:00
helm - add support for -set options when running helm install (#546)
helm - add support for -set options when running helm install SUMMARY helm support setting options -set, -set-string, -set-file and -set-json when running helm install ISSUE TYPE Feature Pull Request COMPONENT NAME helm ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: Bikouo Aubin <None> Reviewed-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
2
tests/integration/targets/helm_kubeconfig/aliases
Normal file
2
tests/integration/targets/helm_kubeconfig/aliases
Normal file
@@ -0,0 +1,2 @@
|
||||
time=40
|
||||
helm
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
|
||||
default_kubeconfig_path: "~/.kube/config"
|
||||
test_namespace:
|
||||
- "helm-in-memory-kubeconfig"
|
||||
- "helm-kubeconfig-with-ca-cert"
|
||||
- "helm-kubeconfig-with-insecure-skip-tls-verify"
|
||||
3
tests/integration/targets/helm_kubeconfig/meta/main.yml
Normal file
3
tests/integration/targets/helm_kubeconfig/meta/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
dependencies:
|
||||
- remove_namespace
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- set_fact:
|
||||
custom_config: "{{ lookup('file', default_kubeconfig_path | expanduser) | from_yaml }}"
|
||||
|
||||
- name: Test helm modules using in-memory kubeconfig
|
||||
include_tasks: "tests_helm_auth.yml"
|
||||
vars:
|
||||
test_kubeconfig: "{{ custom_config }}"
|
||||
helm_namespace: "{{ test_namespace[0] }}"
|
||||
@@ -0,0 +1,76 @@
|
||||
---
|
||||
- set_fact:
|
||||
content: "{{ lookup('file', default_kubeconfig_path) | from_yaml }}"
|
||||
custom_content: {}
|
||||
clusters: []
|
||||
|
||||
- set_fact:
|
||||
custom_content: "{{ custom_content | combine({item.key: item.value}) }}"
|
||||
when: "{{ item.key not in ['clusters'] }}"
|
||||
with_dict: "{{ content }}"
|
||||
|
||||
- set_fact:
|
||||
clusters: "{{ clusters + [item | combine({'cluster': {'certificate-authority-data': omit}}, recursive=true)] }}"
|
||||
with_items: "{{ content.clusters }}"
|
||||
|
||||
- set_fact:
|
||||
custom_content: "{{ custom_content | combine({'clusters': clusters}) }}"
|
||||
|
||||
- name: create temporary file for ca_cert
|
||||
tempfile:
|
||||
suffix: .cacert
|
||||
register: ca_file
|
||||
|
||||
- name: copy content into certificate file
|
||||
copy:
|
||||
content: "{{ content.clusters.0.cluster['certificate-authority-data'] | b64decode }}"
|
||||
dest: "{{ ca_file.path }}"
|
||||
|
||||
- name: create temporary file to save config in
|
||||
tempfile:
|
||||
suffix: .config
|
||||
register: tfile
|
||||
|
||||
- name: create custom config
|
||||
copy:
|
||||
content: "{{ custom_content | to_yaml }}"
|
||||
dest: "{{ tfile.path }}"
|
||||
|
||||
- block:
|
||||
- name: Install Redis chart without ca_cert (should fail)
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_repo_url: https://charts.bitnami.com/bitnami
|
||||
chart_ref: redis
|
||||
namespace: "{{ helm_namespace }}"
|
||||
create_namespace: true
|
||||
name: redis-chart
|
||||
chart_version: '17.0.5'
|
||||
release_values:
|
||||
architecture: standalone
|
||||
release_state: present
|
||||
kubeconfig: "{{ tfile.path }}"
|
||||
ignore_errors: true
|
||||
register: _install
|
||||
|
||||
- name: assert task failed
|
||||
assert:
|
||||
that:
|
||||
- _install is failed
|
||||
- '"Error: Kubernetes cluster unreachable" in _install.msg'
|
||||
|
||||
- name: Test helm modules using in-memory kubeconfig
|
||||
include_tasks: "tests_helm_auth.yml"
|
||||
vars:
|
||||
test_kubeconfig: "{{ tfile.path }}"
|
||||
test_ca_cert: "{{ ca_file.path }}"
|
||||
|
||||
vars:
|
||||
helm_namespace: "{{ test_namespace[1] }}"
|
||||
|
||||
always:
|
||||
- name: Delete temporary file
|
||||
file:
|
||||
state: absent
|
||||
path: "{{ tfile.path }}"
|
||||
ignore_errors: true
|
||||
@@ -0,0 +1,67 @@
|
||||
---
|
||||
- set_fact:
|
||||
content: "{{ lookup('file', default_kubeconfig_path) | from_yaml }}"
|
||||
custom_content: {}
|
||||
clusters: []
|
||||
|
||||
- set_fact:
|
||||
custom_content: "{{ custom_content | combine({item.key: item.value}) }}"
|
||||
when: "{{ item.key not in ['clusters'] }}"
|
||||
with_dict: "{{ content }}"
|
||||
|
||||
- set_fact:
|
||||
clusters: "{{ clusters + [item | combine({'cluster': {'certificate-authority-data': omit}}, recursive=true)] }}"
|
||||
with_items: "{{ content.clusters }}"
|
||||
|
||||
- set_fact:
|
||||
custom_content: "{{ custom_content | combine({'clusters': clusters}) }}"
|
||||
|
||||
- name: create temporary file to save config in
|
||||
tempfile:
|
||||
suffix: .config
|
||||
register: tfile
|
||||
|
||||
- name: create custom config
|
||||
copy:
|
||||
content: "{{ custom_content | to_yaml }}"
|
||||
dest: "{{ tfile.path }}"
|
||||
|
||||
- block:
|
||||
- name: Install Redis chart without validate_certs=false (should fail)
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
chart_repo_url: https://charts.bitnami.com/bitnami
|
||||
chart_ref: redis
|
||||
namespace: "{{ helm_namespace }}"
|
||||
create_namespace: true
|
||||
name: redis-chart
|
||||
chart_version: '17.0.5'
|
||||
release_values:
|
||||
architecture: standalone
|
||||
release_state: present
|
||||
kubeconfig: "{{ tfile.path }}"
|
||||
validate_certs: true
|
||||
ignore_errors: true
|
||||
register: _install
|
||||
|
||||
- name: assert task failed
|
||||
assert:
|
||||
that:
|
||||
- _install is failed
|
||||
- '"Error: Kubernetes cluster unreachable" in _install.msg'
|
||||
|
||||
- name: Test helm modules using in-memory kubeconfig
|
||||
include_tasks: "tests_helm_auth.yml"
|
||||
vars:
|
||||
test_kubeconfig: "{{ tfile.path }}"
|
||||
test_validate_certs: false
|
||||
|
||||
vars:
|
||||
helm_namespace: "{{ test_namespace[2] }}"
|
||||
|
||||
always:
|
||||
- name: Delete temporary file
|
||||
file:
|
||||
state: absent
|
||||
path: "{{ tfile.path }}"
|
||||
ignore_errors: true
|
||||
19
tests/integration/targets/helm_kubeconfig/tasks/main.yml
Normal file
19
tests/integration/targets/helm_kubeconfig/tasks/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Test helm with in-memory kubeconfig
|
||||
include_tasks: "from_in_memory_kubeconfig.yml"
|
||||
|
||||
- name: Test helm with custom kubeconfig and validate_certs=false
|
||||
include_tasks: "from_kubeconfig_with_validate_certs.yml"
|
||||
loop_control:
|
||||
loop_var: test_helm_version
|
||||
with_items:
|
||||
- "v3.10.3"
|
||||
- "v3.8.2"
|
||||
|
||||
- name: Test helm with custom kubeconfig and ca_cert
|
||||
include_tasks: "from_kubeconfig_with_cacert.yml"
|
||||
loop_control:
|
||||
loop_var: test_helm_version
|
||||
with_items:
|
||||
- "v3.5.1"
|
||||
- "v3.4.2"
|
||||
@@ -0,0 +1,197 @@
|
||||
---
|
||||
- name: create temporary directory
|
||||
tempfile:
|
||||
state: directory
|
||||
suffix: .helm
|
||||
register: _dir
|
||||
|
||||
- name: Install helm binary
|
||||
block:
|
||||
- name: "Install {{ test_helm_version }}"
|
||||
include_role:
|
||||
name: install_helm
|
||||
vars:
|
||||
helm_version: "{{ test_helm_version }}"
|
||||
|
||||
when: test_helm_version is defined
|
||||
|
||||
- set_fact:
|
||||
saved_kubeconfig_path: "{{ _dir.path }}/config"
|
||||
|
||||
- block:
|
||||
- name: Copy default kubeconfig
|
||||
copy:
|
||||
remote_src: true
|
||||
src: "{{ default_kubeconfig_path }}"
|
||||
dest: "{{ saved_kubeconfig_path }}"
|
||||
|
||||
- name: Delete default kubeconfig
|
||||
file:
|
||||
path: "{{ default_kubeconfig_path }}"
|
||||
state: absent
|
||||
|
||||
# helm_plugin and helm_plugin_info
|
||||
- name: Install subenv plugin
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
state: present
|
||||
plugin_path: https://github.com/hydeenoble/helm-subenv
|
||||
register: plugin
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- plugin is changed
|
||||
|
||||
- name: Gather info about all plugin
|
||||
helm_plugin_info:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
register: plugin_info
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- '"plugin_list" in plugin_info'
|
||||
- plugin_info.plugin_list != []
|
||||
|
||||
# helm_repository, helm, helm_info
|
||||
- name: Add test_bitnami chart repository
|
||||
helm_repository:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test_bitnami
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
repo_url: https://charts.bitnami.com/bitnami
|
||||
register: repository
|
||||
|
||||
- name: Assert that repository was added
|
||||
assert:
|
||||
that:
|
||||
- repository is changed
|
||||
|
||||
- name: Install chart from repository added before
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: rabbitmq
|
||||
chart_ref: test_bitnami/rabbitmq
|
||||
namespace: "{{ helm_namespace }}"
|
||||
update_repo_cache: true
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
create_namespace: true
|
||||
register: deploy
|
||||
|
||||
- name: Assert chart was successfully deployed
|
||||
assert:
|
||||
that:
|
||||
- deploy is changed
|
||||
|
||||
- name: Get chart content
|
||||
helm_info:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
name: "rabbitmq"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
register: chart_info
|
||||
|
||||
- name: Assert chart was successfully deployed
|
||||
assert:
|
||||
that:
|
||||
- '"status" in chart_info'
|
||||
- chart_info.status.status is defined
|
||||
- chart_info.status.status == "deployed"
|
||||
|
||||
- name: Remove chart
|
||||
helm:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: rabbitmq
|
||||
namespace: "{{ helm_namespace }}"
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
state: absent
|
||||
register: remove_chart
|
||||
|
||||
- name: Assert chart was successfully removed
|
||||
assert:
|
||||
that:
|
||||
- remove_chart is changed
|
||||
|
||||
- name: Get chart content
|
||||
helm_info:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
name: "rabbitmq"
|
||||
namespace: "{{ helm_namespace }}"
|
||||
register: chart_info
|
||||
|
||||
- name: Assert chart was successfully deployed
|
||||
assert:
|
||||
that:
|
||||
- '"status" not in chart_info'
|
||||
|
||||
- name: Remove chart repository
|
||||
helm_repository:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test_bitnami
|
||||
kubeconfig: "{{ test_kubeconfig | default(omit) }}"
|
||||
validate_certs: "{{ test_validate_certs | default(omit) }}"
|
||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
- name: Assert that repository was removed
|
||||
assert:
|
||||
that:
|
||||
- remove is changed
|
||||
|
||||
always:
|
||||
- name: Return kubeconfig
|
||||
copy:
|
||||
remote_src: true
|
||||
src: "{{ saved_kubeconfig_path }}"
|
||||
dest: "{{ default_kubeconfig_path }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete temporary directory
|
||||
file:
|
||||
path: "{{ _dir.path }}"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete temporary directory for helm install
|
||||
file:
|
||||
path: "{{ _helm_install.path }}"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
when: _helm_install is defined
|
||||
|
||||
- name: Remove subenv plugin
|
||||
helm_plugin:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
plugin_name: subenv
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete namespace
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ helm_namespace }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: Delete helm repository
|
||||
helm_repository:
|
||||
binary_path: "{{ helm_binary }}"
|
||||
name: test_bitnami
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
Reference in New Issue
Block a user