From af7c24cba7435bb78d625110aae98ad29d7b81b9 Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:19:42 +0100 Subject: [PATCH] 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 Reviewed-by: Bikouo Aubin Reviewed-by: Mike Graves --- ...m-install-add-support-for-set-options.yaml | 5 + plugins/module_utils/helm.py | 71 ++++++++++++ plugins/modules/helm.py | 50 ++++++++ plugins/modules/helm_info.py | 20 ++++ plugins/modules/helm_template.py | 36 ++++++ tests/integration/targets/helm/aliases | 7 +- .../targets/helm/defaults/main.yml | 17 +-- .../targets/helm/tasks/run_test.yml | 18 +-- .../targets/helm/tasks/test_crds.yml | 15 +-- .../helm/tasks/test_helm_not_installed.yml | 2 +- .../helm/tasks/test_helm_uninstall.yml | 10 +- .../targets/helm/tasks/test_read_envvars.yml | 4 +- .../targets/helm/tasks/test_up_dep.yml | 15 +-- .../tasks/tests_chart/from_local_path.yml | 6 +- .../tasks/tests_chart/from_repository.yml | 2 +- .../helm/tasks/tests_chart/from_url.yml | 2 +- tests/integration/targets/helm_diff/aliases | 3 + .../targets/helm_diff/defaults/main.yml | 3 + .../helm_diff/files/test-chart/Chart.yaml | 6 + .../files/test-chart/templates/configmap.yaml | 6 + .../targets/helm_diff/meta/main.yml | 4 + .../tasks/main.yml} | 2 - .../targets/helm_kubeconfig/aliases | 2 + .../targets/helm_kubeconfig/defaults/main.yml | 7 ++ .../targets/helm_kubeconfig/meta/main.yml | 3 + .../tasks}/from_in_memory_kubeconfig.yml | 4 +- .../tasks}/from_kubeconfig_with_cacert.yml | 4 +- .../from_kubeconfig_with_validate_certs.yml | 4 +- .../tasks/main.yml} | 9 +- .../tasks/tests_helm_auth.yml | 5 +- tests/integration/targets/helm_plugin/aliases | 3 + .../targets/helm_plugin/defaults/main.yml | 2 + .../files/sample_plugin/plugin.yaml | 0 .../targets/helm_plugin/meta/main.yml | 3 + .../tasks/main.yml} | 0 tests/integration/targets/helm_pull/aliases | 2 + .../tasks/main.yml} | 18 +-- .../targets/helm_repository/aliases | 5 + .../targets/helm_repository/defaults/main.yml | 3 + .../targets/helm_repository/meta/main.yml | 3 + .../tasks/main.yml} | 0 .../targets/helm_set_values/aliases | 3 + .../targets/helm_set_values/defaults/main.yml | 3 + .../targets/helm_set_values/meta/main.yml | 3 + .../targets/helm_set_values/tasks/main.yml | 109 ++++++++++++++++++ .../integration/targets/install_helm/aliases | 1 + .../targets/install_helm/defaults/main.yml | 4 + .../targets/install_helm/tasks/main.yml | 15 +++ tests/sanity/ignore-2.10.txt | 1 + tests/sanity/ignore-2.11.txt | 1 + tests/sanity/ignore-2.12.txt | 1 + tests/sanity/ignore-2.13.txt | 1 + tests/sanity/ignore-2.14.txt | 1 + tests/sanity/ignore-2.15.txt | 1 + tests/sanity/ignore-2.9.txt | 1 + tests/sanity/refresh_ignore_files | 1 + tests/unit/module_utils/test_helm.py | 37 ++++++ 57 files changed, 473 insertions(+), 91 deletions(-) create mode 100644 changelogs/fragments/546-helm-install-add-support-for-set-options.yaml create mode 100644 tests/integration/targets/helm_diff/aliases create mode 100644 tests/integration/targets/helm_diff/defaults/main.yml create mode 100644 tests/integration/targets/helm_diff/files/test-chart/Chart.yaml create mode 100644 tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml create mode 100644 tests/integration/targets/helm_diff/meta/main.yml rename tests/integration/targets/{helm/tasks/tests_helm_diff.yml => helm_diff/tasks/main.yml} (99%) create mode 100644 tests/integration/targets/helm_kubeconfig/aliases create mode 100644 tests/integration/targets/helm_kubeconfig/defaults/main.yml create mode 100644 tests/integration/targets/helm_kubeconfig/meta/main.yml rename tests/integration/targets/{helm/tasks/tests_kubeconfig => helm_kubeconfig/tasks}/from_in_memory_kubeconfig.yml (70%) rename tests/integration/targets/{helm/tasks/tests_kubeconfig => helm_kubeconfig/tasks}/from_kubeconfig_with_cacert.yml (95%) rename tests/integration/targets/{helm/tasks/tests_kubeconfig => helm_kubeconfig/tasks}/from_kubeconfig_with_validate_certs.yml (95%) rename tests/integration/targets/{helm/tasks/tests_helm_kubeconfig.yml => helm_kubeconfig/tasks/main.yml} (55%) rename tests/integration/targets/{helm => helm_kubeconfig}/tasks/tests_helm_auth.yml (97%) create mode 100644 tests/integration/targets/helm_plugin/aliases create mode 100644 tests/integration/targets/helm_plugin/defaults/main.yml rename tests/integration/targets/{helm => helm_plugin}/files/sample_plugin/plugin.yaml (100%) create mode 100644 tests/integration/targets/helm_plugin/meta/main.yml rename tests/integration/targets/{helm/tasks/tests_helm_plugin.yml => helm_plugin/tasks/main.yml} (100%) create mode 100644 tests/integration/targets/helm_pull/aliases rename tests/integration/targets/{helm/tasks/tests_helm_pull.yml => helm_pull/tasks/main.yml} (95%) create mode 100644 tests/integration/targets/helm_repository/aliases create mode 100644 tests/integration/targets/helm_repository/defaults/main.yml create mode 100644 tests/integration/targets/helm_repository/meta/main.yml rename tests/integration/targets/{helm/tasks/tests_repository.yml => helm_repository/tasks/main.yml} (100%) create mode 100644 tests/integration/targets/helm_set_values/aliases create mode 100644 tests/integration/targets/helm_set_values/defaults/main.yml create mode 100644 tests/integration/targets/helm_set_values/meta/main.yml create mode 100644 tests/integration/targets/helm_set_values/tasks/main.yml create mode 100644 tests/integration/targets/install_helm/aliases create mode 100644 tests/integration/targets/install_helm/defaults/main.yml create mode 100644 tests/integration/targets/install_helm/tasks/main.yml diff --git a/changelogs/fragments/546-helm-install-add-support-for-set-options.yaml b/changelogs/fragments/546-helm-install-add-support-for-set-options.yaml new file mode 100644 index 00000000..ac266843 --- /dev/null +++ b/changelogs/fragments/546-helm-install-add-support-for-set-options.yaml @@ -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). diff --git a/plugins/module_utils/helm.py b/plugins/module_utils/helm.py index 58c75ffb..a7a2fa7c 100644 --- a/plugins/module_utils/helm.py +++ b/plugins/module_utils/helm.py @@ -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) diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index eabe7a8a..9b2ed386 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -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 diff --git a/plugins/modules/helm_info.py b/plugins/modules/helm_info.py index 77fa1ba8..aefd4477 100644 --- a/plugins/modules/helm_info.py +++ b/plugins/modules/helm_info.py @@ -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 diff --git a/plugins/modules/helm_template.py b/plugins/modules/helm_template.py index e8476dd0..ab50f871 100644 --- a/plugins/modules/helm_template.py +++ b/plugins/modules/helm_template.py @@ -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: diff --git a/tests/integration/targets/helm/aliases b/tests/integration/targets/helm/aliases index 32f65d5f..fdc6dfc7 100644 --- a/tests/integration/targets/helm/aliases +++ b/tests/integration/targets/helm/aliases @@ -1,9 +1,4 @@ -# slow - 11min -slow -time=334 +time=100 helm_info -helm_plugin -helm_plugin_info helm_repository helm_template -helm_pull diff --git a/tests/integration/targets/helm/defaults/main.yml b/tests/integration/targets/helm/defaults/main.yml index ffff2e44..ae860ce8 100644 --- a/tests/integration/targets/helm/defaults/main.yml +++ b/tests/integration/targets/helm/defaults/main.yml @@ -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" diff --git a/tests/integration/targets/helm/tasks/run_test.yml b/tests/integration/targets/helm/tasks/run_test.yml index f54d58ec..545b25c8 100644 --- a/tests/integration/targets/helm/tasks/run_test.yml +++ b/tests/integration/targets/helm/tasks/run_test.yml @@ -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 }}" diff --git a/tests/integration/targets/helm/tasks/test_crds.yml b/tests/integration/targets/helm/tasks/test_crds.yml index 45637ce7..0534869b 100644 --- a/tests/integration/targets/helm/tasks/test_crds.yml +++ b/tests/integration/targets/helm/tasks/test_crds.yml @@ -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 diff --git a/tests/integration/targets/helm/tasks/test_helm_not_installed.yml b/tests/integration/targets/helm/tasks/test_helm_not_installed.yml index e683fc09..2f2fd27e 100644 --- a/tests/integration/targets/helm/tasks/test_helm_not_installed.yml +++ b/tests/integration/targets/helm/tasks/test_helm_not_installed.yml @@ -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 diff --git a/tests/integration/targets/helm/tasks/test_helm_uninstall.yml b/tests/integration/targets/helm/tasks/test_helm_uninstall.yml index b8c1653b..e82891e4 100644 --- a/tests/integration/targets/helm/tasks/test_helm_uninstall.yml +++ b/tests/integration/targets/helm/tasks/test_helm_uninstall.yml @@ -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: diff --git a/tests/integration/targets/helm/tasks/test_read_envvars.yml b/tests/integration/targets/helm/tasks/test_read_envvars.yml index 379b28ed..09c0d355 100644 --- a/tests/integration/targets/helm/tasks/test_read_envvars.yml +++ b/tests/integration/targets/helm/tasks/test_read_envvars.yml @@ -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' diff --git a/tests/integration/targets/helm/tasks/test_up_dep.yml b/tests/integration/targets/helm/tasks/test_up_dep.yml index 6ae49f3f..39a14460 100644 --- a/tests/integration/targets/helm/tasks/test_up_dep.yml +++ b/tests/integration/targets/helm/tasks/test_up_dep.yml @@ -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: diff --git a/tests/integration/targets/helm/tasks/tests_chart/from_local_path.yml b/tests/integration/targets/helm/tasks/tests_chart/from_local_path.yml index f29b3e2c..db3058e2 100644 --- a/tests/integration/targets/helm/tasks/tests_chart/from_local_path.yml +++ b/tests/integration/targets/helm/tasks/tests_chart/from_local_path.yml @@ -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: diff --git a/tests/integration/targets/helm/tasks/tests_chart/from_repository.yml b/tests/integration/targets/helm/tasks/tests_chart/from_repository.yml index d00599a6..0d8bae4f 100644 --- a/tests/integration/targets/helm/tasks/tests_chart/from_repository.yml +++ b/tests/integration/targets/helm/tasks/tests_chart/from_repository.yml @@ -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: diff --git a/tests/integration/targets/helm/tasks/tests_chart/from_url.yml b/tests/integration/targets/helm/tasks/tests_chart/from_url.yml index 0d4922eb..fdd839d3 100644 --- a/tests/integration/targets/helm/tasks/tests_chart/from_url.yml +++ b/tests/integration/targets/helm/tasks/tests_chart/from_url.yml @@ -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] }}" diff --git a/tests/integration/targets/helm_diff/aliases b/tests/integration/targets/helm_diff/aliases new file mode 100644 index 00000000..f85ad0c8 --- /dev/null +++ b/tests/integration/targets/helm_diff/aliases @@ -0,0 +1,3 @@ +time=40 +helm_plugin +helm \ No newline at end of file diff --git a/tests/integration/targets/helm_diff/defaults/main.yml b/tests/integration/targets/helm_diff/defaults/main.yml new file mode 100644 index 00000000..6c2a691f --- /dev/null +++ b/tests/integration/targets/helm_diff/defaults/main.yml @@ -0,0 +1,3 @@ +--- +helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" +helm_namespace: helm-diff diff --git a/tests/integration/targets/helm_diff/files/test-chart/Chart.yaml b/tests/integration/targets/helm_diff/files/test-chart/Chart.yaml new file mode 100644 index 00000000..5d09a08c --- /dev/null +++ b/tests/integration/targets/helm_diff/files/test-chart/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: test-chart +description: A chart used in molecule tests +type: application +version: 0.1.0 +appVersion: "default" diff --git a/tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml b/tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml new file mode 100644 index 00000000..7ef9931d --- /dev/null +++ b/tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-chart-configmap +data: + myValue: {{ default "test" .Values.myValue }} diff --git a/tests/integration/targets/helm_diff/meta/main.yml b/tests/integration/targets/helm_diff/meta/main.yml new file mode 100644 index 00000000..10d989e7 --- /dev/null +++ b/tests/integration/targets/helm_diff/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - remove_namespace + - install_helm diff --git a/tests/integration/targets/helm/tasks/tests_helm_diff.yml b/tests/integration/targets/helm_diff/tasks/main.yml similarity index 99% rename from tests/integration/targets/helm/tasks/tests_helm_diff.yml rename to tests/integration/targets/helm_diff/tasks/main.yml index 3a3c91f7..d54d0ba7 100644 --- a/tests/integration/targets/helm/tasks/tests_helm_diff.yml +++ b/tests/integration/targets/helm_diff/tasks/main.yml @@ -5,8 +5,6 @@ redis_chart_version: '17.0.5' block: - - set_fact: - helm_namespace: "{{ test_namespace[0] }}" - name: Install helm diff helm_plugin: diff --git a/tests/integration/targets/helm_kubeconfig/aliases b/tests/integration/targets/helm_kubeconfig/aliases new file mode 100644 index 00000000..5f429d06 --- /dev/null +++ b/tests/integration/targets/helm_kubeconfig/aliases @@ -0,0 +1,2 @@ +time=40 +helm \ No newline at end of file diff --git a/tests/integration/targets/helm_kubeconfig/defaults/main.yml b/tests/integration/targets/helm_kubeconfig/defaults/main.yml new file mode 100644 index 00000000..0e30cb94 --- /dev/null +++ b/tests/integration/targets/helm_kubeconfig/defaults/main.yml @@ -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" diff --git a/tests/integration/targets/helm_kubeconfig/meta/main.yml b/tests/integration/targets/helm_kubeconfig/meta/main.yml new file mode 100644 index 00000000..2e3ba2fa --- /dev/null +++ b/tests/integration/targets/helm_kubeconfig/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - remove_namespace diff --git a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_in_memory_kubeconfig.yml b/tests/integration/targets/helm_kubeconfig/tasks/from_in_memory_kubeconfig.yml similarity index 70% rename from tests/integration/targets/helm/tasks/tests_kubeconfig/from_in_memory_kubeconfig.yml rename to tests/integration/targets/helm_kubeconfig/tasks/from_in_memory_kubeconfig.yml index 5b242145..aebd69c4 100644 --- a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_in_memory_kubeconfig.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/from_in_memory_kubeconfig.yml @@ -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] }}" diff --git a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_cacert.yml b/tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_cacert.yml similarity index 95% rename from tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_cacert.yml rename to tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_cacert.yml index 9dddfb16..0af0030a 100644 --- a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_cacert.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_cacert.yml @@ -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 diff --git a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_validate_certs.yml b/tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_validate_certs.yml similarity index 95% rename from tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_validate_certs.yml rename to tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_validate_certs.yml index 0a15a42d..73c02a27 100644 --- a/tests/integration/targets/helm/tasks/tests_kubeconfig/from_kubeconfig_with_validate_certs.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/from_kubeconfig_with_validate_certs.yml @@ -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 diff --git a/tests/integration/targets/helm/tasks/tests_helm_kubeconfig.yml b/tests/integration/targets/helm_kubeconfig/tasks/main.yml similarity index 55% rename from tests/integration/targets/helm/tasks/tests_helm_kubeconfig.yml rename to tests/integration/targets/helm_kubeconfig/tasks/main.yml index 5da2ce44..244f1bdf 100644 --- a/tests/integration/targets/helm/tasks/tests_helm_kubeconfig.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/main.yml @@ -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 diff --git a/tests/integration/targets/helm/tasks/tests_helm_auth.yml b/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml similarity index 97% rename from tests/integration/targets/helm/tasks/tests_helm_auth.yml rename to tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml index 63b252ff..8599b66a 100644 --- a/tests/integration/targets/helm/tasks/tests_helm_auth.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml @@ -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 diff --git a/tests/integration/targets/helm_plugin/aliases b/tests/integration/targets/helm_plugin/aliases new file mode 100644 index 00000000..babf73f4 --- /dev/null +++ b/tests/integration/targets/helm_plugin/aliases @@ -0,0 +1,3 @@ +time=30 +helm_plugin +helm_plugin_info \ No newline at end of file diff --git a/tests/integration/targets/helm_plugin/defaults/main.yml b/tests/integration/targets/helm_plugin/defaults/main.yml new file mode 100644 index 00000000..60d628d5 --- /dev/null +++ b/tests/integration/targets/helm_plugin/defaults/main.yml @@ -0,0 +1,2 @@ +--- +helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" diff --git a/tests/integration/targets/helm/files/sample_plugin/plugin.yaml b/tests/integration/targets/helm_plugin/files/sample_plugin/plugin.yaml similarity index 100% rename from tests/integration/targets/helm/files/sample_plugin/plugin.yaml rename to tests/integration/targets/helm_plugin/files/sample_plugin/plugin.yaml diff --git a/tests/integration/targets/helm_plugin/meta/main.yml b/tests/integration/targets/helm_plugin/meta/main.yml new file mode 100644 index 00000000..cf4590de --- /dev/null +++ b/tests/integration/targets/helm_plugin/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - install_helm diff --git a/tests/integration/targets/helm/tasks/tests_helm_plugin.yml b/tests/integration/targets/helm_plugin/tasks/main.yml similarity index 100% rename from tests/integration/targets/helm/tasks/tests_helm_plugin.yml rename to tests/integration/targets/helm_plugin/tasks/main.yml diff --git a/tests/integration/targets/helm_pull/aliases b/tests/integration/targets/helm_pull/aliases new file mode 100644 index 00000000..49fdb76b --- /dev/null +++ b/tests/integration/targets/helm_pull/aliases @@ -0,0 +1,2 @@ +time=27 +helm_pull \ No newline at end of file diff --git a/tests/integration/targets/helm/tasks/tests_helm_pull.yml b/tests/integration/targets/helm_pull/tasks/main.yml similarity index 95% rename from tests/integration/targets/helm/tasks/tests_helm_pull.yml rename to tests/integration/targets/helm_pull/tasks/main.yml index fde934ad..3705c5cb 100644 --- a/tests/integration/targets/helm/tasks/tests_helm_pull.yml +++ b/tests/integration/targets/helm_pull/tasks/main.yml @@ -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 }}" diff --git a/tests/integration/targets/helm_repository/aliases b/tests/integration/targets/helm_repository/aliases new file mode 100644 index 00000000..eb25b7b3 --- /dev/null +++ b/tests/integration/targets/helm_repository/aliases @@ -0,0 +1,5 @@ +time=20 +helm_repository +helm_info +helm +helm_template \ No newline at end of file diff --git a/tests/integration/targets/helm_repository/defaults/main.yml b/tests/integration/targets/helm_repository/defaults/main.yml new file mode 100644 index 00000000..5b60b517 --- /dev/null +++ b/tests/integration/targets/helm_repository/defaults/main.yml @@ -0,0 +1,3 @@ +--- +chart_test_repo: "https://kubernetes.github.io/ingress-nginx" +helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" diff --git a/tests/integration/targets/helm_repository/meta/main.yml b/tests/integration/targets/helm_repository/meta/main.yml new file mode 100644 index 00000000..cf4590de --- /dev/null +++ b/tests/integration/targets/helm_repository/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - install_helm diff --git a/tests/integration/targets/helm/tasks/tests_repository.yml b/tests/integration/targets/helm_repository/tasks/main.yml similarity index 100% rename from tests/integration/targets/helm/tasks/tests_repository.yml rename to tests/integration/targets/helm_repository/tasks/main.yml diff --git a/tests/integration/targets/helm_set_values/aliases b/tests/integration/targets/helm_set_values/aliases new file mode 100644 index 00000000..c042c5b4 --- /dev/null +++ b/tests/integration/targets/helm_set_values/aliases @@ -0,0 +1,3 @@ +time=40 +helm +helm_info \ No newline at end of file diff --git a/tests/integration/targets/helm_set_values/defaults/main.yml b/tests/integration/targets/helm_set_values/defaults/main.yml new file mode 100644 index 00000000..73c5a0bb --- /dev/null +++ b/tests/integration/targets/helm_set_values/defaults/main.yml @@ -0,0 +1,3 @@ +--- +helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" +helm_namespace: helm-set-values diff --git a/tests/integration/targets/helm_set_values/meta/main.yml b/tests/integration/targets/helm_set_values/meta/main.yml new file mode 100644 index 00000000..2e3ba2fa --- /dev/null +++ b/tests/integration/targets/helm_set_values/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - remove_namespace diff --git a/tests/integration/targets/helm_set_values/tasks/main.yml b/tests/integration/targets/helm_set_values/tasks/main.yml new file mode 100644 index 00000000..7ce5125f --- /dev/null +++ b/tests/integration/targets/helm_set_values/tasks/main.yml @@ -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 }}" diff --git a/tests/integration/targets/install_helm/aliases b/tests/integration/targets/install_helm/aliases new file mode 100644 index 00000000..7a68b11d --- /dev/null +++ b/tests/integration/targets/install_helm/aliases @@ -0,0 +1 @@ +disabled diff --git a/tests/integration/targets/install_helm/defaults/main.yml b/tests/integration/targets/install_helm/defaults/main.yml new file mode 100644 index 00000000..0f8c952f --- /dev/null +++ b/tests/integration/targets/install_helm/defaults/main.yml @@ -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" diff --git a/tests/integration/targets/install_helm/tasks/main.yml b/tests/integration/targets/install_helm/tasks/main.yml new file mode 100644 index 00000000..49e36a46 --- /dev/null +++ b/tests/integration/targets/install_helm/tasks/main.yml @@ -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 diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 61bd6825..b617363d 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -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 diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 53b2ef90..80122d80 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -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 diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 8572453e..6cfa02f6 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -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 diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt index 8572453e..6cfa02f6 100644 --- a/tests/sanity/ignore-2.13.txt +++ b/tests/sanity/ignore-2.13.txt @@ -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 diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 8572453e..6cfa02f6 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -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 diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index 58af38eb..95cd652a 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -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 diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index a2b1c858..7828a0c0 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -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 diff --git a/tests/sanity/refresh_ignore_files b/tests/sanity/refresh_ignore_files index 1549124a..bdb01b8c 100644 --- a/tests/sanity/refresh_ignore_files +++ b/tests/sanity/refresh_ignore_files @@ -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", ] diff --git a/tests/unit/module_utils/test_helm.py b/tests/unit/module_utils/test_helm.py index bb8843e5..de2c1569 100644 --- a/tests/unit/module_utils/test_helm.py +++ b/tests/unit/module_utils/test_helm.py @@ -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