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:
Bikouo Aubin
2023-01-23 17:19:42 +01:00
committed by GitHub
parent 804b9ab57c
commit af7c24cba7
57 changed files with 473 additions and 91 deletions

View File

@@ -0,0 +1,5 @@
---
minor_changes:
- helm - add support for -set-file, -set-json, -set and -set-string options when running helm install (https://github.com/ansible-collections/kubernetes.core/issues/533).
- helm_template - add support for -set-file, -set-json, -set and -set-string options when running helm template (https://github.com/ansible-collections/kubernetes.core/pull/546).
- helm_info - add hooks, notes and manifest as part of returned information (https://github.com/ansible-collections/kubernetes.core/pull/546).

View File

@@ -215,6 +215,56 @@ class AnsibleHelmModule(object):
return {}
return yaml.safe_load(out)
def parse_yaml_content(self, content):
if not HAS_YAML:
self.fail_json(msg=missing_required_lib("yaml"), exception=HAS_YAML)
try:
return list(yaml.safe_load_all(content))
except (IOError, yaml.YAMLError) as exc:
self.fail_json(
msg="Error parsing YAML content: {0}".format(exc), raw_data=content
)
def get_manifest(self, release_name):
command = [
self.get_helm_binary(),
"get",
"manifest",
release_name,
]
rc, out, err = self.run_helm_command(" ".join(command))
if rc != 0:
self.fail_json(msg=err)
return self.parse_yaml_content(out)
def get_notes(self, release_name):
command = [
self.get_helm_binary(),
"get",
"notes",
release_name,
]
rc, out, err = self.run_helm_command(" ".join(command))
if rc != 0:
self.fail_json(msg=err)
return out
def get_hooks(self, release_name):
command = [
self.get_helm_binary(),
"get",
"hooks",
release_name,
]
rc, out, err = self.run_helm_command(" ".join(command))
if rc != 0:
self.fail_json(msg=err)
return self.parse_yaml_content(out)
def get_helm_plugin_list(self):
"""
Return `helm plugin list`
@@ -230,3 +280,24 @@ class AnsibleHelmModule(object):
rc=rc,
)
return (rc, out, err, helm_plugin_list)
def get_helm_set_values_args(self, set_values):
if any(v.get("value_type") == "json" for v in set_values):
if LooseVersion(self.get_helm_version()) < LooseVersion("3.10.0"):
self.fail_json(
msg="This module requires helm >= 3.10.0, to use set_values parameter with value type set to 'json'. current version is {0}".format(
self.get_helm_version()
)
)
options = []
for opt in set_values:
value_type = opt.get("value_type", "raw")
value = opt.get("value")
if value_type == "raw":
options.append("--set " + value)
else:
options.append("--set-{0} '{1}'".format(value_type, value))
return " ".join(options)

View File

@@ -105,6 +105,31 @@ options:
- Run C(helm repo update) before the operation. Can be run as part of the package installation or as a separate step (see Examples).
default: false
type: bool
set_values:
description:
- Values to pass to chart configuration
required: false
type: list
elements: dict
suboptions:
value:
description:
- Value to pass to chart configuration (e.g phase=prod).
type: str
required: true
value_type:
description:
- Use C(raw) set individual value.
- Use C(string) to force a string for an individual value.
- Use C(file) to set individual values from a file when the value itself is too long for the command line or is dynamically generated.
- Use C(json) to set json values (scalars/objects/arrays). This feature requires helm>=3.10.0.
default: raw
choices:
- raw
- string
- json
- file
version_added: '2.4.0'
#Helm options
disable_hook:
@@ -232,6 +257,15 @@ EXAMPLES = r"""
state: absent
update_repo_cache: true
- name: Deploy Grafana chart using set values on target
kubernetes.core.helm:
name: test
chart_ref: stable/grafana
release_namespace: monitoring
set_values:
- value: phase=prod
value_type: string
# From git
- name: Git clone stable repo on HEAD
ansible.builtin.git:
@@ -438,6 +472,7 @@ def deploy(
skip_crds=False,
timeout=None,
dependency_update=None,
set_value_args=None,
):
"""
Install/upgrade/rollback release chart
@@ -495,6 +530,9 @@ def deploy(
if history_max is not None:
deploy_command += " --history-max=%s" % str(history_max)
if set_value_args:
deploy_command += " " + set_value_args
deploy_command += " " + release_name + " " + chart_name
return deploy_command
@@ -643,6 +681,7 @@ def argument_spec():
replace=dict(type="bool", default=False),
skip_crds=dict(type="bool", default=False),
history_max=dict(type="int"),
set_values=dict(type="list", elements="dict"),
)
)
return arg_spec
@@ -692,6 +731,7 @@ def main():
skip_crds = module.params.get("skip_crds")
history_max = module.params.get("history_max")
timeout = module.params.get("timeout")
set_values = module.params.get("set_values")
if update_repo_cache:
run_repo_update(module)
@@ -760,6 +800,10 @@ def main():
)
if release_status is None: # Not installed
set_value_args = None
if set_values:
set_value_args = module.get_helm_set_values_args(set_values)
helm_cmd = deploy(
helm_cmd,
release_name,
@@ -778,6 +822,7 @@ def main():
skip_crds=skip_crds,
history_max=history_max,
timeout=timeout,
set_value_args=set_value_args,
)
changed = True
@@ -813,6 +858,10 @@ def main():
)
if force or would_change:
set_value_args = None
if set_values:
set_value_args = module.get_helm_set_values_args(set_values)
helm_cmd = deploy(
helm_cmd,
release_name,
@@ -831,6 +880,7 @@ def main():
history_max=history_max,
timeout=timeout,
dependency_update=dependency_update,
set_value_args=set_value_args,
)
changed = True

View File

@@ -117,6 +117,23 @@ status:
type: str
returned: always
description: Dict of Values used to deploy
hooks:
type: list
elements: dict
description: Hooks of the release
returned: always
version_added: "2.4.0"
notes:
type: str
description: Notes of the release
returned: always
version_added: "2.4.0"
manifest:
type: list
elements: dict
description: Manifest of the release
returned: always
version_added: "2.4.0"
"""
import traceback
@@ -185,6 +202,9 @@ def get_release_status(module, release_name, release_state, get_all_values=False
return None
release["values"] = module.get_values(release_name, get_all_values)
release["manifest"] = module.get_manifest(release_name)
release["notes"] = module.get_notes(release_name)
release["hooks"] = module.get_hooks(release_name)
return release

View File

@@ -114,6 +114,31 @@ options:
- Run C(helm repo update) before the operation. Can be run as part of the template generation or as a separate step.
default: false
type: bool
set_values:
description:
- Values to pass to chart configuration.
required: false
type: list
elements: dict
suboptions:
value:
description:
- Value to pass to chart configuration (e.g phase=prod).
type: str
required: true
value_type:
description:
- Use C(raw) set individual value.
- Use C(string) to force a string for an individual value.
- Use C(file) to set individual values from a file when the value itself is too long for the command line or is dynamically generated.
- Use C(json) to set json values (scalars/objects/arrays). This feature requires helm>=3.10.0.
default: raw
choices:
- raw
- string
- json
- file
version_added: '2.4.0'
"""
EXAMPLES = r"""
@@ -201,6 +226,7 @@ def template(
release_values=None,
values_files=None,
include_crds=False,
set_values=None,
):
cmd += " template "
@@ -244,6 +270,9 @@ def template(
if include_crds:
cmd += " --include-crds"
if set_values:
cmd += " " + set_values
return cmd
@@ -264,6 +293,7 @@ def main():
show_only=dict(type="list", default=[], elements="str"),
values_files=dict(type="list", default=[], elements="str"),
update_repo_cache=dict(type="bool", default=False),
set_values=dict(type="list", elements="dict"),
),
supports_check_mode=True,
)
@@ -282,6 +312,7 @@ def main():
release_values = module.params.get("release_values")
values_files = module.params.get("values_files")
update_repo_cache = module.params.get("update_repo_cache")
set_values = module.params.get("set_values")
if not IMP_YAML:
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
@@ -292,6 +323,10 @@ def main():
update_cmd = helm_cmd + " repo update"
module.run_helm_command(update_cmd)
set_values_args = None
if set_values:
set_values_args = module.get_helm_set_values_args(set_values)
tmpl_cmd = template(
helm_cmd,
chart_ref,
@@ -306,6 +341,7 @@ def main():
show_only=show_only,
values_files=values_files,
include_crds=include_crds,
set_values=set_values_args,
)
if not check_mode:

View File

@@ -1,9 +1,4 @@
# slow - 11min
slow
time=334
time=100
helm_info
helm_plugin
helm_plugin_info
helm_repository
helm_template
helm_pull

View File

@@ -14,20 +14,13 @@ chart_test_values:
revisionHistoryLimit: 0
myValue: "changed"
default_kubeconfig_path: "~/.kube/config"
test_namespace:
- "helm-diff"
- "helm-envvars"
- "helm-test-crds"
- "helm-uninstall"
- "helm-not-installed"
- "helm-crd"
- "helm-url"
- "helm-repository"
- "helm-read-envvars"
- "helm-dep-update"
- "helm-local-path-001"
- "helm-local-path-002"
- "helm-local-path-003"
- "helm-dep"
- "helm-in-memory-kubeconfig"
- "helm-kubeconfig-with-insecure-skip-tls-verify"
- "helm-kubeconfig-with-ca-cert"
- "helm-from-repository"
- "helm-from-url"

View File

@@ -10,14 +10,12 @@
include_tasks: test_helm_not_installed.yml
- name: "Install {{ helm_version }}"
include_tasks: install.yml
include_role:
name: install_helm
- name: "Ensure we honor the environment variables"
include_tasks: test_read_envvars.yml
- name: tests_repository
include_tasks: tests_repository.yml
- name: Deploy charts
include_tasks: "tests_chart/{{ test_chart_type }}.yml"
loop_control:
@@ -30,12 +28,6 @@
- name: test helm dependency update
include_tasks: test_up_dep.yml
- name: Test helm plugin
include_tasks: tests_helm_plugin.yml
- name: Test helm diff
include_tasks: tests_helm_diff.yml
- name: Test helm uninstall
include_tasks: test_helm_uninstall.yml
@@ -43,12 +35,6 @@
- name: Test Skip CRDS feature in helm chart install
include_tasks: test_crds.yml
- name: Test helm modules with custom kube config, validate_certs and/or ca_cert
include_tasks: tests_helm_kubeconfig.yml
- name: Test helm pull
include_tasks: tests_helm_pull.yml
- name: Clean helm install
file:
path: "{{ item }}"

View File

@@ -2,11 +2,12 @@
- name: Test CRDs
vars:
test_chart: "test-crds"
helm_namespace: "{{ test_namespace[0] }}"
block:
- name: Create namespace
k8s:
kind: Namespace
name: "{{ test_namespace[4] }}"
name: "{{ helm_namespace }}"
- name: Copy test chart
copy:
@@ -17,7 +18,7 @@
helm:
binary_path: "{{ helm_binary }}"
chart_ref: "/tmp/helm_test_crds/{{ test_chart }}"
namespace: "{{ test_namespace[4] }}"
namespace: "{{ helm_namespace }}"
name: test-crds
skip_crds: true
register: install
@@ -33,7 +34,7 @@
apiVersion: ansible.com/v1
kind: Foo
metadata:
namespace: "{{ test_namespace[4] }}"
namespace: "{{ helm_namespace }}"
name: test-foo
foobar: footest
ignore_errors: true
@@ -48,7 +49,7 @@
- name: Uninstall chart
helm:
binary_path: "{{ helm_binary }}"
namespace: "{{ test_namespace[4] }}"
namespace: "{{ helm_namespace }}"
name: test-crds
state: absent
@@ -56,7 +57,7 @@
helm:
binary_path: "{{ helm_binary }}"
chart_ref: "/tmp/helm_test_crds/{{ test_chart }}"
namespace: "{{ test_namespace[4] }}"
namespace: "{{ helm_namespace }}"
name: test-crds
- name: Create custom resource
@@ -65,7 +66,7 @@
apiVersion: ansible.com/v1
kind: Foo
metadata:
namespace: "{{ test_namespace[4] }}"
namespace: "{{ helm_namespace }}"
name: test-foo
foobar: footest
register: result
@@ -85,7 +86,7 @@
- name: Remove namespace
k8s:
kind: Namespace
name: "{{ test_namespace[4] }}"
name: "{{ helm_namespace }}"
state: absent
ignore_errors: true

View File

@@ -4,7 +4,7 @@
binary_path: "{{ helm_binary}}_fake"
name: test
chart_ref: "{{ chart_test }}"
namespace: "{{ test_namespace[3] }}"
namespace: "helm-test"
ignore_errors: yes
register: helm_missing_binary

View File

@@ -4,11 +4,11 @@
version: "3.7.0"
register: test_version
- block:
- set_fact:
chart_source: "https://github.com/kubernetes/kube-state-metrics/releases/download/kube-state-metrics-helm-chart-2.13.3/kube-state-metrics-2.13.3.tgz"
chart_name: "test-wait-uninstall"
helm_namespace: "{{ test_namespace[2] }}"
- vars:
chart_source: "https://github.com/kubernetes/kube-state-metrics/releases/download/kube-state-metrics-helm-chart-2.13.3/kube-state-metrics-2.13.3.tgz"
chart_name: "test-wait-uninstall"
helm_namespace: "{{ test_namespace[1] }}"
block:
- name: Install chart
helm:

View File

@@ -3,8 +3,10 @@
binary_path: "{{ helm_binary }}"
state: absent
name: does-not-exist
namespace: "{{ test_namespace[1] }}"
namespace: "{{ helm_namespace }}"
environment:
K8S_AUTH_HOST: somewhere
vars:
helm_namespace: "{{ test_namespace[2] }}"
register: _helm_result
failed_when: '"http://somewhere/version" not in _helm_result.stderr'

View File

@@ -1,5 +1,7 @@
# Helm module
- name: "Test dependency update for helm module"
vars:
helm_namespace: "{{ test_namespace[3] }}"
block:
- name: copy chart
copy:
@@ -9,9 +11,6 @@
- test-chart
- dep-up
- set_fact:
helm_namespace: "{{ test_namespace[10] }}"
- name: "Test chart with dependency_update false"
helm:
binary_path: "{{ helm_binary }}"
@@ -81,8 +80,6 @@
kind: Namespace
name: "{{ helm_namespace }}"
state: absent
wait: true
wait_timeout: 180
- name: "Remove charts"
file:
@@ -153,14 +150,6 @@
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:

View File

@@ -23,7 +23,7 @@
chart_test_version: "{{ chart_test_version_local_path }}"
chart_test_version_upgrade: "{{ chart_test_version_upgrade_local_path }}"
chart_name: "local-path-001"
helm_namespace: "{{ test_namespace[7] }}"
helm_namespace: "{{ test_namespace[4] }}"
- name: Test appVersion idempotence
vars:
@@ -69,7 +69,7 @@
chart_source: "/tmp/helm_test_appversion/test-chart/{{ chart_test }}-{{ chart_test_app_version }}-{{ chart_test_version }}.tgz"
chart_source_upgrade: "/tmp/helm_test_appversion/test-chart/{{ chart_test }}-{{ chart_test_upgrade_app_version }}-{{ chart_test_version_upgrade }}.tgz"
chart_name: "local-path-002"
helm_namespace: "{{ test_namespace[8] }}"
helm_namespace: "{{ test_namespace[5] }}"
- name: Test appVersion handling when null
vars:
@@ -99,7 +99,7 @@
chart_source: "/tmp/helm_test_appversion/test-null/{{ chart_test }}/"
chart_source_upgrade: "{{ chart_test }}-{{ chart_test_version_upgrade }}.tgz"
chart_name: "local-path-003"
helm_namespace: "{{ test_namespace[9] }}"
helm_namespace: "{{ test_namespace[6] }}"
- name: Remove clone repos
file:

View File

@@ -12,7 +12,7 @@
chart_source: "test_helm/{{ chart_test }}"
chart_source_version: "{{ chart_test_version }}"
chart_source_version_upgrade: "{{ chart_test_version_upgrade }}"
helm_namespace: "{{ test_namespace[6] }}"
helm_namespace: "{{ test_namespace[7] }}"
- name: Remove chart repo
helm_repository:

View File

@@ -5,4 +5,4 @@
source: url
chart_source: "https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-{{ chart_test_version }}/{{ chart_test }}-{{ chart_test_version }}.tgz"
chart_source_upgrade: "https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-{{ chart_test_version_upgrade }}/{{ chart_test }}-{{ chart_test_version_upgrade }}.tgz"
helm_namespace: "{{ test_namespace[5] }}"
helm_namespace: "{{ test_namespace[8] }}"

View File

@@ -0,0 +1,3 @@
time=40
helm_plugin
helm

View File

@@ -0,0 +1,3 @@
---
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
helm_namespace: helm-diff

View File

@@ -0,0 +1,6 @@
apiVersion: v2
name: test-chart
description: A chart used in molecule tests
type: application
version: 0.1.0
appVersion: "default"

View File

@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: test-chart-configmap
data:
myValue: {{ default "test" .Values.myValue }}

View File

@@ -0,0 +1,4 @@
---
dependencies:
- remove_namespace
- install_helm

View File

@@ -5,8 +5,6 @@
redis_chart_version: '17.0.5'
block:
- set_fact:
helm_namespace: "{{ test_namespace[0] }}"
- name: Install helm diff
helm_plugin:

View File

@@ -0,0 +1,2 @@
time=40
helm

View File

@@ -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"

View File

@@ -0,0 +1,3 @@
---
dependencies:
- remove_namespace

View File

@@ -3,7 +3,7 @@
custom_config: "{{ lookup('file', default_kubeconfig_path | expanduser) | from_yaml }}"
- name: Test helm modules using in-memory kubeconfig
include_tasks: "../tests_helm_auth.yml"
include_tasks: "tests_helm_auth.yml"
vars:
test_kubeconfig: "{{ custom_config }}"
helm_namespace: "{{ test_namespace[11] }}"
helm_namespace: "{{ test_namespace[0] }}"

View File

@@ -60,13 +60,13 @@
- '"Error: Kubernetes cluster unreachable" in _install.msg'
- name: Test helm modules using in-memory kubeconfig
include_tasks: "../tests_helm_auth.yml"
include_tasks: "tests_helm_auth.yml"
vars:
test_kubeconfig: "{{ tfile.path }}"
test_ca_cert: "{{ ca_file.path }}"
vars:
helm_namespace: "{{ test_namespace[13] }}"
helm_namespace: "{{ test_namespace[1] }}"
always:
- name: Delete temporary file

View File

@@ -51,13 +51,13 @@
- '"Error: Kubernetes cluster unreachable" in _install.msg'
- name: Test helm modules using in-memory kubeconfig
include_tasks: "../tests_helm_auth.yml"
include_tasks: "tests_helm_auth.yml"
vars:
test_kubeconfig: "{{ tfile.path }}"
test_validate_certs: false
vars:
helm_namespace: "{{ test_namespace[12] }}"
helm_namespace: "{{ test_namespace[2] }}"
always:
- name: Delete temporary file

View File

@@ -1,9 +1,9 @@
---
- name: Test helm with in-memory kubeconfig
include_tasks: "tests_kubeconfig/from_in_memory_kubeconfig.yml"
include_tasks: "from_in_memory_kubeconfig.yml"
- name: Test helm with custom kubeconfig and validate_certs=false
include_tasks: "tests_kubeconfig/from_kubeconfig_with_validate_certs.yml"
include_tasks: "from_kubeconfig_with_validate_certs.yml"
loop_control:
loop_var: test_helm_version
with_items:
@@ -11,12 +11,9 @@
- "v3.8.2"
- name: Test helm with custom kubeconfig and ca_cert
include_tasks: "tests_kubeconfig/from_kubeconfig_with_cacert.yml"
include_tasks: "from_kubeconfig_with_cacert.yml"
loop_control:
loop_var: test_helm_version
with_items:
- "v3.5.1"
- "v3.4.2"
- name: install default helm archive version
include_tasks: install.yml

View File

@@ -8,9 +8,10 @@
- name: Install helm binary
block:
- name: "Install {{ test_helm_version }}"
include_tasks: install.yml
include_role:
name: install_helm
vars:
helm_archive_name: "helm-{{ test_helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"
helm_version: "{{ test_helm_version }}"
when: test_helm_version is defined

View File

@@ -0,0 +1,3 @@
time=30
helm_plugin
helm_plugin_info

View File

@@ -0,0 +1,2 @@
---
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"

View File

@@ -0,0 +1,3 @@
---
dependencies:
- install_helm

View File

@@ -0,0 +1,2 @@
time=27
helm_pull

View File

@@ -36,7 +36,7 @@
# Testing helm pull with helm version == 2.3.0
- block:
- name: Assert that helm pull failed with helm <= 3.0.0
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -55,7 +55,7 @@
# Testing helm pull with helm version == 3.0.0
- block:
- name: Download chart using chart_ssl_cert_file
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -71,7 +71,7 @@
- _result.msg == "Parameter chart_ssl_cert_file requires helm >= 3.1.0, current version is 3.0.0"
- name: Download chart using chart_ssl_key_file
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -87,7 +87,7 @@
- _result.msg == "Parameter chart_ssl_key_file requires helm >= 3.1.0, current version is 3.0.0"
- name: Download chart using chart_ca_cert
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -108,7 +108,7 @@
# Testing helm pull with helm version == 3.1.0
- block:
- name: Download chart using chart_ssl_cert_file, chart_ca_cert, chart_ssl_key_file
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -127,7 +127,7 @@
- '"--key-file ssl_key_file" in _result.command'
- name: Download chart using skip_tls_certs_check
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -150,7 +150,7 @@
# Test options chart_version, verify, pass-credentials, provenance, untar_chart
# skip_tls_certs_check, repo_url, repo_username, repo_password
- name: Testing chart version
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: redis
destination: "{{ destination }}"
@@ -182,7 +182,7 @@
- '"--keyring pubring.gpg" in _result.command'
- name: Download chart using chart_ref
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
destination: "{{ destination }}"
@@ -201,7 +201,7 @@
- _chart.stat.isreg
- name: Download chart using untar_chart
kubernetes.core.helm_pull:
helm_pull:
binary_path: "{{ helm_path }}"
chart_ref: redis
destination: "{{ destination }}"

View File

@@ -0,0 +1,5 @@
time=20
helm_repository
helm_info
helm
helm_template

View File

@@ -0,0 +1,3 @@
---
chart_test_repo: "https://kubernetes.github.io/ingress-nginx"
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"

View File

@@ -0,0 +1,3 @@
---
dependencies:
- install_helm

View File

@@ -0,0 +1,3 @@
time=40
helm
helm_info

View File

@@ -0,0 +1,3 @@
---
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
helm_namespace: helm-set-values

View File

@@ -0,0 +1,3 @@
---
dependencies:
- remove_namespace

View File

@@ -0,0 +1,109 @@
- name: Install helm using set_values parameters
helm:
binary_path: "{{ helm_binary }}"
chart_ref: mariadb
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-mariadb
release_namespace: "{{ helm_namespace }}"
create_namespace: true
set_values:
- value: phase=integration
value_type: string
- value: versioned=false
- name: Get value set as string
helm_info:
binary_path: "{{ helm_binary }}"
release_name: test-mariadb
release_namespace: "{{ helm_namespace }}"
register: user_values
- name: Assert that release was created with user-defined variables
assert:
that:
- '"phase" in user_values.status["values"]'
- '"versioned" in user_values.status["values"]'
- user_values.status["values"]["phase"] == "integration"
- user_values.status["values"]["versioned"] is false
# install chart using set_values and release_values
- name: Install helm binary (> 3.10.0) requires to use set-json
include_role:
name: install_helm
vars:
helm_version: "v3.10.3"
- name: Install helm using set_values parameters
helm:
binary_path: "{{ helm_binary }}"
chart_ref: apache
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-apache
release_namespace: "{{ helm_namespace }}"
create_namespace: true
set_values:
- value: 'master.image={"registry": "docker.io", "repository": "bitnami/apache", "tag": "2.4.54-debian-11-r74"}'
value_type: json
release_values:
replicaCount: 3
- name: Get release info
helm_info:
binary_path: "{{ helm_binary }}"
release_name: test-apache
release_namespace: "{{ helm_namespace }}"
register: values
- name: Assert that release was created with user-defined variables
assert:
that:
- values.status["values"].replicaCount == 3
- values.status["values"].master.image.registry == "docker.io"
- values.status["values"].master.image.repository == "bitnami/apache"
- values.status["values"].master.image.tag == "2.4.54-debian-11-r74"
# install chart using set_values and values_files
- name: create temporary file to save values in
tempfile:
suffix: .yml
register: ymlfile
- block:
- name: copy content into values file
copy:
content: |
---
mode: distributed
dest: "{{ ymlfile.path }}"
- name: Install helm using set_values parameters
helm:
binary_path: "{{ helm_binary }}"
chart_ref: minio
chart_repo_url: https://charts.bitnami.com/bitnami
release_name: test-minio
release_namespace: "{{ helm_namespace }}"
create_namespace: true
set_values:
- value: 'disableWebUI=true'
values_files:
- "{{ ymlfile.path }}"
- name: Get release info
helm_info:
binary_path: "{{ helm_binary }}"
release_name: test-minio
release_namespace: "{{ helm_namespace }}"
register: values
- name: Assert that release was created with user-defined variables
assert:
that:
- values.status["values"].mode == "distributed"
- values.status["values"].disableWebUI is true
always:
- name: Delete temporary file
file:
state: absent
path: "{{ ymlfile.path }}"

View File

@@ -0,0 +1 @@
disabled

View File

@@ -0,0 +1,4 @@
---
helm_version: v3.7.0
helm_install_path: /tmp/helm
helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"

View File

@@ -0,0 +1,15 @@
---
- name: Init Helm folders
file:
path: "{{ helm_install_path }}"
state: directory
- name: Unarchive Helm binary
unarchive:
src: "https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}"
dest: "{{ helm_install_path }}"
remote_src: yes
retries: 10
delay: 5
register: result
until: result is not failed

View File

@@ -17,6 +17,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/doc_fragments/k8s_name_options.py future-import-boilerplate!skip

View File

@@ -20,6 +20,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/modules/k8s.py validate-modules:return-syntax-error

View File

@@ -23,6 +23,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/modules/k8s.py validate-modules:return-syntax-error

View File

@@ -23,6 +23,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/modules/k8s.py validate-modules:return-syntax-error

View File

@@ -23,6 +23,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/modules/k8s.py validate-modules:return-syntax-error

View File

@@ -26,6 +26,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/modules/k8s.py validate-modules:return-syntax-error

View File

@@ -14,6 +14,7 @@ tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
tests/sanity/refresh_ignore_files shebang!skip
plugins/doc_fragments/k8s_name_options.py future-import-boilerplate!skip

View File

@@ -46,6 +46,7 @@ YAML_LINT_SKIPS = [
"tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml",
"tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml",
"tests/integration/targets/helm/files/test-chart/templates/configmap.yaml",
"tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml",
"tests/integration/targets/k8s_scale/files/deployment.yaml",
]

View File

@@ -415,3 +415,40 @@ def test_module_prepare_helm_environment_with_ca_cert(helm_version, is_env_var_s
print(json.dumps(content, indent=2))
assert content["clusters"][0]["cluster"]["certificate-authority"] == ca_cert
os.remove(kubeconfig_path)
@pytest.mark.parametrize(
"set_values, expected",
[
([{"value": "test"}], ["--set test"]),
([{"value_type": "raw", "value": "test"}], ["--set test"]),
(
[{"value_type": "string", "value": "string_value"}],
["--set-string 'string_value'"],
),
([{"value_type": "file", "value": "file_path"}], ["--set-file 'file_path'"]),
(
[{"value_type": "json", "value": '{"a": 1, "b": "some_value"}'}],
['--set-json \'{"a": 1, "b": "some_value"}\''],
),
(
[
{"value_type": "string", "value": "string_value"},
{"value_type": "file", "value": "file_path"},
],
["--set-string 'string_value'", "--set-file 'file_path'"],
),
],
)
def test_module_get_helm_set_values_args(set_values, expected):
module = MagicMock()
module.params = {}
module.fail_json.side_effect = SystemExit(1)
helm_module = AnsibleHelmModule(module=module)
helm_module.get_helm_version = MagicMock()
helm_module.get_helm_version.return_value = "3.10.1"
result = helm_module.get_helm_set_values_args(set_values)
assert " ".join(expected) == result