diff --git a/.github/workflows/integration-tests-helm.yaml b/.github/workflows/integration-tests-helm.yaml new file mode 100644 index 00000000..0562d59c --- /dev/null +++ b/.github/workflows/integration-tests-helm.yaml @@ -0,0 +1,210 @@ +name: Integration tests Helm + +concurrency: + group: integration-tests-helm-${{ github.head_ref }} + cancel-in-progress: true + +on: + pull_request: + types: + - opened + - reopened + - labeled + - unlabeled + - synchronize + branches: + - main + - stable-* + +permissions: {} + +jobs: + splitter: + env: + source_dir: "./source" + runs-on: ubuntu-latest + outputs: + helm_targets: ${{ steps.select-targets.outputs.targets }} + permissions: + pull-requests: read + contents: read + steps: + - name: Checkout the collection repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: ${{ env.source_dir }} + fetch-depth: "0" + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: list changes for pull request + id: splitter + uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@4678c74a7d712d55e663c88f66eec6d9c3642550 + with: + collections_to_test: ${{ env.source_dir }} + total_jobs: 8 + + - name: Select Helm targets + id: select-targets + run: | + import os, json + with open(os.environ.get('GITHUB_OUTPUT'), "a", encoding="utf-8") as fh: + data = os.environ.get("ALL_TEST_TARGETS") + targets = [] + for target in data.split(";"): + if target and ':' in target: + targets.extend([v for v in target.split(':', maxsplit=1)[1].split(',') if v.startswith('helm')]) + fh.write(f'targets={json.dumps(targets)}\n') + shell: python + env: + ALL_TEST_TARGETS: ${{ steps.splitter.outputs.test_targets }} + + integration: + runs-on: ubuntu-latest + timeout-minutes: 60 + needs: + - splitter + if: ${{ needs.splitter.outputs.helm_targets != '' && needs.splitter.outputs.helm_targets != '[]' }} + env: + source: "./source" + ansible_posix: "./ansible_posix" + community_general: "./community_general" + ansible-version: "milestone" + python-version: "3.13" + permissions: + contents: read + strategy: + fail-fast: false + matrix: + helm-version: + - v3.0.0 + - v3.1.0 + - v3.8.0 + - v3.10.3 + - v3.15.4 + - v3.16.0 + - v3.17.0 + - v3.22.0 + - v4.0.0 + - v4.2.1 + - latest + ansible_test_target: ${{ fromJson(needs.splitter.outputs.helm_targets) }} + exclude: + # helm_registry_auth: only test against recent versions to reduce CI cost + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.0.0" + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.1.0" + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.8.0" + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.10.3" + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.15.4" + - ansible_test_target: "helm_registry_auth" + helm-version: "v3.16.0" + # helm install/upgrade --create-namespace requires helm >= 3.2.0 + - ansible_test_target: "helm_diff" + helm-version: "v3.0.0" + - ansible_test_target: "helm_diff" + helm-version: "v3.1.0" + - ansible_test_target: "helm_diff" + helm-version: "v3.8.0" + - ansible_test_target: "helm_diff" + helm-version: "v3.10.3" + # UPGRADE FAILED: conflict occurred while applying object helm-diff/test-chart-another-configmap /v1 + - ansible_test_target: "helm_diff" + helm-version: "v4.0.0" + - ansible_test_target: "helm_repository" + helm-version: "v3.0.0" + - ansible_test_target: "helm_repository" + helm-version: "v3.1.0" + - ansible_test_target: "helm_kubeconfig" + helm-version: "v3.0.0" + - ansible_test_target: "helm_kubeconfig" + helm-version: "v3.1.0" + - ansible_test_target: "helm_set_values" + helm-version: "v3.0.0" + - ansible_test_target: "helm_set_values" + helm-version: "v3.1.0" + - ansible_test_target: "helm_set_values" + helm-version: "v3.8.0" + - ansible_test_target: "helm" + helm-version: "v3.0.0" + - ansible_test_target: "helm" + helm-version: "v3.1.0" + - ansible_test_target: "helm_uninstall" + helm-version: "v3.0.0" + - ansible_test_target: "helm_uninstall" + helm-version: "v3.1.0" + name: "${{ matrix.ansible_test_target }}-${{ matrix.helm-version }}" + steps: + - name: Checkout kubernetes.core repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: ${{ env.source }} + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: Set up Python ${{ env.python-version }} + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: ${{ env.python-version }} + + # install ansible + - name: Install ansible-core (${{ env.ansible-version }}) + env: + ANSIBLE_VERSION: ${{ env.ansible-version }} + run: | + curl -sSL --proto '=https' --tlsv1.2 --retry 5 --retry-delay 10 --retry-all-errors \ + "https://github.com/ansible/ansible/archive/${ANSIBLE_VERSION}.tar.gz" \ + -o ansible.tar.gz + python3 -m pip install --disable-pip-version-check ./ansible.tar.gz + rm ansible.tar.gz + shell: bash + + - name: Build and install collection + id: install-src + uses: ansible-network/github_actions/.github/actions/build_install_collection@4678c74a7d712d55e663c88f66eec6d9c3642550 + with: + install_python_dependencies: true + source_path: ${{ env.source }} + + - name: create kubernetes cluster + uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0 + with: + node_image: "kindest/node:v1.29.2" + + - name: "Install Helm version ${{ matrix.helm-version }}" + uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + with: + version: '${{ matrix.helm-version }}' + + - name: Verify Helm Installation + run: helm version + + - name: Disable selinux with selinux_please_lie_to_me + run: | + python3 -m pip uninstall -y selinux + python3 -m pip install --only-binary=:all: selinux_please_lie_to_me==1.0.1 + shell: bash + + - name: Install python requirements + run: python3 -m pip install -r requirements.txt -r test-requirements.txt + shell: bash + working-directory: ${{ steps.install-src.outputs.collection_path }} + + - name: Run integration tests + run: >- + ansible-test integration + --diff + --no-temp-workdir + --color + --skip-tags False + --retry-on-error + --continue-on-error + --python ${{ env.python-version }} + -v + ${{ matrix.ansible_test_target }} + shell: bash + working-directory: ${{ steps.install-src.outputs.collection_path }} diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 6e87a868..8ab40a56 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -17,9 +17,8 @@ jobs: source_dir: "./source" runs-on: ubuntu-latest outputs: - test_targets: ${{ steps.splitter.outputs.test_targets }} - test_targets_json: ${{ steps.splitter.outputs.test_targets_json }} - test_jobs: ${{ steps.splitter.outputs.test_jobs }} + test_targets: ${{ steps.select-targets.outputs.targets }} + test_jobs: ${{ steps.select-targets.outputs.jobs }} steps: - name: Checkout the collection repository uses: actions/checkout@v3 @@ -35,18 +34,40 @@ jobs: collections_to_test: ${{ env.source_dir }} total_jobs: 8 - - name: Display splitter output + - name: Remove all Helm related targets + id: select-targets run: | - echo "test_targets=${{ steps.splitter.outputs.test_targets }}" - echo "test_targets_json=${{ steps.splitter.outputs.test_targets_json }}" - echo "test_jobs=${{ steps.splitter.outputs.test_jobs }}" + import os, json + with open(os.environ.get('GITHUB_OUTPUT'), "a", encoding="utf-8") as fh: + data = os.environ.get("ALL_TEST_TARGETS") + index = 0 + result = {} + for target in data.split(";"): + if target and ':' in target: + k8s = [v for v in target.split(':', maxsplit=1)[1].split(',') if not v.startswith('helm')] + if k8s: + result[index] = ' '.join(k8s) + index += 1 + fh.write(f'targets={json.dumps(result)}\n') + fh.write(f'jobs={json.dumps(list(result.keys()))}\n') + shell: python + env: + ALL_TEST_TARGETS: ${{ steps.splitter.outputs.test_targets }} + + - name: Display splitter output + env: + TARGETS: ${{ steps.select-targets.outputs.targets }} + JOBS: ${{ steps.select-targets.outputs.jobs }} + run: | + echo "targets => $TARGETS" + echo "jobs => $JOBS" shell: bash integration: runs-on: ubuntu-latest timeout-minutes: 60 needs: - splitter - if: ${{ needs.splitter.outputs.test_targets != '' }} + if: ${{ needs.splitter.outputs.test_jobs != '' && needs.splitter.outputs.test_jobs != '[]' }} env: source: "./source" cloud_common: "./cloudcommon" @@ -87,12 +108,14 @@ jobs: fh.write(f'ansible_test_targets={json.loads(os.environ.get("ALL_TEST_TARGETS")).get(os.environ.get("WORKFLOW_ID"))}\n') shell: python env: - ALL_TEST_TARGETS: ${{ needs.splitter.outputs.test_targets_json }} + ALL_TEST_TARGETS: ${{ needs.splitter.outputs.test_targets }} WORKFLOW_ID: ${{ matrix.workflow-id }} - name: Display ansible test targets + env: + ANSIBLE_TEST_TARGETS: ${{ steps.read-targets.outputs.ansible_test_targets }} run: | - echo "ansible_test_targets -> ${{ steps.read-targets.outputs.ansible_test_targets }}" + echo "ansible_test_targets -> $ANSIBLE_TEST_TARGETS" - name: Checkout kubernetes.core repository uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 8e40d545..ea5589b9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,12 +16,13 @@ tests/integration/cloud-config-* .ansible # Helm charts -tests/integration/*-chart-*.tgz +tests/integration/*.tgz tests/integration/targets/*/*.tgz # ansible-test generated file tests/integration/inventory tests/integration/*-*.yml +tests/integration/integration_config.yml # IDE and editor settings .vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 447a2363..7e08c415 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/ansible/cloud-content-ci-automation - rev: precommit_hook + rev: 77f45b0357b6b3c27b04e934f0f51c9b50b7aa25 hooks: - id: block-ide-ai-files always_run: true diff --git a/README.md b/README.md index cef74464..e74deabe 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,8 @@ You can run the collection's test suites with the commands: make test-integration make test-unit +For instructions on running Helm integration tests locally, see the [integration tests README](https://github.com/ansible-collections/kubernetes.core/blob/main/tests/integration/README.md). + ### Testing with `molecule` There are also integration tests in the `molecule` directory which are meant to be run against a local Kubernetes cluster, e.g. using [KinD](https://kind.sigs.k8s.io) or [Minikube](https://minikube.sigs.k8s.io). To set up a local cluster using KinD and run Molecule: diff --git a/changelogs/fragments/20260309-fix-helm-diff-plain-http.yml b/changelogs/fragments/20260309-fix-helm-diff-plain-http.yml new file mode 100644 index 00000000..7cf86221 --- /dev/null +++ b/changelogs/fragments/20260309-fix-helm-diff-plain-http.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - helm - Remove `--plain-http` option from `helm diff upgrade`, as it is not supported by the helm-diff plugin (https://github.com/ansible-collections/kubernetes.core/pull/1232). diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index 88cb9ab4..b4cd2a62 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -956,7 +956,6 @@ def helmdiff_check( reset_values=True, reset_then_reuse_values=False, insecure_skip_tls_verify=False, - plain_http=False, skip_schema_validation=False, ): """ @@ -1024,17 +1023,6 @@ def helmdiff_check( else: cmd += " --skip-schema-validation" - if plain_http: - helm_version = module.get_helm_version() - if LooseVersion(helm_version) < LooseVersion("3.13.0"): - module.fail_json( - msg="plain_http requires helm >= 3.13.0, current version is {0}".format( - helm_version - ) - ) - else: - cmd += " --plain-http" - rc, out, err = module.run_helm_command(cmd) return (len(out.strip()) > 0, out.strip()) @@ -1362,7 +1350,6 @@ def main(): reset_values=reset_values, reset_then_reuse_values=reset_then_reuse_values, insecure_skip_tls_verify=insecure_skip_tls_verify, - plain_http=plain_http, skip_schema_validation=skip_schema_validation, ) if would_change and module._diff: diff --git a/sonar-project.properties b/sonar-project.properties index 53b20ab7..701e961f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -28,7 +28,7 @@ sonar.cpd.exclusions=tests/** # constructor (not {...} literals) for readability and consistency across the # collection. Suppress python:S7498 ("prefer literal syntax"), which conflicts # with that convention and otherwise re-fires on every new module argument. -sonar.issue.ignore.multicriteria=e1,e2,e3 +sonar.issue.ignore.multicriteria=e1,e2,e3,e4,e5 sonar.issue.ignore.multicriteria.e1.ruleKey=python:S7498 sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.py @@ -45,3 +45,24 @@ sonar.issue.ignore.multicriteria.e2.resourceKey=tests/**/*.py # to simplify maintenance. Suppress githubactions:S7637 ("use full commit SHA"). sonar.issue.ignore.multicriteria.e3.ruleKey=githubactions:S7637 sonar.issue.ignore.multicriteria.e3.resourceKey=.github/workflows/**/*.yaml + +# Workflows across this repo install ansible-core from a GitHub source +# archive (required for devel/milestone builds, which have no published +# wheel) and install this collection's shared test-requirements.txt / +# requirements.txt. Suppress githubactions:S8541 ("omitting --only-binary +# :all:") repo-wide for workflow files: forcing wheel-only installs would +# break the ansible-core source install and fails outright on the +# test-requirements.txt pin coverage==4.5.4, which has no Python 3.13 wheel. +# Scoped the same way as e3 above, since a filename-only resourceKey (as +# originally used here) does not reliably suppress issues already raised +# against this project. +sonar.issue.ignore.multicriteria.e4.ruleKey=githubactions:S8541 +sonar.issue.ignore.multicriteria.e4.resourceKey=.github/workflows/**/*.yaml + +# Same shared test-requirements.txt / requirements.txt as above are not +# hash-locked; that is a repo-wide dependency-management concern affecting +# every existing workflow. Suppress githubactions:S8544 ("dependencies +# without locking resolved versions") repo-wide for workflow files rather +# than diverging from established practice. +sonar.issue.ignore.multicriteria.e5.ruleKey=githubactions:S8544 +sonar.issue.ignore.multicriteria.e5.resourceKey=.github/workflows/**/*.yaml diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 00000000..b0921288 --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,46 @@ +# Running Helm Integration Tests Locally + +This guide explains how to run the `helm*` integration test targets locally using `ansible-test`. + +## Prerequisites + +- `ansible-test` available in your environment (installed with `ansible-core`) +- A Kubernetes cluster accessible via `kubectl` (for targets that interact with a cluster) + +## Configuration + +Create an `integration_config.yml` file under `tests/integration/` with the following variables: + +```yaml +setup_helm_version: vx.x.x # e.g v4.2.1 +helm_install_path: /path/to/helm/directory +``` + +### Variables + +| Variable | Description | +|---|---| +| `setup_helm_version` | The Helm version to install (e.g. `v4.2.1`). The `v` prefix is optional and will be added automatically if omitted. | +| `helm_install_path` | Path to a directory that either already contains a `helm` executable matching the version set in `setup_helm_version`, or an empty/non-existent directory where Helm will be downloaded and installed. | + +If a `helm` binary already exists at `/helm`, the setup will skip the download and use the existing binary directly. + +## Running Tests + +Run a specific Helm test target with: + +```bash +ansible-test integration --python -v --no-temp-workdir +``` + +For example, to run the `helm` target with Python 3.12: + +```bash +ansible-test integration --python 3.12 -v --no-temp-workdir helm +``` + +You can run multiple targets in a single command: + +```bash +ansible-test integration --python 3.12 -v --no-temp-workdir helm helm_diff helm_plugin +``` diff --git a/tests/integration/targets/helm/aliases b/tests/integration/targets/helm/aliases index 6ef13eba..7de68efc 100644 --- a/tests/integration/targets/helm/aliases +++ b/tests/integration/targets/helm/aliases @@ -1 +1,4 @@ -disabled # used by test targets helm_vX_XX_XX +helm +helm_info +helm_plugin +helm_template diff --git a/tests/integration/targets/helm/defaults/main.yml b/tests/integration/targets/helm/defaults/main.yml index ec2c0c62..94570c8c 100644 --- a/tests/integration/targets/helm/defaults/main.yml +++ b/tests/integration/targets/helm/defaults/main.yml @@ -1,6 +1,6 @@ --- -helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz" -helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" +helm_binary: "helm" +setup_helm_version_binary_path: "{{ helm_binary }}" chart_test: "ingress-nginx" chart_test_oci: "oci://registry-1.docker.io/bitnamicharts/redis" diff --git a/tests/integration/targets/helm/library/helm_test_version.py b/tests/integration/targets/helm/library/helm_test_version.py deleted file mode 100644 index 1ac12e0f..00000000 --- a/tests/integration/targets/helm/library/helm_test_version.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright: (c) 2021, Ansible Project -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = r""" ---- -module: helm_test_version -short_description: check helm executable version -author: - - Aubin Bikouo (@abikouo) -requirements: - - "helm (https://github.com/helm/helm/releases)" -description: - - validate version of helm binary is lower than the specified version. -options: - binary_path: - description: - - The path of a helm binary to use. - required: false - type: path - version: - description: - - version to test against helm binary. - type: str - default: 3.7.0 -""" - -EXAMPLES = r""" -- name: validate helm binary version is lower than 3.5.0 - helm_test_version: - binary_path: path/to/helm - version: "3.5.0" -""" - -RETURN = r""" -message: - type: str - description: Text message describing the test result. - returned: always - sample: 'version installed: 3.4.5 is lower than version 3.5.0' -result: - type: bool - description: Test result. - returned: always - sample: 1 -""" - -import re - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.kubernetes.core.plugins.module_utils.version import ( - LooseVersion, -) - - -def main(): - module = AnsibleModule( - argument_spec=dict( - binary_path=dict(type="path"), - version=dict(type="str", default="3.7.0"), - ), - ) - - bin_path = module.params.get("binary_path") - version = module.params.get("version") - - if bin_path is not None: - helm_cmd_common = bin_path - else: - helm_cmd_common = "helm" - - helm_cmd_common = module.get_bin_path(helm_cmd_common, required=True) - rc, out, err = module.run_command([helm_cmd_common, "version"]) - if rc != 0: - module.fail_json(msg="helm version failed.", err=err, out=out, rc=rc) - - m = re.match(r'version.BuildInfo{Version:"v([0-9\.]*)",', out) - installed_version = m.group(1) - - message = "version installed: %s" % installed_version - if LooseVersion(installed_version) < LooseVersion(version): - message += " is lower than version %s" % version - module.exit_json(changed=False, result=True, message=message) - else: - message += " is greater than version %s" % version - module.exit_json(changed=False, result=False, message=message) - - -if __name__ == "__main__": - main() diff --git a/tests/integration/targets/helm/meta/main.yml b/tests/integration/targets/helm/meta/main.yml index d05af689..82a1764b 100644 --- a/tests/integration/targets/helm/meta/main.yml +++ b/tests/integration/targets/helm/meta/main.yml @@ -1,3 +1,5 @@ --- +dependencies: + - setup_helm_version collections: - kubernetes.core diff --git a/tests/integration/targets/helm/tasks/main.yml b/tests/integration/targets/helm/tasks/main.yml index 3c8d3ff8..a814e67a 100644 --- a/tests/integration/targets/helm/tasks/main.yml +++ b/tests/integration/targets/helm/tasks/main.yml @@ -1,22 +1,11 @@ --- - name: Ensure helm is not installed - file: - path: "{{ item }}" + ansible.builtin.file: + path: "/tmp/helm" state: absent - with_items: - - "/tmp/helm" - name: Check failed if helm is not installed - include_tasks: test_helm_not_installed.yml - -- name: Install Helm v4 - ansible.builtin.include_role: - name: install_helm - vars: - helm_version: v3.6.0 - -- name: Test helm uninstall - ansible.builtin.include_tasks: test_helm_uninstall.yml + ansible.builtin.include_tasks: test_helm_not_installed.yml - name: Run tests - include_tasks: run_test.yml + ansible.builtin.include_tasks: run_test.yml diff --git a/tests/integration/targets/helm/tasks/run_test.yml b/tests/integration/targets/helm/tasks/run_test.yml index 1eb120b7..ff9a4f0f 100644 --- a/tests/integration/targets/helm/tasks/run_test.yml +++ b/tests/integration/targets/helm/tasks/run_test.yml @@ -1,22 +1,18 @@ --- -- name: "Install {{ helm_version }}" - include_role: - name: install_helm - - name: Main helm tests block: - name: Install helm-diff plugin helm_plugin: binary_path: "{{ helm_binary }}" plugin_path: https://github.com/databus23/helm-diff - plugin_version: "{{ helm_version is version('v4.0.0', '>=') | ternary('v3.14.0', 'v3.10.0') }}" + plugin_version: "{{ helm_version | string is ansible.builtin.version('4.0.0', '>=') | ternary('v3.14.0', 'v3.10.0') }}" verify: false - name: "Ensure we honor the environment variables" - include_tasks: test_read_envvars.yml + ansible.builtin.include_tasks: test_read_envvars.yml - name: Deploy charts - include_tasks: "tests_chart/{{ test_chart_type }}.yml" + ansible.builtin.include_tasks: "tests_chart/{{ test_chart_type }}.yml" loop_control: loop_var: test_chart_type with_items: @@ -24,33 +20,34 @@ - from_repository - from_url - - name: test helm upgrade with reuse_values - include_tasks: test_helm_reuse_values.yml + - name: Test helm upgrade with reuse_values + ansible.builtin.include_tasks: test_helm_reuse_values.yml - - name: test helm upgrade with reset_then_reuse_values - include_tasks: test_helm_reset_then_reuse_values.yml + - name: Test helm upgrade with reset_then_reuse_values + ansible.builtin.include_tasks: test_helm_reset_then_reuse_values.yml + when: helm_version | string is ansible.builtin.version('3.14.0', '>=') - - name: test helm dependency update - include_tasks: test_up_dep.yml + - name: Test helm dependency update + ansible.builtin.include_tasks: test_up_dep.yml - name: Test helm install with chart name containing space - include_tasks: test_helm_with_space_into_chart_name.yml + ansible.builtin.include_tasks: test_helm_with_space_into_chart_name.yml # https://github.com/ansible-collections/community.kubernetes/issues/296 - name: Test Skip CRDS feature in helm chart install - include_tasks: test_crds.yml + ansible.builtin.include_tasks: test_crds.yml - name: Test insecure registry flag feature - include_tasks: test_helm_insecure.yml + ansible.builtin.include_tasks: test_helm_insecure.yml - name: Test take ownership flag feature - include_tasks: test_helm_take_ownership.yml + ansible.builtin.include_tasks: test_helm_take_ownership.yml - name: Test helm skip_schema_validation - include_tasks: test_skip_schema_validation.yml + ansible.builtin.include_tasks: test_skip_schema_validation.yml - name: Test helm wait_for_jobs - include_tasks: test_helm_wait_for_jobs.yml + ansible.builtin.include_tasks: test_helm_wait_for_jobs.yml always: - name: Remove helm-diff plugin diff --git a/tests/integration/targets/helm/tasks/test_helm_insecure.yml b/tests/integration/targets/helm/tasks/test_helm_insecure.yml index 2da16a68..cfa00122 100644 --- a/tests/integration/targets/helm/tasks/test_helm_insecure.yml +++ b/tests/integration/targets/helm/tasks/test_helm_insecure.yml @@ -14,7 +14,7 @@ register: install - name: Validate that insecure flag is not set - assert: + ansible.builtin.assert: that: - install is changed - '"--insecure-skip-tls-verify" not in install.command' @@ -30,18 +30,18 @@ ignore_errors: true - name: Validate that insecure flag IS set if helm version is >= 3.16.0 - assert: + ansible.builtin.assert: that: - install is changed - '"--insecure-skip-tls-verify" in install.command' - when: '"v3.16.0" <= helm_version' + when: helm_version | string is ansible.builtin.version("3.16.0", ">=") - name: Validate that feature fails for helm < 3.16.0 - assert: + ansible.builtin.assert: that: - install is failed - '"insecure_skip_tls_verify requires helm >= 3.16.0" in install.msg' - when: 'helm_version < "v3.16.0"' + when: helm_version | string is ansible.builtin.version("3.16.0", "<") always: - name: Remove helm namespace 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 02e1de52..02eb1d61 100644 --- a/tests/integration/targets/helm/tasks/test_helm_not_installed.yml +++ b/tests/integration/targets/helm/tasks/test_helm_not_installed.yml @@ -1,7 +1,7 @@ --- - name: Failed test when helm is not installed helm: - binary_path: "{{ helm_binary}}_fake" + binary_path: "{{ helm_binary }}_fake" name: test chart_ref: "{{ chart_test }}" namespace: "helm-test" @@ -9,15 +9,7 @@ register: helm_missing_binary - name: Assert that helm is not installed - assert: - that: - - helm_missing_binary is failed - - "'No such file or directory' in helm_missing_binary.msg" - when: ansible_version.full is version('2.20', '<') - -- name: Assert that helm is not installed (ansible 2.20+) - assert: + ansible.builtin.assert: that: - helm_missing_binary is failed - "'Error executing command' in helm_missing_binary.msg" - when: ansible_version.full is version('2.20', '>=') diff --git a/tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml b/tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml index dab9d958..821fe5fb 100644 --- a/tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml +++ b/tests/integration/targets/helm/tasks/test_helm_reset_then_reuse_values.yml @@ -32,7 +32,7 @@ register: release_value - name: Validate that chart values are as expected - assert: + ansible.builtin.assert: that: - install is changed - '"--reset-then-reuse-values" not in install.command' @@ -80,7 +80,7 @@ register: release_value - name: Validate that chart values are as expected - assert: + ansible.builtin.assert: that: - upgrade is changed - '"--reset-then-reuse-values" in upgrade.command' diff --git a/tests/integration/targets/helm/tasks/test_helm_reuse_values.yml b/tests/integration/targets/helm/tasks/test_helm_reuse_values.yml index 69cca3a8..dcd17822 100644 --- a/tests/integration/targets/helm/tasks/test_helm_reuse_values.yml +++ b/tests/integration/targets/helm/tasks/test_helm_reuse_values.yml @@ -32,7 +32,7 @@ register: release_value - name: Validate that chart values are as expected - assert: + ansible.builtin.assert: that: - install is changed - '"--reuse-values=True" not in install.command' @@ -72,7 +72,7 @@ register: release_value - name: Validate that chart values are as expected - assert: + ansible.builtin.assert: that: - upgrade is changed - '"--reuse-values=True" in upgrade.command' diff --git a/tests/integration/targets/helm/tasks/test_helm_take_ownership.yml b/tests/integration/targets/helm/tasks/test_helm_take_ownership.yml index 84e2732a..e442d0e5 100644 --- a/tests/integration/targets/helm/tasks/test_helm_take_ownership.yml +++ b/tests/integration/targets/helm/tasks/test_helm_take_ownership.yml @@ -14,7 +14,7 @@ register: install - name: Validate that take-ownership flag is not set - assert: + ansible.builtin.assert: that: - install is changed - '"--take-ownership" not in install.command' @@ -50,18 +50,18 @@ ignore_errors: true - name: Validate that take-ownership flag IS set if helm version is >= 3.17.0 - assert: + ansible.builtin.assert: that: - upgrade is changed - '"--take-ownership" in upgrade.command' - when: '"v3.17.0" <= helm_version' + when: helm_version | string is ansible.builtin.version("3.17.0", ">=") - name: Validate that feature fails for helm < 3.17.0 - assert: + ansible.builtin.assert: that: - upgrade is failed - '"take_ownership requires helm >= 3.17.0" in upgrade.msg' - when: 'helm_version < "v3.17.0"' + when: helm_version | string is ansible.builtin.version("3.17.0", "<") - name: Upgrade chart (take-onwership flag not set) helm: @@ -79,18 +79,18 @@ ignore_errors: true - name: Validate that take-ownership flag IS set if helm version is >= 3.17.0 - assert: + ansible.builtin.assert: that: - upgrade is changed - '"--take-ownership" not in upgrade.command' - when: '"v3.17.0" <= helm_version' + when: helm_version | string is ansible.builtin.version("3.17.0", ">=") - name: Validate that feature fails for helm < 3.17.0 - assert: + ansible.builtin.assert: that: - upgrade is changed - upgrade.msg is not defined - when: 'helm_version < "v3.17.0"' + when: helm_version | string is ansible.builtin.version("3.17.0", "<") always: - name: Remove helm namespace diff --git a/tests/integration/targets/helm/tasks/test_helm_uninstall.yml b/tests/integration/targets/helm/tasks/test_helm_uninstall.yml deleted file mode 100644 index 16060e18..00000000 --- a/tests/integration/targets/helm/tasks/test_helm_uninstall.yml +++ /dev/null @@ -1,97 +0,0 @@ -- name: validate helm version lower than 3.7.0 - helm_test_version: - binary_path: "{{ helm_binary }}" - version: "3.7.0" - register: test_version - -- 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" - chart_name_pending: "test-uninstall-pending-release" - helm_namespace: "{{ test_namespace[1] }}" - block: - - - name: Install chart - helm: - binary_path: "{{ helm_binary }}" - name: "{{ chart_name }}" - chart_ref: "{{ chart_source }}" - namespace: "{{ helm_namespace }}" - create_namespace: true - - - name: Delete chart with wait - helm: - state: absent - binary_path: "{{ helm_binary }}" - name: "{{ chart_name }}" - namespace: "{{ helm_namespace }}" - wait: yes - register: uninstall - - - name: assert warning has been raised - assert: - that: - - uninstall.warnings is defined - - '"helm uninstall support option --wait for helm release >= 3.7.0" in uninstall.warnings' - - - name: Install Helm v4 - ansible.builtin.include_role: - name: install_helm - vars: - helm_version: v4.0.0 - - - name: Install chart - helm: - binary_path: "{{ helm_binary }}" - name: "{{ chart_name }}" - chart_ref: "{{ chart_source }}" - namespace: "{{ helm_namespace }}" - create_namespace: true - - - name: uninstall chart again using recent version - helm: - state: absent - binary_path: "{{ helm_binary }}" - name: "{{ chart_name }}" - namespace: "{{ helm_namespace }}" - wait: yes - register: uninstall - - # Test uninstall chart release with 'pending-install' status - - name: Create chart release with 'pending-install' status - helm_test_pending: - binary_path: "{{ helm_binary }}" - chart_ref: "{{ chart_source }}" - chart_release: "{{ chart_name_pending }}" - chart_release_namespace: "{{ helm_namespace }}" - - - name: Uninstall chart release with 'pending-install' status - helm: - binary_path: "{{ helm_binary }}" - release_name: "{{ chart_name_pending }}" - namespace: "{{ helm_namespace }}" - release_state: absent - register: _uninstall - - - name: Get Helm release details - helm_info: - binary_path: "{{ helm_binary }}" - release_namespace: "{{ helm_namespace }}" - release_state: pending - release_name: "{{ chart_name_pending }}" - register: _info - - - name: assert release does not exist anymore - assert: - that: - - _uninstall is changed - - _info.status is undefined - - always: - - name: Remove namespace - k8s: - kind: Namespace - name: "{{ helm_namespace }}" - state: absent - ignore_errors: true - when: test_version.result diff --git a/tests/integration/targets/helm/tasks/test_helm_wait_for_jobs.yml b/tests/integration/targets/helm/tasks/test_helm_wait_for_jobs.yml index 48c7735c..cfdae97a 100644 --- a/tests/integration/targets/helm/tasks/test_helm_wait_for_jobs.yml +++ b/tests/integration/targets/helm/tasks/test_helm_wait_for_jobs.yml @@ -19,19 +19,19 @@ ignore_errors: true - name: Validate wait_for_jobs with helm >= 3.5.0 works - assert: + ansible.builtin.assert: that: - install is changed - "'--wait' in install.command" - "'--wait-for-jobs' in install.command" - when: "helm_version is ansible.builtin.version('v3.5.0', '>=')" + when: "helm_version | string is ansible.builtin.version('3.5.0', '>=')" - name: Validate wait_for_jobs with helm < 3.5.0 fails - assert: + ansible.builtin.assert: that: - install is failed - "'wait_for_jobs requires helm >= 3.5.0' in install.msg" - when: "helm_version is ansible.builtin.version('v3.5.0', '<')" + when: "helm_version | string is ansible.builtin.version('3.5.0', '<')" - name: Install chart with wait_for_jobs but without wait helm: @@ -44,7 +44,7 @@ register: install_no_wait - name: Validate wait_for_jobs is ignored without wait - assert: + ansible.builtin.assert: that: - install_no_wait is changed - "'--wait-for-jobs' not in install_no_wait.command" diff --git a/tests/integration/targets/helm/tasks/test_helm_with_space_into_chart_name.yml b/tests/integration/targets/helm/tasks/test_helm_with_space_into_chart_name.yml index fcf86766..f28031ba 100644 --- a/tests/integration/targets/helm/tasks/test_helm_with_space_into_chart_name.yml +++ b/tests/integration/targets/helm/tasks/test_helm_with_space_into_chart_name.yml @@ -27,7 +27,7 @@ register: install_chart - name: Assert that chart is installed - assert: + ansible.builtin.assert: that: - install_chart is changed - install_chart.status.status | lower == 'deployed' @@ -40,7 +40,7 @@ register: chart_info - name: Assert that Chart is installed (using helm_info) - assert: + ansible.builtin.assert: that: - chart_info.status.status | lower == 'deployed' diff --git a/tests/integration/targets/helm/tasks/test_skip_schema_validation.yml b/tests/integration/targets/helm/tasks/test_skip_schema_validation.yml index f3afe574..6674d701 100644 --- a/tests/integration/targets/helm/tasks/test_skip_schema_validation.yml +++ b/tests/integration/targets/helm/tasks/test_skip_schema_validation.yml @@ -22,22 +22,22 @@ ignore_errors: true - name: Debug install result - debug: + ansible.builtin.debug: var: install - name: Validate skip_schema_validation with helm >= 3.16.0 works - assert: + ansible.builtin.assert: that: - install is changed - "'--skip-schema-validation' in install.command" - when: "helm_version is ansible.builtin.version('v3.16.0', '>=')" + when: "helm_version | string is ansible.builtin.version('3.16.0', '>=')" - name: Validate skip_schema_validation with helm < 3.16.0 fails - assert: + ansible.builtin.assert: that: - install is failed - "'skip_schema_validation requires helm >= 3.16.0' in install.msg" - when: "helm_version is ansible.builtin.version('v3.16.0', '<')" + when: "helm_version | string is ansible.builtin.version('3.16.0', '<')" always: - name: Remove helm namespace diff --git a/tests/integration/targets/helm/tasks/test_up_dep.yml b/tests/integration/targets/helm/tasks/test_up_dep.yml index 39a14460..c54a8256 100644 --- a/tests/integration/targets/helm/tasks/test_up_dep.yml +++ b/tests/integration/targets/helm/tasks/test_up_dep.yml @@ -3,8 +3,8 @@ vars: helm_namespace: "{{ test_namespace[3] }}" block: - - name: copy chart - copy: + - name: Copy chart + ansible.builtin.copy: src: "{{ item }}" dest: /tmp loop: @@ -19,16 +19,16 @@ chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" dependency_update: false - create_namespace: yes + create_namespace: true register: release - name: "Get stats of the subchart" - stat: + ansible.builtin.stat: path: "/tmp/test-chart/Chart.lock" register: stat_result - name: "Check if the subchart not exist in chart" - assert: + ansible.builtin.assert: that: - not stat_result.stat.exists success_msg: "subchart not exist in the chart directory" @@ -41,12 +41,12 @@ chart_ref: "/tmp/test-chart" chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" - create_namespace: yes + create_namespace: true dependency_update: true ignore_errors: true register: release - - assert: + - ansible.builtin.assert: that: - release.warnings[0] == "There is no dependencies block defined in Chart.yaml. Dependency update will not be performed. Please consider add dependencies block or disable dependency_update to remove this warning." success_msg: "warning when there is no dependencies block with dependency_update enabled" @@ -59,16 +59,16 @@ chart_version: "{{ chart_source_version | default(omit) }}" namespace: "{{ helm_namespace }}" dependency_update: true - create_namespace: yes + create_namespace: true register: release - name: "Get stats of the subchart" - stat: + ansible.builtin.stat: path: "/tmp/dep-up/Chart.lock" register: stat_result - name: "Check if the subchart exists in chart" - assert: + ansible.builtin.assert: that: - stat_result.stat.exists success_msg: "subchart exist in the chart directory" @@ -82,7 +82,7 @@ state: absent - name: "Remove charts" - file: + ansible.builtin.file: state: absent path: "/tmp/{{ item }}" loop: @@ -92,8 +92,8 @@ # Helm_template module - name: "Test dependency update for helm_template module" block: - - name: copy chart - copy: + - name: Copy chart + ansible.builtin.copy: src: "{{ item }}" dest: /tmp loop: @@ -110,7 +110,7 @@ register: result - name: "Get stats of the subchart" - stat: + ansible.builtin.stat: path: "{{ item }}" register: stat_result loop: @@ -118,7 +118,7 @@ - /tmp/dep_up/charts/test-chart/templates/configmap.yaml - name: "Check if the subchart exist in chart" - assert: + ansible.builtin.assert: that: - stat_result.results[0].stat.exists - stat_result.results[1].stat.exists @@ -135,7 +135,7 @@ register: result - name: "Get stats of the subchart" - stat: + ansible.builtin.stat: path: "{{ item }}" register: stat_result loop: @@ -143,7 +143,7 @@ - /tmp/test-chart/templates/configmap.yaml - name: "Check if the subchart not exist in chart" - assert: + ansible.builtin.assert: that: - not stat_result.results[0].stat.exists - stat_result.results[1].stat.exists @@ -152,7 +152,7 @@ always: - name: "Remove charts" - file: + ansible.builtin.file: state: absent path: "/tmp/{{ item }}" loop: diff --git a/tests/integration/targets/helm/tasks/tests_chart.yml b/tests/integration/targets/helm/tasks/tests_chart.yml index 988365de..ccaa909e 100644 --- a/tests/integration/targets/helm/tasks/tests_chart.yml +++ b/tests/integration/targets/helm/tasks/tests_chart.yml @@ -5,12 +5,12 @@ chart_release_replaced_name: "test-{{ chart_name | default(source) }}-001" block: - name: Create temp directory - tempfile: + ansible.builtin.tempfile: state: directory register: tmpdir - name: Set temp directory fact - set_fact: + ansible.builtin.set_fact: temp_dir: "{{ tmpdir.path }}" - name: Check helm_info empty @@ -21,7 +21,7 @@ register: empty_info - name: "Assert that no charts are installed with helm_info" - assert: + ansible.builtin.assert: that: - empty_info.status is undefined @@ -36,7 +36,7 @@ register: install_fail - name: "Assert that Install fail {{ chart_test }} from {{ source }}" - assert: + ansible.builtin.assert: that: - install_fail is failed - "'Error: create: failed to create: namespaces \"' + helm_namespace + '\" not found' in install_fail.stderr" @@ -53,7 +53,7 @@ check_mode: true - name: "Assert that {{ chart_test }} chart is installed from {{ source }} in check mode" - assert: + ansible.builtin.assert: that: - install_check_mode is changed - install_check_mode.status is defined @@ -70,7 +70,7 @@ register: install - name: "Assert that {{ chart_test }} chart version {{ chart_test_version }} is installed from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed - install.status.chart == chart_test+"-"+chart_test_version @@ -94,7 +94,7 @@ register: release_state_content_info - name: "Assert that {{ chart_test }} chart version {{ chart_test_version }} is installed from {{ source }} with helm_info" - assert: + ansible.builtin.assert: that: - content_info.status.chart == chart_test+"-"+chart_test_version - content_info.status.status | lower == 'deployed' @@ -111,7 +111,7 @@ diff: true - name: Assert idempotency - assert: + ansible.builtin.assert: that: - install is not changed - install.status.chart == chart_test+"-"+chart_test_version @@ -128,7 +128,7 @@ register: install - name: "Assert that {{ chart_test }} chart is upgraded with new var from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed - install.status.status | lower == 'deployed' @@ -147,7 +147,7 @@ diff: true - name: Assert idempotency after add vars - assert: + ansible.builtin.assert: that: - install is not changed - install.status.status | lower == 'deployed' @@ -164,7 +164,7 @@ register: install - name: "Assert that {{ chart_test }} chart is upgraded with new var from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed - install.status.status | lower == 'deployed' @@ -182,7 +182,7 @@ diff: true - name: Assert idempotency after removing vars - assert: + ansible.builtin.assert: that: - install is not changed - install.status.status | lower == 'deployed' @@ -199,7 +199,7 @@ register: install - name: "Assert that {{ chart_test }} chart is upgraded with new version from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed - install.status.status | lower == 'deployed' @@ -216,7 +216,7 @@ diff: true - name: Assert idempotency after upgrade - assert: + ansible.builtin.assert: that: - install is not changed - install.status.status | lower == 'deployed' @@ -231,7 +231,7 @@ register: install - name: "Assert that {{ chart_test }} chart is removed from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed @@ -245,7 +245,7 @@ diff: true - name: Assert idempotency - assert: + ansible.builtin.assert: that: - install is not changed @@ -260,7 +260,7 @@ register: install - name: "Assert that {{ chart_test }} chart is installed from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed @@ -269,12 +269,12 @@ binary_path: "{{ helm_binary }}" state: absent name: "{{ chart_release_replaced_name }}" - purge: False + purge: false namespace: "{{ helm_namespace }}" register: install - name: Check if chart is removed - assert: + ansible.builtin.assert: that: - install is changed @@ -285,11 +285,11 @@ chart_ref: "{{ chart_source }}" chart_version: "{{ chart_test_version }}" namespace: "{{ helm_namespace }}" - replace: True + replace: true register: install - name: "Assert that {{ chart_test }} chart is installed from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed @@ -302,7 +302,7 @@ register: install - name: Check if chart is removed - assert: + ansible.builtin.assert: that: - install is changed @@ -318,7 +318,7 @@ register: install - name: "Assert that {{ chart_test }} chart has var from {{ source }}" - assert: + ansible.builtin.assert: that: - install is changed - install.status.status | lower == 'deployed' @@ -337,7 +337,7 @@ register: install - name: "Assert the result is consistent" - assert: + ansible.builtin.assert: that: - not (install is changed) @@ -358,7 +358,7 @@ - "{{ role_path }}/files/values.yaml" register: result - - assert: + - ansible.builtin.assert: that: - result is changed - result is not failed @@ -366,11 +366,11 @@ - result.command is match(helm_binary+" template "+chart_source) - name: Check templates created - stat: + ansible.builtin.stat: path: "{{ temp_dir }}/{{ chart_test }}/templates" register: result - - assert: + - ansible.builtin.assert: that: result.stat.exists @@ -379,7 +379,7 @@ binary_path: "{{ helm_binary }}" chart_ref: "{{ chart_source }}" chart_version: "{{ chart_test_version }}" - disable_hook: True + disable_hook: true release_name: "myrelease" release_namespace: "myreleasenamespace" show_only: @@ -389,7 +389,7 @@ register: result when: chart_source is search("test-chart") - - assert: + - ansible.builtin.assert: that: - result is changed - result is not failed @@ -412,14 +412,14 @@ register: result - name: Assert that release fails with non-existent context - assert: + ansible.builtin.assert: that: - result is failed - "'context \"does-not-exist\" does not exist' in result.stderr" always: - name: Clean up temp dir - file: + ansible.builtin.file: state: absent path: "{{ temp_dir }}" ignore_errors: true diff --git a/tests/integration/targets/helm_diff/defaults/main.yml b/tests/integration/targets/helm_diff/defaults/main.yml index 6c2a691f..21ade8a6 100644 --- a/tests/integration/targets/helm_diff/defaults/main.yml +++ b/tests/integration/targets/helm_diff/defaults/main.yml @@ -1,3 +1,2 @@ --- -helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" helm_namespace: helm-diff diff --git a/tests/integration/targets/helm_diff/meta/main.yml b/tests/integration/targets/helm_diff/meta/main.yml index b700f8c1..8a98e8e1 100644 --- a/tests/integration/targets/helm_diff/meta/main.yml +++ b/tests/integration/targets/helm_diff/meta/main.yml @@ -1,5 +1,6 @@ --- dependencies: - remove_namespace - - install_helm - setup_helm_registry + - setup_helm + - setup_helm_version diff --git a/tests/integration/targets/helm_diff/playbook.yaml b/tests/integration/targets/helm_diff/playbook.yaml deleted file mode 100644 index cb953721..00000000 --- a/tests/integration/targets/helm_diff/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- connection: local - gather_facts: true - hosts: localhost - - roles: - - helm_diff diff --git a/tests/integration/targets/helm_diff/runme.sh b/tests/integration/targets/helm_diff/runme.sh deleted file mode 100755 index 02ef1460..00000000 --- a/tests/integration/targets/helm_diff/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_diff/tasks/main.yml b/tests/integration/targets/helm_diff/tasks/main.yml index 94ca81fd..9d3271f9 100644 --- a/tests/integration/targets/helm_diff/tasks/main.yml +++ b/tests/integration/targets/helm_diff/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: Define default value for helm binary path + ansible.builtin.set_fact: + helm_binary: "{{ setup_helm_binary_path | default('helm') }}" + - name: Test helm diff functionality vars: test_chart_ref: "/tmp/test-chart" @@ -10,10 +14,11 @@ binary_path: "{{ helm_binary }}" state: present plugin_path: https://github.com/databus23/helm-diff - plugin_version: 3.9.13 + verify: false + plugin_version: "{{ helm_version | string is ansible.builtin.version('4.0.0', '>=') | ternary('3.14.0', '3.10.0') }}" - name: Copy test chart - copy: + ansible.builtin.copy: src: "test-chart/" dest: "{{ test_chart_ref }}" @@ -26,13 +31,13 @@ create_namespace: true register: install - - assert: + - ansible.builtin.assert: that: - install is changed - name: Modify local chart - blockinfile: - create: yes + ansible.builtin.blockinfile: + create: true path: "{{ test_chart_ref }}/templates/anothermap.yaml" block: !unsafe | apiVersion: v1 @@ -55,7 +60,7 @@ - name: Check if helm diff check is correct vars: foo_bar_value: "+ foo: bar" - assert: + ansible.builtin.assert: that: - foo_bar_value in diff_result.diff.prepared @@ -67,7 +72,7 @@ chart_ref: "{{ test_chart_ref }}" register: install - - assert: + - ansible.builtin.assert: that: - install is changed @@ -77,12 +82,12 @@ name: test-chart namespace: "{{ helm_namespace }}" chart_ref: "{{ test_chart_ref }}" - check_mode: yes + check_mode: true diff: true register: diff_result - name: Check if no diff in check mode when no change - assert: + ansible.builtin.assert: that: - '"diff" not in diff_result' @@ -94,12 +99,12 @@ chart_ref: "{{ test_chart_ref }}" register: install - - assert: + - ansible.builtin.assert: that: - install is not changed - name: Modify values - blockinfile: + ansible.builtin.blockinfile: create: true path: "{{ test_chart_ref }}/values.yml" block: | @@ -116,7 +121,7 @@ - "{{ test_chart_ref }}/values.yml" register: install - - assert: + - ansible.builtin.assert: that: - install is changed @@ -130,7 +135,7 @@ - "{{ test_chart_ref }}/values.yml" register: install - - assert: + - ansible.builtin.assert: that: - install is not changed @@ -146,7 +151,7 @@ - "{{ test_chart_ref }}/values.yml" register: install - - assert: + - ansible.builtin.assert: that: - install is changed @@ -162,7 +167,7 @@ - "{{ test_chart_ref }}/values.yml" register: install - - assert: + - ansible.builtin.assert: that: - install is not changed @@ -181,7 +186,7 @@ value_type: string register: install - - assert: + - ansible.builtin.assert: that: - install is changed @@ -200,7 +205,7 @@ value_type: string register: install - - assert: + - ansible.builtin.assert: that: - install is not changed @@ -213,7 +218,7 @@ ignore_errors: true - name: Define chart variables - set_fact: + ansible.builtin.set_fact: test_chart_values: myValue: 'Some ConfigMap data value' myConfigmapName: 'ansible-config-from-url' @@ -247,7 +252,9 @@ path: '{{ _tmpd.path }}' - name: Log into Helm registry - ansible.builtin.command: "{{ helm_binary }} registry login -u testuser -p 'pass123!' localhost:6035" + ansible.builtin.shell: >- + echo 'pass123!' | {{ helm_binary }} registry login -u testuser --password-stdin localhost:6035 + {{ helm_version | string is ansible.builtin.version("3.18.0", ">=") | ternary('--plain-http', '--insecure') }} - name: Install chart from remote URL helm: @@ -257,6 +264,7 @@ namespace: "{{ helm_namespace }}" name: another-chart release_values: "{{ test_chart_values }}" + plain_http: "{{ helm_version | string is ansible.builtin.version('3.13.0', '>=') }}" - name: Upgrade chart helm: @@ -266,44 +274,21 @@ namespace: "{{ helm_namespace }}" name: another-chart release_values: "{{ test_chart_values }}" + plain_http: "{{ helm_version | string is ansible.builtin.version('3.13.0', '>=') }}" check_mode: true register: _upgrade - name: Assert that module raised a warning - assert: + ansible.builtin.assert: that: - not _upgrade.changed - _upgrade.warnings is defined - _upgrade.warnings | length == 1 - _upgrade.warnings[0] == "The default idempotency check can fail to report changes in certain cases. Install helm diff >= 3.4.1 for better results." - - name: Install helm diff (version=3.4.1) - helm_plugin: - binary_path: "{{ helm_binary }}" - state: present - plugin_path: https://github.com/databus23/helm-diff - plugin_version: 3.4.1 - - - name: Upgrade chart once again - helm: - binary_path: "{{ helm_binary }}" - chart_ref: "{{ test_chart_ref_url }}" - chart_version: 0.1.0 - namespace: "{{ helm_namespace }}" - name: another-chart - release_values: "{{ test_chart_values }}" - check_mode: true - register: _upgrade_2 - - - name: Assert that module raised a warning - assert: - that: - - _upgrade_2.changed - - _upgrade_2.warnings is not defined - always: - name: Remove chart directory - file: + ansible.builtin.file: path: "{{ test_chart_ref }}" state: absent ignore_errors: true @@ -324,6 +309,7 @@ wait: true ignore_errors: true -- include_tasks: reuse_values.yml +- ansible.builtin.include_tasks: reuse_values.yml -- include_tasks: reset_then_reuse_values.yml +- ansible.builtin.include_tasks: reset_then_reuse_values.yml + when: helm_version | string is ansible.builtin.version('3.8.0', '>') diff --git a/tests/integration/targets/helm_diff/tasks/reset_then_reuse_values.yml b/tests/integration/targets/helm_diff/tasks/reset_then_reuse_values.yml index 0de76eaa..43e9187c 100644 --- a/tests/integration/targets/helm_diff/tasks/reset_then_reuse_values.yml +++ b/tests/integration/targets/helm_diff/tasks/reset_then_reuse_values.yml @@ -1,6 +1,6 @@ --- - name: Create temporary directory for helm chart - tempfile: + ansible.builtin.tempfile: suffix: .helm state: directory register: helm_dir @@ -16,7 +16,8 @@ binary_path: "{{ helm_binary }}" state: present plugin_path: https://github.com/databus23/helm-diff - plugin_version: 3.9.14 + verify: false + plugin_version: "{{ helm_version | string is ansible.builtin.version('4.0.0', '>=') | ternary('3.14.0', '3.10.0') }}" - name: Copy test chart ansible.builtin.copy: @@ -58,7 +59,7 @@ register: helm_upgrade - name: Ensure task did not reported change - assert: + ansible.builtin.assert: that: - helm_upgrade is not changed @@ -75,7 +76,7 @@ register: helm_upgrade - name: Ensure task reported change - assert: + ansible.builtin.assert: that: - helm_upgrade is changed @@ -88,19 +89,24 @@ ignore_errors: true - name: Delete Helm folders - file: + ansible.builtin.file: path: /tmp/helm/ state: absent - name: Install old version of helm ansible.builtin.include_role: - name: install_helm + name: setup_helm vars: - helm_version: "v3.8.0" + setup_helm_version: "v3.8.0" + helm_install_path: "{{ helm_dir.path }}/helm_v3_8_0" + + - name: Set path to helm binary v3.8.0 + ansible.builtin.set_fact: + helm_binary_path_v3_8_0: "{{ helm_dir.path }}/helm_v3_8_0/helm" - name: Upgrade helm release (with reset_then_reuse_values=true) kubernetes.core.helm: - binary_path: "{{ helm_binary }}" + binary_path: "{{ helm_binary_path_v3_8_0 }}" chart_ref: "{{ test_chart_path }}" reuse_values: false reset_then_reuse_values: true @@ -112,25 +118,26 @@ ignore_errors: true - name: Debug - debug: + ansible.builtin.debug: var: helm_upgrade - name: Ensure warning for Helm version - assert: + ansible.builtin.assert: that: - helm_upgrade is failed - '"reset_then_reuse_values requires helm >= 3.14.0, current version is" in helm_upgrade.msg' - name: Install helm diff helm_plugin: - binary_path: "{{ helm_binary }}" + binary_path: "{{ helm_binary_path_v3_8_0 }}" state: present plugin_path: https://github.com/databus23/helm-diff plugin_version: "3.8.0" + verify: false - name: Upgrade helm release (with reset_then_reuse_values=true) kubernetes.core.helm: - binary_path: "{{ helm_binary }}" + binary_path: "{{ helm_binary_path_v3_8_0 }}" chart_ref: "{{ test_chart_path }}" reuse_values: false reset_then_reuse_values: true @@ -142,23 +149,23 @@ ignore_errors: true - name: Debug - debug: + ansible.builtin.debug: var: helm_upgrade - name: Ensure warning for Helm Diff version - assert: + ansible.builtin.assert: that: - helm_upgrade is failed - '"reset_then_reuse_values requires helm diff >= 3.9.12, current version is" in helm_upgrade.msg' always: - name: Delete Helm folders - file: + ansible.builtin.file: path: /tmp/helm/ state: absent - name: Remove temporary directory - file: + ansible.builtin.file: path: "{{ helm_dir.path }}" state: absent ignore_errors: true diff --git a/tests/integration/targets/helm_diff/tasks/reuse_values.yml b/tests/integration/targets/helm_diff/tasks/reuse_values.yml index 8962fe12..ffb95e49 100644 --- a/tests/integration/targets/helm_diff/tasks/reuse_values.yml +++ b/tests/integration/targets/helm_diff/tasks/reuse_values.yml @@ -1,6 +1,6 @@ --- - name: Create temporary directory for helm chart - tempfile: + ansible.builtin.tempfile: suffix: .helm state: directory register: helm_dir @@ -17,7 +17,8 @@ binary_path: "{{ helm_binary }}" state: present plugin_path: https://github.com/databus23/helm-diff - plugin_version: 3.9.4 + verify: false + plugin_version: "{{ helm_version | string is ansible.builtin.version('4.0.0', '>=') | ternary('3.14.0', '3.10.0') }}" - name: Copy test chart ansible.builtin.copy: @@ -50,7 +51,7 @@ register: helm_upgrade - name: Ensure task did not reported change - assert: + ansible.builtin.assert: that: - helm_upgrade is not changed @@ -66,7 +67,7 @@ register: helm_upgrade - name: Ensure task reported change - assert: + ansible.builtin.assert: that: - helm_upgrade is changed diff --git a/tests/integration/targets/helm_kubeconfig/defaults/main.yml b/tests/integration/targets/helm_kubeconfig/defaults/main.yml index 54f51267..f4449916 100644 --- a/tests/integration/targets/helm_kubeconfig/defaults/main.yml +++ b/tests/integration/targets/helm_kubeconfig/defaults/main.yml @@ -4,7 +4,4 @@ test_namespace: - "helm-in-memory-kubeconfig" - "helm-kubeconfig-with-ca-cert" - "helm-kubeconfig-with-insecure-skip-tls-verify" -helm_versions: - - v3.10.3 - - v3.16.4 - - v4.0.0 +helm_binary: helm diff --git a/tests/integration/targets/helm_kubeconfig/tasks/main.yml b/tests/integration/targets/helm_kubeconfig/tasks/main.yml index de7c170c..c307eb2c 100644 --- a/tests/integration/targets/helm_kubeconfig/tasks/main.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/main.yml @@ -1,5 +1,2 @@ --- - ansible.builtin.include_tasks: run_tests.yml - loop: "{{ helm_versions }}" - loop_control: - loop_var: helm_version diff --git a/tests/integration/targets/helm_kubeconfig/tasks/run_tests.yml b/tests/integration/targets/helm_kubeconfig/tasks/run_tests.yml index be199de2..04d84eb5 100644 --- a/tests/integration/targets/helm_kubeconfig/tasks/run_tests.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/run_tests.yml @@ -1,10 +1,6 @@ --- -- name: Run tests with helm version "{{ helm_version }}" +- name: Run tests block: - - name: "Install Helm" - ansible.builtin.include_role: - name: install_helm - - name: Test helm with in-memory kubeconfig ansible.builtin.include_tasks: "from_in_memory_kubeconfig.yml" diff --git a/tests/integration/targets/helm_oci_registry_progress/defaults/main.yml b/tests/integration/targets/helm_oci_registry_progress/defaults/main.yml index e6cb6c03..1e27bd95 100644 --- a/tests/integration/targets/helm_oci_registry_progress/defaults/main.yml +++ b/tests/integration/targets/helm_oci_registry_progress/defaults/main.yml @@ -1,8 +1,4 @@ --- -# Helm >= 4.2.1 is required for this test to be meaningful: that is the release which -# moved the OCI registry progress messages from stderr to stdout (helm/helm#32056). -helm_oci_version: v4.2.4 - helm_oci_namespace: helm-oci-registry-progress test_namespace: "{{ helm_oci_namespace }}" @@ -18,3 +14,4 @@ helm_oci_chart_version: 1.0.0+build.1 # A version without build metadata, to cover the case where the progress messages # happen to be valid YAML and so corrupt the parsed output silently. helm_oci_chart_version_plain: 1.0.1 +helm_binary: "helm" diff --git a/tests/integration/targets/helm_oci_registry_progress/meta/main.yml b/tests/integration/targets/helm_oci_registry_progress/meta/main.yml index 745901b7..e967fc13 100644 --- a/tests/integration/targets/helm_oci_registry_progress/meta/main.yml +++ b/tests/integration/targets/helm_oci_registry_progress/meta/main.yml @@ -2,3 +2,4 @@ dependencies: - remove_namespace - setup_helm_registry + - setup_helm_version diff --git a/tests/integration/targets/helm_oci_registry_progress/tasks/main.yml b/tests/integration/targets/helm_oci_registry_progress/tasks/main.yml index ab6ac5da..f494109c 100644 --- a/tests/integration/targets/helm_oci_registry_progress/tasks/main.yml +++ b/tests/integration/targets/helm_oci_registry_progress/tasks/main.yml @@ -12,15 +12,12 @@ # messages. Without the fix, the helm task below fails with # "could not find expected ':'". - name: Test OCI charts whose version contains build metadata +# Helm >= 4.2.1 is required for this test to be meaningful: that is the release which +# moved the OCI registry progress messages from stderr to stdout (helm/helm#32056). + when: helm_version | string is ansible.builtin.version('4.2.1', '>=') vars: chart_ref: "oci://{{ helm_oci_registry }}/{{ helm_oci_repo_path }}/{{ helm_oci_chart_name }}" block: - - name: "Install Helm {{ helm_oci_version }}" - ansible.builtin.include_role: - name: install_helm - vars: - helm_version: "{{ helm_oci_version }}" - - name: Create temporary directory to hold the chart ansible.builtin.tempfile: state: directory diff --git a/tests/integration/targets/helm_plain_http/.gitignore b/tests/integration/targets/helm_plain_http/.gitignore deleted file mode 100644 index 2ea79720..00000000 --- a/tests/integration/targets/helm_plain_http/.gitignore +++ /dev/null @@ -1 +0,0 @@ -redis* diff --git a/tests/integration/targets/helm_plain_http/defaults/main.yml b/tests/integration/targets/helm_plain_http/defaults/main.yml new file mode 100644 index 00000000..c3737230 --- /dev/null +++ b/tests/integration/targets/helm_plain_http/defaults/main.yml @@ -0,0 +1,12 @@ +--- +helm_binary: helm +setup_helm_version_binary_path: "{{ helm_binary }}" +test_namespace: helm-plain-http + +# Matches the plain-HTTP registry stood up by the setup_helm_registry role. +registry_host: "localhost:6035" +registry_username: testuser +registry_password: 'pass123!' +registry_repo_path: testing +chart_name: test-chart-plain-http +chart_version: "0.1.0" diff --git a/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/Chart.yaml b/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/Chart.yaml new file mode 100644 index 00000000..2a81b7c3 --- /dev/null +++ b/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: test-chart-plain-http +description: A minimal chart used to exercise plain_http against a plain-HTTP OCI registry +type: application +version: 0.1.0 +appVersion: "default" diff --git a/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/templates/configmap.yaml b/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/templates/configmap.yaml new file mode 100644 index 00000000..69bd24ed --- /dev/null +++ b/tests/integration/targets/helm_plain_http/files/test-chart-plain-http/templates/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-chart-plain-http-configmap +data: + myValue: test diff --git a/tests/integration/targets/helm_plain_http/inventory.ini b/tests/integration/targets/helm_plain_http/inventory.ini deleted file mode 100644 index 13bcbe25..00000000 --- a/tests/integration/targets/helm_plain_http/inventory.ini +++ /dev/null @@ -1,4 +0,0 @@ -[all] -helm-3.12.3 helm_version=v3.12.3 test_namespace=helm-plain-http-v3-12-3 tests_should_failed=true -helm-3.18.2 helm_version=v3.18.2 test_namespace=helm-plain-http-v3-18-2 tests_should_failed=false -helm-4.0.0 helm_version=v4.0.0 test_namespace=helm-plain-http-v4-0-0 tests_should_failed=false \ No newline at end of file diff --git a/tests/integration/targets/helm_plain_http/meta/main.yml b/tests/integration/targets/helm_plain_http/meta/main.yml new file mode 100644 index 00000000..e58347ab --- /dev/null +++ b/tests/integration/targets/helm_plain_http/meta/main.yml @@ -0,0 +1,5 @@ +--- +dependencies: + - setup_namespace + - setup_helm_registry + - setup_helm_version diff --git a/tests/integration/targets/helm_plain_http/playbooks/play.yaml b/tests/integration/targets/helm_plain_http/playbooks/play.yaml deleted file mode 100644 index 1ae7f3d7..00000000 --- a/tests/integration/targets/helm_plain_http/playbooks/play.yaml +++ /dev/null @@ -1,15 +0,0 @@ -- name: Run test for helm plain http option - hosts: all - gather_facts: true - strategy: free - - vars: - ansible_connection: local - ansible_python_interpreter: "{{ ansible_playbook_python }}" - chart_test_oci: "oci://registry-1.docker.io/bitnamicharts/redis" - - roles: - - role: setup_namespace - - tasks: - - ansible.builtin.include_tasks: tasks/test.yaml diff --git a/tests/integration/targets/helm_plain_http/playbooks/tasks/test.yaml b/tests/integration/targets/helm_plain_http/playbooks/tasks/test.yaml deleted file mode 100644 index 81e0bafc..00000000 --- a/tests/integration/targets/helm_plain_http/playbooks/tasks/test.yaml +++ /dev/null @@ -1,95 +0,0 @@ ---- -- name: Run test for helm - block: - - name: Create temporary directory to install chart In - ansible.builtin.tempfile: - state: directory - suffix: .helm - register: install_path - - - name: Install required helm version - ansible.builtin.include_role: - name: install_helm - vars: - helm_install_path: "{{ install_path.path }}" - - # helm - - name: Run helm with plain_http - kubernetes.core.helm: - binary_path: "{{ helm_binary }}" - chart_ref: "{{ chart_test_oci }}" - release_name: test-secure - release_namespace: "{{ test_namespace }}" - create_namespace: true - plain_http: true - register: install_chart - ignore_errors: true - - - name: Ensure module failed as expected - ansible.builtin.assert: - that: - - install_chart is failed - - '"plain_http requires helm >= 3.13.0" in install_chart.msg' - when: tests_should_failed | bool - - - name: Ensure the result command contains the expected option - ansible.builtin.assert: - that: - - install_chart is not failed - - '"--plain-http" in install_chart.command' - when: not (tests_should_failed | bool) - - # helm_pull - - name: Trying to download helm chart with option plain_http - kubernetes.core.helm_pull: - chart_ref: "{{ chart_test_oci }}" - destination: "{{ playbook_dir }}" - binary_path: "{{ helm_binary }}" - plain_http: true - register: pull_chart - ignore_errors: true - - - name: Ensure module failed as expected - ansible.builtin.assert: - that: - - pull_chart is failed - - '"plain_http requires helm >= 3.13.0" in pull_chart.msg' - when: tests_should_failed | bool - - - name: Ensure the result command contains the expected option - ansible.builtin.assert: - that: - - pull_chart is not failed - - '"--plain-http" in pull_chart.command' - when: not (tests_should_failed | bool) - - # helm_template - - name: Test helm render template - kubernetes.core.helm_template: - binary_path: "{{ helm_binary }}" - chart_ref: "{{ chart_test_oci }}" - output_dir: "{{ playbook_dir }}" - plain_http: true - register: template - ignore_errors: true - - - name: Ensure module failed as expected - ansible.builtin.assert: - that: - - template is failed - - '"plain_http requires helm >= 3.13.0" in template.msg' - when: tests_should_failed | bool - - - name: Ensure the result command contains the expected option - ansible.builtin.assert: - that: - - template is not failed - - '"--plain-http" in template.command' - when: not (tests_should_failed | bool) - - always: - - name: Delete temporary file - ansible.builtin.file: - path: "{{ install_path.path }}" - state: absent - ignore_errors: true diff --git a/tests/integration/targets/helm_plain_http/runme.sh b/tests/integration/targets/helm_plain_http/runme.sh deleted file mode 100755 index 3cfa5280..00000000 --- a/tests/integration/targets/helm_plain_http/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbooks/play.yaml -i inventory.ini "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_plain_http/tasks/main.yml b/tests/integration/targets/helm_plain_http/tasks/main.yml new file mode 100644 index 00000000..63f1d387 --- /dev/null +++ b/tests/integration/targets/helm_plain_http/tasks/main.yml @@ -0,0 +1,167 @@ +--- +- name: Test plain_http against a plain-HTTP OCI registry + vars: + plain_http_supported: "{{ helm_version | string is ansible.builtin.version('3.13.0', '>=') }}" + chart_ref_oci: "oci://{{ registry_host }}/{{ registry_repo_path }}/{{ chart_name }}" + block: + - name: Create a temporary directory to hold the chart + ansible.builtin.tempfile: + state: directory + suffix: .chart + register: _tmpd + + # helm < 3.13.0 cannot talk to a plain-HTTP OCI registry: the modules reject + # plain_http before issuing any helm command, so no chart has to be present. + - name: Ensure plain_http is rejected on unsupported helm versions + when: not (plain_http_supported | bool) + block: + - name: Attempt helm install with plain_http + kubernetes.core.helm: + binary_path: "{{ helm_binary }}" + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + release_name: test-secure + release_namespace: "{{ test_namespace }}" + create_namespace: true + plain_http: true + register: install_chart + ignore_errors: true + + - name: Ensure helm failed with the version error + ansible.builtin.assert: + that: + - install_chart is failed + - '"plain_http requires helm >= 3.13.0" in install_chart.msg' + + - name: Attempt helm_pull with plain_http + kubernetes.core.helm_pull: + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + destination: "{{ _tmpd.path }}" + binary_path: "{{ helm_binary }}" + plain_http: true + register: pull_chart + ignore_errors: true + + - name: Ensure helm_pull failed with the version error + ansible.builtin.assert: + that: + - pull_chart is failed + - '"plain_http requires helm >= 3.13.0" in pull_chart.msg' + + - name: Attempt helm_template with plain_http + kubernetes.core.helm_template: + binary_path: "{{ helm_binary }}" + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + plain_http: true + register: template + ignore_errors: true + + - name: Ensure helm_template failed with the version error + ansible.builtin.assert: + that: + - template is failed + - '"plain_http requires helm >= 3.13.0" in template.msg' + + # helm >= 3.13.0 exercises plain HTTP end to end against the registry stood up + # by the setup_helm_registry role, so the assertions prove the flag actually + # reaches a plain-HTTP registry rather than just appearing in the command. + - name: Exercise plain_http end to end + when: plain_http_supported | bool + block: + - name: Copy the test chart + ansible.builtin.copy: + src: "{{ chart_name }}" + dest: "{{ _tmpd.path }}/" + + - name: Push the chart to the plain-HTTP registry + ansible.builtin.include_role: + name: push_to_helm_registry + vars: + chart_local_path: "{{ _tmpd.path }}/{{ chart_name }}" + chart_repo_path: "{{ registry_repo_path }}" + helm_binary_path: "{{ helm_binary }}" + + - name: Log into the helm registry + ansible.builtin.shell: >- + echo '{{ registry_password }}' | {{ helm_binary }} registry login + -u {{ registry_username }} --password-stdin {{ registry_host }} + {{ helm_version | string is ansible.builtin.version('3.18.0', '>=') | ternary('--plain-http', '') }} + + - name: Install the chart over plain HTTP + kubernetes.core.helm: + binary_path: "{{ helm_binary }}" + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + release_name: test-secure + release_namespace: "{{ test_namespace }}" + create_namespace: true + plain_http: true + register: install_chart + + - name: Ensure the release installed over plain HTTP + ansible.builtin.assert: + that: + - install_chart is changed + - '"--plain-http" in install_chart.command' + + - name: Pull the chart over plain HTTP + kubernetes.core.helm_pull: + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + destination: "{{ _tmpd.path }}" + binary_path: "{{ helm_binary }}" + plain_http: true + register: pull_chart + + - name: Ensure the chart was pulled over plain HTTP + ansible.builtin.assert: + that: + - pull_chart is not failed + - '"--plain-http" in pull_chart.command' + + - name: Render the chart over plain HTTP + kubernetes.core.helm_template: + binary_path: "{{ helm_binary }}" + chart_ref: "{{ chart_ref_oci }}" + chart_version: "{{ chart_version }}" + plain_http: true + register: template + + - name: Ensure the chart rendered over plain HTTP + ansible.builtin.assert: + that: + - template is not failed + - '"--plain-http" in template.command' + - "'kind: ConfigMap' in template.stdout" + + always: + - name: Uninstall the release + kubernetes.core.helm: + binary_path: "{{ helm_binary }}" + release_name: test-secure + release_namespace: "{{ test_namespace }}" + state: absent + when: plain_http_supported | bool + ignore_errors: true + + - name: Remove the test namespace + kubernetes.core.k8s: + api_version: v1 + kind: Namespace + name: "{{ test_namespace }}" + state: absent + wait: true + ignore_errors: true + + - name: Log out of the helm registry + ansible.builtin.command: "{{ helm_binary }} registry logout {{ registry_host }}" + when: plain_http_supported | bool + ignore_errors: true + + - name: Remove the temporary directory + ansible.builtin.file: + path: "{{ _tmpd.path }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/helm_plugin/defaults/main.yml b/tests/integration/targets/helm_plugin/defaults/main.yml index 60d628d5..5fe14da9 100644 --- a/tests/integration/targets/helm_plugin/defaults/main.yml +++ b/tests/integration/targets/helm_plugin/defaults/main.yml @@ -1,2 +1,2 @@ --- -helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm" +helm_binary: "helm" diff --git a/tests/integration/targets/helm_plugin/playbook.yaml b/tests/integration/targets/helm_plugin/playbook.yaml deleted file mode 100644 index 2b50d19c..00000000 --- a/tests/integration/targets/helm_plugin/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- connection: local - gather_facts: true - hosts: localhost - - roles: - - helm_plugin diff --git a/tests/integration/targets/helm_plugin/runme.sh b/tests/integration/targets/helm_plugin/runme.sh deleted file mode 100755 index 02ef1460..00000000 --- a/tests/integration/targets/helm_plugin/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_plugin/tasks/main.yml b/tests/integration/targets/helm_plugin/tasks/main.yml index 1ea01e04..c525e6a5 100644 --- a/tests/integration/targets/helm_plugin/tasks/main.yml +++ b/tests/integration/targets/helm_plugin/tasks/main.yml @@ -1,8 +1,3 @@ --- - name: Run tests - include_tasks: run_tests.yml - loop_control: - loop_var: helm_version - with_items: - - "v3.17.0" - - "v4.0.0" + ansible.builtin.include_tasks: run_tests.yml diff --git a/tests/integration/targets/helm_plugin/tasks/run_tests.yml b/tests/integration/targets/helm_plugin/tasks/run_tests.yml index fd86a2de..dcf28e37 100644 --- a/tests/integration/targets/helm_plugin/tasks/run_tests.yml +++ b/tests/integration/targets/helm_plugin/tasks/run_tests.yml @@ -1,8 +1,4 @@ --- -- name: "Install {{ helm_version }}" - include_role: - name: install_helm - - block: - name: Install env plugin in check mode helm_plugin: @@ -13,7 +9,7 @@ register: check_install_env check_mode: true - - assert: + - ansible.builtin.assert: that: - check_install_env.changed @@ -25,7 +21,7 @@ verify: false register: install_env - - assert: + - ansible.builtin.assert: that: - install_env.changed @@ -34,7 +30,7 @@ binary_path: "{{ helm_binary }}" register: plugin_info - - assert: + - ansible.builtin.assert: that: - plugin_info.plugin_list is defined @@ -46,7 +42,7 @@ verify: false register: install_env - - assert: + - ansible.builtin.assert: that: - not install_env.changed @@ -59,7 +55,7 @@ register: check_uninstall_env check_mode: true - - assert: + - ansible.builtin.assert: that: - check_uninstall_env.changed @@ -70,7 +66,7 @@ plugin_name: env register: uninstall_env - - assert: + - ansible.builtin.assert: that: - uninstall_env.changed @@ -81,7 +77,7 @@ plugin_name: env register: uninstall_env - - assert: + - ansible.builtin.assert: that: - not uninstall_env.changed @@ -95,7 +91,7 @@ # https://github.com/ansible-collections/community.kubernetes/issues/399 - block: - name: Copy required plugin files - copy: + ansible.builtin.copy: src: "files/sample_plugin" dest: "/tmp/helm_plugin_test/" @@ -107,7 +103,7 @@ register: sample_plugin_output - name: Assert that sample_plugin is installed or not - assert: + ansible.builtin.assert: that: - sample_plugin_output.changed @@ -117,13 +113,13 @@ register: r - name: Set sample_plugin version - set_fact: + ansible.builtin.set_fact: plugin_version: "{{ ( r.plugin_list | selectattr('name', 'equalto', plugin_name) | list )[0].version }}" vars: plugin_name: "sample_plugin" - name: Assert if sample_plugin with multiline comment is installed - assert: + ansible.builtin.assert: that: - plugin_version == "0.0.1" always: @@ -156,7 +152,7 @@ register: plugin_list - name: assert that unittest has been installed with specified version - assert: + ansible.builtin.assert: that: - plugin_list.plugin_list[0].version == "1.0.1" @@ -169,7 +165,7 @@ check_mode: true - name: Assert that module reported change while running in check mode - assert: + ansible.builtin.assert: that: - _update_checkmode.changed - '"Updated plugin: unittest" not in _update_checkmode.stdout' @@ -181,8 +177,8 @@ state: latest register: _update - - name: assert update was performed - assert: + - name: Assert update was performed + ansible.builtin.assert: that: - _update.changed - '"Updated plugin: unittest" in _update.stdout' diff --git a/tests/integration/targets/helm_pull/defaults/main.yml b/tests/integration/targets/helm_pull/defaults/main.yml new file mode 100644 index 00000000..d1b937e7 --- /dev/null +++ b/tests/integration/targets/helm_pull/defaults/main.yml @@ -0,0 +1,2 @@ +--- +helm_binary: helm diff --git a/tests/integration/targets/helm_pull/meta/main.yml b/tests/integration/targets/helm_pull/meta/main.yml new file mode 100644 index 00000000..3ec1f599 --- /dev/null +++ b/tests/integration/targets/helm_pull/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_helm_version diff --git a/tests/integration/targets/helm_pull/playbook.yaml b/tests/integration/targets/helm_pull/playbook.yaml deleted file mode 100644 index 43c5e6d4..00000000 --- a/tests/integration/targets/helm_pull/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- connection: local - gather_facts: true - hosts: localhost - - roles: - - helm_pull diff --git a/tests/integration/targets/helm_pull/runme.sh b/tests/integration/targets/helm_pull/runme.sh deleted file mode 100755 index 02ef1460..00000000 --- a/tests/integration/targets/helm_pull/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_pull/tasks/main.yml b/tests/integration/targets/helm_pull/tasks/main.yml index 8849c344..8a9bf4d5 100644 --- a/tests/integration/targets/helm_pull/tasks/main.yml +++ b/tests/integration/targets/helm_pull/tasks/main.yml @@ -1,101 +1,83 @@ --- -- name: Define helm versions to test - set_fact: - helm_versions: - - 3.8.0 - - 3.1.0 - - 3.0.0 - - 4.0.0 - - block: - name: Create temp directory for helm tests - tempfile: + ansible.builtin.tempfile: state: directory register: tmpdir - name: Set temp directory fact - set_fact: + ansible.builtin.set_fact: temp_dir: "{{ tmpdir.path }}" - - set_fact: - destination: "{{ temp_dir }}" - - - name: Install Helm versions - ansible.builtin.include_role: - name: install_helm - loop: "{{ helm_versions }}" - vars: - helm_version: "v{{ item }}" - helm_install_path: "{{ temp_dir }}/{{ item }}" - # Testing helm pull with helm version == 3.0.0 - - block: + - name: Run test with helm version '3.0.0' + when: helm_version | string is ansible.builtin.version('3.0.0', "==") + block: - name: Download chart using chart_ssl_cert_file helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_ssl_cert_file: ssl_cert_file ignore_errors: true check_mode: true register: _result - - name: assert that module failed with proper message - assert: + - name: Assert that module failed with proper message + ansible.builtin.assert: that: - _result is failed - _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 helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_ssl_key_file: ssl_key_file ignore_errors: true check_mode: true register: _result - name: assert that module failed with proper message - assert: + ansible.builtin.assert: that: - _result is failed - _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 helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_ca_cert: ca_cert_file ignore_errors: true check_mode: true register: _result - - name: assert that module failed with proper message - assert: + - name: Assert that module failed with proper message + ansible.builtin.assert: that: - _result is failed - _result.msg == "Parameter chart_ca_cert requires helm >= 3.1.0, current version is 3.0.0" - vars: - helm_path: "{{ temp_dir }}/3.0.0/helm" - # Testing helm pull with helm version == 3.1.0 - - block: + - name: Run test with helm version '3.1.0' + when: helm_version | string is ansible.builtin.version('3.1.0', "==") + block: - name: Download chart using chart_ssl_cert_file, chart_ca_cert, chart_ssl_key_file helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_ssl_cert_file: ssl_cert_file chart_ssl_key_file: ssl_key_file chart_ca_cert: ca_cert_file check_mode: true register: _result - - name: assert that module failed with proper message - assert: + - name: Assert that module failed with proper message + ansible.builtin.assert: that: - _result is changed - '"--ca-file ca_cert_file" in _result.command' @@ -104,32 +86,31 @@ - name: Download chart using skip_tls_certs_check helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" skip_tls_certs_check: true ignore_errors: true check_mode: true register: _result - - name: assert that module failed with proper message - assert: + - name: Assert that module failed with proper message + ansible.builtin.assert: that: - _result is failed - _result.msg == "Parameter skip_tls_certs_check requires helm >= 3.3.0, current version is 3.1.0" - vars: - helm_path: "{{ temp_dir }}/3.1.0/helm" - # Testing helm pull with helm version == 3.8.0 - - block: + - name: Run test with helm version '3.8.0' + when: helm_version | string is ansible.builtin.version('3.8.0', "==") + block: # Test options chart_version, verify, pass-credentials, provenance, untar_chart # skip_tls_certs_check, repo_url, repo_username, repo_password - name: Testing chart version helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: redis - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_version: "0.2.1" verify_chart: true pass_credentials: true @@ -143,7 +124,8 @@ check_mode: true register: _result - - assert: + - name: Validate module results + ansible.builtin.assert: that: - _result is changed - '"--version 0.2.1" in _result.command' @@ -154,24 +136,24 @@ - '"--insecure-skip-tls-verify" in _result.command' - '"--repo https://charts.bitnami.com/bitnami" in _result.command' - '"--username ansible" in _result.command' - - '"--password ***" in _result.command' + - '"--password " in _result.command' # can be followed by '***' or '$REDACTED$' - '"--keyring pubring.gpg" in _result.command' - '"Module did not set no_log for pass_credentials" not in _result.stderr' - name: Download chart using chart_ref helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz - destination: "{{ destination }}" + destination: "{{ temp_dir }}" register: _result - name: Check chart on local filesystem - stat: - path: "{{ destination }}/grafana-5.6.0.tgz" + ansible.builtin.stat: + path: "{{ temp_dir }}/grafana-5.6.0.tgz" register: _chart - name: Validate that chart was downloaded - assert: + ansible.builtin.assert: that: - _result is changed - _chart.stat.exists @@ -179,19 +161,19 @@ - name: Download chart using untar_chart helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}" + destination: "{{ temp_dir }}" untar_chart: true register: _result - name: Check chart on local filesystem - stat: - path: "{{ destination }}/redis" + ansible.builtin.stat: + path: "{{ temp_dir }}/redis" register: _chart - name: Validate that chart was downloaded - assert: + ansible.builtin.assert: that: - _result is changed - _chart.stat.exists @@ -200,22 +182,22 @@ # Test idempotency with tarred chart - name: Download chart with version (first time) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_version: "24.1.0" register: _result_first - name: Download chart with version (second time - should be idempotent) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_version: "24.1.0" register: _result_second - name: Validate idempotency for tarred chart - assert: + ansible.builtin.assert: that: - _result_first is changed - _result_second is not changed @@ -223,81 +205,77 @@ # Test force parameter with tarred chart - name: Download chart with force=true (should always download) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}" + destination: "{{ temp_dir }}" chart_version: "24.1.0" force: true register: _result_force - name: Validate force parameter causes download - assert: + ansible.builtin.assert: that: - _result_force is changed # Test idempotency with untarred chart in the separate folder - name: Create separate directory for untar test under {{ temp_dir }} ansible.builtin.file: - path: "{{ destination }}/untar_test" + path: "{{ temp_dir }}/untar_test" state: directory mode: '0755' - name: Download and untar chart (first time) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}/untar_test" + destination: "{{ temp_dir }}/untar_test" chart_version: "24.0.0" untar_chart: true register: _result_untar_first - name: Download and untar chart (second time - should be idempotent) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}/untar_test" + destination: "{{ temp_dir }}/untar_test" chart_version: "24.0.0" untar_chart: true register: _result_untar_second - name: Validate idempotency for untarred chart - assert: + ansible.builtin.assert: that: - _result_untar_first is changed - _result_untar_second is not changed - name: Download and untar chart with force=true (should remove existing directory and re-extract) helm_pull: - binary_path: "{{ helm_path }}" + binary_path: "{{ helm_binary }}" chart_ref: "oci://registry-1.docker.io/bitnamicharts/redis" - destination: "{{ destination }}/untar_test" + destination: "{{ temp_dir }}/untar_test" chart_version: "24.0.0" untar_chart: true force: true register: _result_untar_force - name: Validate first force extraction works - assert: + ansible.builtin.assert: that: - _result_untar_force is changed - name: Verify chart directory still exists after force re-extraction - stat: - path: "{{ destination }}/untar_test/redis" + ansible.builtin.stat: + path: "{{ temp_dir }}/untar_test/redis" register: _chart_after_force - name: Validate chart directory exists - assert: + ansible.builtin.assert: that: - _chart_after_force.stat.exists - _chart_after_force.stat.isdir - vars: - helm_path: "{{ temp_dir }}/3.8.0/helm" - - always: - name: Delete temp directory - file: + ansible.builtin.file: state: absent path: "{{ temp_dir }}" diff --git a/tests/integration/targets/helm_registry_auth/defaults/main.yaml b/tests/integration/targets/helm_registry_auth/defaults/main.yaml index fcb80984..cb563c75 100644 --- a/tests/integration/targets/helm_registry_auth/defaults/main.yaml +++ b/tests/integration/targets/helm_registry_auth/defaults/main.yaml @@ -7,7 +7,4 @@ wrong_password: 'WrongPassword' registry_name: oci_registry registry_port: 5002 test_chart: https://github.com/grafana/helm-charts/releases/download/k8s-monitoring-1.6.8/k8s-monitoring-1.6.8.tgz -helm_versions: - - v3.17.0 - - v3.20.0 - - v4.0.0 +helm_binary: helm diff --git a/tests/integration/targets/helm_registry_auth/meta/main.yml b/tests/integration/targets/helm_registry_auth/meta/main.yml new file mode 100644 index 00000000..3ec1f599 --- /dev/null +++ b/tests/integration/targets/helm_registry_auth/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_helm_version diff --git a/tests/integration/targets/helm_registry_auth/playbook.yaml b/tests/integration/targets/helm_registry_auth/playbook.yaml deleted file mode 100644 index 6444271a..00000000 --- a/tests/integration/targets/helm_registry_auth/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Test helm_registry_auth module - hosts: localhost - connection: local - gather_facts: true - roles: - - helm_registry_auth diff --git a/tests/integration/targets/helm_registry_auth/runme.sh b/tests/integration/targets/helm_registry_auth/runme.sh deleted file mode 100755 index 29fda1c9..00000000 --- a/tests/integration/targets/helm_registry_auth/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" diff --git a/tests/integration/targets/helm_registry_auth/tasks/main.yml b/tests/integration/targets/helm_registry_auth/tasks/main.yml index f33778fc..8d35c533 100644 --- a/tests/integration/targets/helm_registry_auth/tasks/main.yml +++ b/tests/integration/targets/helm_registry_auth/tasks/main.yml @@ -44,9 +44,6 @@ - name: Run tests ansible.builtin.include_tasks: run_tests.yml - loop: "{{ helm_versions }}" - loop_control: - loop_var: helm_version always: - name: Stop and remove the registry diff --git a/tests/integration/targets/helm_registry_auth/tasks/run_tests.yml b/tests/integration/targets/helm_registry_auth/tasks/run_tests.yml index 51c33627..abc1b764 100644 --- a/tests/integration/targets/helm_registry_auth/tasks/run_tests.yml +++ b/tests/integration/targets/helm_registry_auth/tasks/run_tests.yml @@ -1,9 +1,5 @@ --- - block: - - name: Install helm versions - ansible.builtin.include_role: - name: install_helm - # - name: Test the registry with correct credentials to ensure that the registry is running # ansible.builtin.shell: >- # echo {{ password | quote }} | {{ helm_binary }} registry login localhost:{{ registry_port }} @@ -31,7 +27,7 @@ # Helm < 4.2.1 prints success messages to stderr (https://github.com/helm/helm/issues/13464), # Helm >= 4.2.1 moves them to stdout (https://github.com/helm/helm/pull/32056). # Check both streams to stay version-agnostic. - assert: + ansible.builtin.assert: that: - "'Login Succeeded' in _helm_registry_auth_correct.stdout_lines + _helm_registry_auth_correct.stderr_lines" - password not in _helm_registry_auth_correct.command @@ -48,7 +44,7 @@ # Helm < 4.2.1 prints success messages to stderr (https://github.com/helm/helm/issues/13464), # Helm >= 4.2.1 moves them to stdout (https://github.com/helm/helm/pull/32056). # Check both streams to stay version-agnostic. - assert: + ansible.builtin.assert: that: "'Pushed: localhost:' + registry_port | string + '/test/k8s-monitoring' in _save_chart.stdout + _save_chart.stderr" - name: Test logout @@ -62,7 +58,7 @@ # Helm < 4.2.1 prints success messages to stderr (https://github.com/helm/helm/issues/13464), # Helm >= 4.2.1 moves them to stdout (https://github.com/helm/helm/pull/32056). # Check both streams to stay version-agnostic. - assert: + ansible.builtin.assert: that: "'Removing login credentials' in _helm_registry_auth_logout.stdout + _helm_registry_auth_logout.stderr" - name: Ensure that not able to push to the registry @@ -79,7 +75,7 @@ - "_save_chart.rc != 0" - name: Test idempotency of logout with helm < 3.18.0 - when: helm_version is ansible.builtin.version('v3.18.0', '<') + when: helm_version | string is ansible.builtin.version('3.18.0', '<') block: - name: Test logout idempotency diff --git a/tests/integration/targets/helm_repository/defaults/main.yml b/tests/integration/targets/helm_repository/defaults/main.yml index c6bf63a3..e214f12f 100644 --- a/tests/integration/targets/helm_repository/defaults/main.yml +++ b/tests/integration/targets/helm_repository/defaults/main.yml @@ -1,5 +1,3 @@ --- chart_test_repo: "https://kubernetes.github.io/ingress-nginx" -helm_versions: - - v3.20.0 - - v4.0.0 +helm_binary: helm diff --git a/tests/integration/targets/helm_repository/playbook.yaml b/tests/integration/targets/helm_repository/playbook.yaml deleted file mode 100644 index f2a56a7b..00000000 --- a/tests/integration/targets/helm_repository/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- connection: local - gather_facts: true - hosts: localhost - - roles: - - helm_repository diff --git a/tests/integration/targets/helm_repository/runme.sh b/tests/integration/targets/helm_repository/runme.sh deleted file mode 100755 index 02ef1460..00000000 --- a/tests/integration/targets/helm_repository/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_repository/tasks/main.yml b/tests/integration/targets/helm_repository/tasks/main.yml index bd538a42..5d4102a3 100644 --- a/tests/integration/targets/helm_repository/tasks/main.yml +++ b/tests/integration/targets/helm_repository/tasks/main.yml @@ -1,6 +1,3 @@ --- - name: Run test for helm_repository module ansible.builtin.include_tasks: run_tests.yml - loop: "{{ helm_versions }}" - loop_control: - loop_var: helm_version diff --git a/tests/integration/targets/helm_repository/tasks/run_tests.yml b/tests/integration/targets/helm_repository/tasks/run_tests.yml index 4476fc2e..a702d9e5 100644 --- a/tests/integration/targets/helm_repository/tasks/run_tests.yml +++ b/tests/integration/targets/helm_repository/tasks/run_tests.yml @@ -1,8 +1,4 @@ --- -- name: "Install helm version {{ helm_version }}" - ansible.builtin.include_role: - name: install_helm - - name: "Ensure test_helm_repo doesn't exist" helm_repository: binary_path: "{{ helm_binary }}" @@ -17,7 +13,7 @@ register: repository - name: Assert that test_helm_repo repository is added - assert: + ansible.builtin.assert: that: - repository is changed - '"--insecure-skip-tls-verify" not in repository.command' @@ -30,7 +26,7 @@ register: repository - name: Assert idempotency - assert: + ansible.builtin.assert: that: - repository is not changed @@ -43,7 +39,7 @@ ignore_errors: true - name: Assert that adding repository with the same name failed - assert: + ansible.builtin.assert: that: - repository_errors is failed @@ -56,7 +52,7 @@ register: repository - name: Assert that test_helm_repo repository is changed - assert: + ansible.builtin.assert: that: - repository is changed @@ -68,7 +64,7 @@ register: repository - name: Assert that test_helm_repo repository is removed - assert: + ansible.builtin.assert: that: - repository is changed @@ -80,7 +76,7 @@ register: repository - name: Assert idempotency - assert: + ansible.builtin.assert: that: - repository is not changed @@ -93,7 +89,7 @@ register: repository - name: Assert that repository added and flag set - assert: + ansible.builtin.assert: that: - repository is changed - '"--insecure-skip-tls-verify" in repository.command' diff --git a/tests/integration/targets/helm_set_values/defaults/main.yml b/tests/integration/targets/helm_set_values/defaults/main.yml index 6b710808..f28703ba 100644 --- a/tests/integration/targets/helm_set_values/defaults/main.yml +++ b/tests/integration/targets/helm_set_values/defaults/main.yml @@ -1,5 +1,3 @@ --- helm_namespace: helm-set-values -helm_versions: - - v3.10.3 - - v4.0.0 +helm_binary: helm diff --git a/tests/integration/targets/helm_set_values/meta/main.yml b/tests/integration/targets/helm_set_values/meta/main.yml index 10d989e7..2e3ba2fa 100644 --- a/tests/integration/targets/helm_set_values/meta/main.yml +++ b/tests/integration/targets/helm_set_values/meta/main.yml @@ -1,4 +1,3 @@ --- dependencies: - remove_namespace - - install_helm diff --git a/tests/integration/targets/helm_set_values/playbook.yaml b/tests/integration/targets/helm_set_values/playbook.yaml deleted file mode 100644 index 5d3109d2..00000000 --- a/tests/integration/targets/helm_set_values/playbook.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- connection: local - gather_facts: true - hosts: localhost - - roles: - - helm_set_values diff --git a/tests/integration/targets/helm_set_values/runme.sh b/tests/integration/targets/helm_set_values/runme.sh deleted file mode 100755 index 02ef1460..00000000 --- a/tests/integration/targets/helm_set_values/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_CALLBACKS_ENABLED=profile_tasks -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yaml "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_set_values/tasks/main.yml b/tests/integration/targets/helm_set_values/tasks/main.yml index cee51166..d7110a00 100644 --- a/tests/integration/targets/helm_set_values/tasks/main.yml +++ b/tests/integration/targets/helm_set_values/tasks/main.yml @@ -1,4 +1,4 @@ -- name: Install helm using set_values parameters +- name: Install helm chart using set_values parameters helm: binary_path: "{{ helm_binary }}" chart_ref: oci://registry-1.docker.io/bitnamicharts/mariadb @@ -18,7 +18,7 @@ register: user_values - name: Assert that release was created with user-defined variables - assert: + ansible.builtin.assert: that: - '"phase" in user_values.status["release_values"]' - '"versioned" in user_values.status["release_values"]' @@ -27,16 +27,15 @@ - block: - name: create temporary file to save values in - tempfile: + ansible.builtin.tempfile: suffix: .yml register: ymlfile - ansible.builtin.include_tasks: run_tests.yml - loop: "{{ helm_versions }}" always: - name: Delete temporary file - file: + ansible.builtin.file: state: absent path: "{{ ymlfile.path }}" ignore_errors: true diff --git a/tests/integration/targets/helm_set_values/tasks/run_tests.yml b/tests/integration/targets/helm_set_values/tasks/run_tests.yml index 31c5ace7..12af64a9 100644 --- a/tests/integration/targets/helm_set_values/tasks/run_tests.yml +++ b/tests/integration/targets/helm_set_values/tasks/run_tests.yml @@ -1,16 +1,9 @@ --- -# install chart using set_values and release_values -- name: 'Install helm binary (> 3.10.0) requires to use set-json (helm_version={{ item }})' - include_role: - name: install_helm - vars: - helm_version: "{{ item }}" - -- name: Install helm using set_values parameters +- name: Install helm chart using set_values parameters helm: binary_path: "{{ helm_binary }}" chart_ref: oci://registry-1.docker.io/bitnamicharts/apache - release_name: 'test-apache-{{ item }}' + release_name: 'test-apache' release_namespace: "{{ helm_namespace }}" create_namespace: true set_values: @@ -22,12 +15,12 @@ - name: Get release info helm_info: binary_path: "{{ helm_binary }}" - release_name: 'test-apache-{{ item }}' + release_name: 'test-apache' release_namespace: "{{ helm_namespace }}" register: values - name: Assert that release was created with user-defined variables - assert: + ansible.builtin.assert: that: - values.status["release_values"].replicaCount == 3 - values.status["release_values"].master.image.registry == "docker.io" @@ -35,8 +28,8 @@ - values.status["release_values"].master.image.tag == "2.4.54-debian-11-r74" # install chart using set_values and values_files -- name: copy content into values file - copy: +- name: Copy content into values file + ansible.builtin.copy: content: | --- mode: distributed @@ -46,7 +39,7 @@ helm: binary_path: "{{ helm_binary }}" chart_ref: oci://registry-1.docker.io/bitnamicharts/minio - release_name: 'test-minio-{{ item }}' + release_name: 'test-minio' release_namespace: "{{ helm_namespace }}" create_namespace: true set_values: @@ -57,12 +50,12 @@ - name: Get release info helm_info: binary_path: "{{ helm_binary }}" - release_name: 'test-minio-{{ item }}' + release_name: 'test-minio' release_namespace: "{{ helm_namespace }}" register: values - name: Assert that release was created with user-defined variables - assert: + ansible.builtin.assert: that: - values.status["release_values"].mode == "distributed" - values.status["release_values"].disableWebUI is true diff --git a/tests/integration/targets/helm_uninstall/aliases b/tests/integration/targets/helm_uninstall/aliases new file mode 100644 index 00000000..52a8c44a --- /dev/null +++ b/tests/integration/targets/helm_uninstall/aliases @@ -0,0 +1,3 @@ +time=40 +helm +helm_info diff --git a/tests/integration/targets/helm_uninstall/defaults/main.yml b/tests/integration/targets/helm_uninstall/defaults/main.yml new file mode 100644 index 00000000..21df7fdd --- /dev/null +++ b/tests/integration/targets/helm_uninstall/defaults/main.yml @@ -0,0 +1,3 @@ +--- +helm_binary: helm +helm_namespace: helm-uninstall diff --git a/tests/integration/targets/helm/library/helm_test_pending.py b/tests/integration/targets/helm_uninstall/library/helm_test_pending.py similarity index 100% rename from tests/integration/targets/helm/library/helm_test_pending.py rename to tests/integration/targets/helm_uninstall/library/helm_test_pending.py diff --git a/tests/integration/targets/helm_uninstall/meta/main.yml b/tests/integration/targets/helm_uninstall/meta/main.yml new file mode 100644 index 00000000..42770dfd --- /dev/null +++ b/tests/integration/targets/helm_uninstall/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - remove_namespace + - setup_helm_version diff --git a/tests/integration/targets/helm_uninstall/tasks/main.yml b/tests/integration/targets/helm_uninstall/tasks/main.yml new file mode 100644 index 00000000..6696570e --- /dev/null +++ b/tests/integration/targets/helm_uninstall/tasks/main.yml @@ -0,0 +1,90 @@ +- 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" + chart_name_pending: "test-uninstall-pending-release" + block: + + - name: Install chart + helm: + binary_path: "{{ helm_binary }}" + name: "{{ chart_name }}" + chart_ref: "{{ chart_source }}" + namespace: "{{ helm_namespace }}" + create_namespace: true + + - name: Delete chart with wait + helm: + state: absent + binary_path: "{{ helm_binary }}" + name: "{{ chart_name }}" + namespace: "{{ helm_namespace }}" + wait: true + register: uninstall + + - name: Assert chart was uninstalled + ansible.builtin.assert: + that: + - uninstall is changed + + - when: helm_version | string is ansible.builtin.version('4.0.0', '<') + block: + - name: Install Helm v4 + ansible.builtin.include_role: + name: setup_helm + vars: + setup_helm_version: v4.0.0 + + - name: Install chart + helm: + binary_path: "{{ setup_helm_binary_path }}" + name: "{{ chart_name }}" + chart_ref: "{{ chart_source }}" + namespace: "{{ helm_namespace }}" + create_namespace: true + + - name: Uninstall chart again using recent version + helm: + state: absent + binary_path: "{{ setup_helm_binary_path }}" + name: "{{ chart_name }}" + namespace: "{{ helm_namespace }}" + wait: true + register: uninstall + + # Test uninstall chart release with 'pending-install' status + - name: Create chart release with 'pending-install' status + helm_test_pending: + binary_path: "{{ setup_helm_binary_path }}" + chart_ref: "{{ chart_source }}" + chart_release: "{{ chart_name_pending }}" + chart_release_namespace: "{{ helm_namespace }}" + + - name: Uninstall chart release with 'pending-install' status + helm: + binary_path: "{{ setup_helm_binary_path }}" + release_name: "{{ chart_name_pending }}" + namespace: "{{ helm_namespace }}" + release_state: absent + register: _uninstall + + - name: Get Helm release details + helm_info: + binary_path: "{{ setup_helm_binary_path }}" + release_namespace: "{{ helm_namespace }}" + release_state: pending + release_name: "{{ chart_name_pending }}" + register: _info + + - name: Assert release does not exist anymore + ansible.builtin.assert: + that: + - _uninstall is changed + - _info.status is undefined + + always: + - name: Remove namespace + k8s: + kind: Namespace + name: "{{ helm_namespace }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/helm_v3_15_4/aliases b/tests/integration/targets/helm_v3_15_4/aliases deleted file mode 100644 index a80cfed0..00000000 --- a/tests/integration/targets/helm_v3_15_4/aliases +++ /dev/null @@ -1,4 +0,0 @@ -helm -helm_template -helm_info -helm_repository \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_15_4/inventory.ini b/tests/integration/targets/helm_v3_15_4/inventory.ini deleted file mode 100644 index 6bf36611..00000000 --- a/tests/integration/targets/helm_v3_15_4/inventory.ini +++ /dev/null @@ -1,2 +0,0 @@ -[all] -v3.15.4 \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_15_4/play.yaml b/tests/integration/targets/helm_v3_15_4/play.yaml deleted file mode 100644 index 71724bc2..00000000 --- a/tests/integration/targets/helm_v3_15_4/play.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- name: Run tests for Helm v3.15.4 - hosts: all - connection: local - gather_facts: true - - vars: - ansible_python_interpreter: "{{ ansible_playbook_python }}" - helm_version: "{{ inventory_hostname }}" - - roles: - - role: helm diff --git a/tests/integration/targets/helm_v3_15_4/runme.sh b/tests/integration/targets/helm_v3_15_4/runme.sh deleted file mode 100755 index 2b5bb1b6..00000000 --- a/tests/integration/targets/helm_v3_15_4/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook play.yaml -i inventory.ini "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_16_0/aliases b/tests/integration/targets/helm_v3_16_0/aliases deleted file mode 100644 index a80cfed0..00000000 --- a/tests/integration/targets/helm_v3_16_0/aliases +++ /dev/null @@ -1,4 +0,0 @@ -helm -helm_template -helm_info -helm_repository \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_16_0/inventory.ini b/tests/integration/targets/helm_v3_16_0/inventory.ini deleted file mode 100644 index c49ca863..00000000 --- a/tests/integration/targets/helm_v3_16_0/inventory.ini +++ /dev/null @@ -1,2 +0,0 @@ -[all] -v3.16.0 \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_16_0/play.yaml b/tests/integration/targets/helm_v3_16_0/play.yaml deleted file mode 100644 index afd3454f..00000000 --- a/tests/integration/targets/helm_v3_16_0/play.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- name: Run tests for Helm v3.16.0 - hosts: all - connection: local - gather_facts: true - - vars: - ansible_python_interpreter: "{{ ansible_playbook_python }}" - helm_version: "{{ inventory_hostname }}" - - roles: - - role: helm diff --git a/tests/integration/targets/helm_v3_16_0/runme.sh b/tests/integration/targets/helm_v3_16_0/runme.sh deleted file mode 100755 index 2b5bb1b6..00000000 --- a/tests/integration/targets/helm_v3_16_0/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook play.yaml -i inventory.ini "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_17_0/aliases b/tests/integration/targets/helm_v3_17_0/aliases deleted file mode 100644 index a80cfed0..00000000 --- a/tests/integration/targets/helm_v3_17_0/aliases +++ /dev/null @@ -1,4 +0,0 @@ -helm -helm_template -helm_info -helm_repository \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_17_0/inventory.ini b/tests/integration/targets/helm_v3_17_0/inventory.ini deleted file mode 100644 index ea3b890b..00000000 --- a/tests/integration/targets/helm_v3_17_0/inventory.ini +++ /dev/null @@ -1,2 +0,0 @@ -[all] -v3.17.0 \ No newline at end of file diff --git a/tests/integration/targets/helm_v3_17_0/play.yaml b/tests/integration/targets/helm_v3_17_0/play.yaml deleted file mode 100644 index 6388d2a0..00000000 --- a/tests/integration/targets/helm_v3_17_0/play.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- name: Run tests for Helm v3.17.0 - hosts: all - connection: local - gather_facts: true - - vars: - ansible_python_interpreter: "{{ ansible_playbook_python }}" - helm_version: "{{ inventory_hostname }}" - - roles: - - role: helm diff --git a/tests/integration/targets/helm_v3_17_0/runme.sh b/tests/integration/targets/helm_v3_17_0/runme.sh deleted file mode 100755 index 2b5bb1b6..00000000 --- a/tests/integration/targets/helm_v3_17_0/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook play.yaml -i inventory.ini "$@" \ No newline at end of file diff --git a/tests/integration/targets/helm_v4_0_0/aliases b/tests/integration/targets/helm_v4_0_0/aliases deleted file mode 100644 index a80cfed0..00000000 --- a/tests/integration/targets/helm_v4_0_0/aliases +++ /dev/null @@ -1,4 +0,0 @@ -helm -helm_template -helm_info -helm_repository \ No newline at end of file diff --git a/tests/integration/targets/helm_v4_0_0/inventory.ini b/tests/integration/targets/helm_v4_0_0/inventory.ini deleted file mode 100644 index 066a9cee..00000000 --- a/tests/integration/targets/helm_v4_0_0/inventory.ini +++ /dev/null @@ -1,2 +0,0 @@ -[all] -v4.0.0 \ No newline at end of file diff --git a/tests/integration/targets/helm_v4_0_0/play.yaml b/tests/integration/targets/helm_v4_0_0/play.yaml deleted file mode 100644 index 5591456a..00000000 --- a/tests/integration/targets/helm_v4_0_0/play.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- name: Run tests for Helm v4.0.0 - hosts: all - connection: local - gather_facts: true - - vars: - ansible_python_interpreter: "{{ ansible_playbook_python }}" - helm_version: "{{ inventory_hostname }}" - - roles: - - role: helm diff --git a/tests/integration/targets/helm_v4_0_0/runme.sh b/tests/integration/targets/helm_v4_0_0/runme.sh deleted file mode 100755 index 2b5bb1b6..00000000 --- a/tests/integration/targets/helm_v4_0_0/runme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook play.yaml -i inventory.ini "$@" \ No newline at end of file diff --git a/tests/integration/targets/install_helm/defaults/main.yml b/tests/integration/targets/install_helm/defaults/main.yml deleted file mode 100644 index d62c8fc5..00000000 --- a/tests/integration/targets/install_helm/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -helm_version: v3.16.4 -helm_install_path: /tmp/helm -helm_default_archive_name: "https://get.helm.sh/helm-{{ helm_version }}-{{ ansible_system | lower }}-{{ ansible_architecture | lower }}.tar.gz" diff --git a/tests/integration/targets/install_helm/tasks/main.yml b/tests/integration/targets/install_helm/tasks/main.yml deleted file mode 100644 index 3fce576f..00000000 --- a/tests/integration/targets/install_helm/tasks/main.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- name: Init Helm folders - file: - path: "{{ helm_install_path }}" - state: directory - -- ansible.builtin.set_fact: - os_path: "{{ lookup('env', 'PATH') }}" - -- name: Download the Helm install script - ansible.builtin.get_url: - url: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-{{ major_version }}" - dest: /tmp/get_helm.sh - mode: '0700' - vars: - major_version: "{{ helm_version | split('.') | first | replace('v', '') }}" - -- name: Run the install script (helm version = {{ helm_version }}) - ansible.builtin.command: /tmp/get_helm.sh - environment: - DESIRED_VERSION: "{{ helm_version }}" - HELM_INSTALL_DIR: "{{ helm_install_path }}" - PATH: "{{ os_path }}:{{ helm_install_path }}" - VERIFY_CHECKSUM: "false" - register: helm_install_result - changed_when: "'is already at the latest version' not in helm_install_result.stdout" - -- name: Save Helm binary path for later use - ansible.builtin.set_fact: - helm_binary: "{{ helm_install_path }}/helm" diff --git a/tests/integration/targets/push_to_helm_registry/tasks/main.yml b/tests/integration/targets/push_to_helm_registry/tasks/main.yml index d3dfda18..0dc4600a 100644 --- a/tests/integration/targets/push_to_helm_registry/tasks/main.yml +++ b/tests/integration/targets/push_to_helm_registry/tasks/main.yml @@ -1,10 +1,13 @@ --- - name: Ensure we can log into the helm registry - command: >- - {{ helm_binary_path }} registry login + ansible.builtin.shell: >- + echo "{{ chart_repo_password }}" | {{ helm_binary_path }} registry login -u {{ chart_repo_username }} - -p {{ chart_repo_password }} + --password-stdin + {{ helm_version | string is ansible.builtin.version("3.18.0", ">=") | ternary('--plain-http', '') }} {{ chart_repo_url }} + environment: + HELM_EXPERIMENTAL_OCI: "1" - name: Package chart and push to helm registry block: @@ -15,7 +18,7 @@ register: _tmpfile - name: Package helm chart - command: '{{ helm_binary_path }} package {{ chart_local_path }} --destination {{ _tmpfile.path }}' + ansible.builtin.command: '{{ helm_binary_path }} package {{ chart_local_path }} --destination {{ _tmpfile.path }}' - name: Locate helm chart package ansible.builtin.find: @@ -24,11 +27,14 @@ register: _files - name: Helm push chart to the registry - command: '{{ helm_binary_path }} push {{ _files.files.0.path }} oci://{{ chart_repo_url }}/{{ chart_repo_path }}' + ansible.builtin.command: >- + {{ helm_binary_path }} push {{ _files.files.0.path }} + oci://{{ chart_repo_url }}/{{ chart_repo_path }} + {{ (helm_version | string is ansible.builtin.version('3.13.0', '>=')) | ternary('--plain-http', '') }} always: - name: Logout from registry - command: '{{ helm_binary_path }} registry logout {{ chart_repo_url }}' + ansible.builtin.command: '{{ helm_binary_path }} registry logout {{ chart_repo_url }}' ignore_errors: true - name: Delete temporary directory diff --git a/tests/integration/targets/install_helm/aliases b/tests/integration/targets/setup_helm/aliases similarity index 100% rename from tests/integration/targets/install_helm/aliases rename to tests/integration/targets/setup_helm/aliases diff --git a/tests/integration/targets/setup_helm/defaults/main.yml b/tests/integration/targets/setup_helm/defaults/main.yml new file mode 100644 index 00000000..11b5830b --- /dev/null +++ b/tests/integration/targets/setup_helm/defaults/main.yml @@ -0,0 +1,4 @@ +--- +setup_helm_version: v3.16.4 +helm_install_path: /tmp/helm +helm_default_archive_name: "https://get.helm.sh/helm-{{ setup_helm_version }}-{{ ansible_system | lower }}-{{ ansible_architecture | lower }}.tar.gz" diff --git a/tests/integration/targets/setup_helm/handlers/main.yml b/tests/integration/targets/setup_helm/handlers/main.yml new file mode 100644 index 00000000..ab532203 --- /dev/null +++ b/tests/integration/targets/setup_helm/handlers/main.yml @@ -0,0 +1,4 @@ +- name: 'Delete temporary directory' + ansible.builtin.file: + state: absent + path: "{{ helm_install_path }}" diff --git a/tests/integration/targets/setup_helm/tasks/main.yml b/tests/integration/targets/setup_helm/tasks/main.yml new file mode 100644 index 00000000..2da4a4a8 --- /dev/null +++ b/tests/integration/targets/setup_helm/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: Check if executable is already present + ansible.builtin.stat: + path: "{{ helm_install_path }}/helm" + register: helm_stat + +- when: not helm_stat.stat.exists + block: + - name: Init Helm folders + ansible.builtin.file: + path: "{{ helm_install_path }}" + state: directory + notify: 'Delete temporary directory' + + - name: Set variable os_path + ansible.builtin.set_fact: + os_path: "{{ lookup('env', 'PATH') }}" + + - name: Add version prefix if not defined + ansible.builtin.set_fact: + helm_version_str: "{{ setup_helm_version.startswith('v') | ternary('', 'v') ~ setup_helm_version }}" + + - name: Download the Helm install script + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-{{ major_version }}" + dest: /tmp/get_helm.sh + mode: '0700' + vars: + major_version: "{{ helm_version_str | split('.') | first | replace('v', '') }}" + + - name: Run the install script (helm version = {{ helm_version_str }}) + ansible.builtin.command: /tmp/get_helm.sh + environment: + DESIRED_VERSION: "{{ helm_version_str }}" + HELM_INSTALL_DIR: "{{ helm_install_path }}" + PATH: "{{ os_path }}:{{ helm_install_path }}" + VERIFY_CHECKSUM: "false" + register: helm_install_result + changed_when: "'is already at the latest version' not in helm_install_result.stdout" + +- name: Save Helm binary path for later use + ansible.builtin.set_fact: + setup_helm_binary_path: "{{ helm_install_path }}/helm" diff --git a/tests/integration/targets/setup_helm_version/aliases b/tests/integration/targets/setup_helm_version/aliases new file mode 100644 index 00000000..7a68b11d --- /dev/null +++ b/tests/integration/targets/setup_helm_version/aliases @@ -0,0 +1 @@ +disabled diff --git a/tests/integration/targets/setup_helm_version/library/test_helm_read_version.py b/tests/integration/targets/setup_helm_version/library/test_helm_read_version.py new file mode 100644 index 00000000..a408c2e9 --- /dev/null +++ b/tests/integration/targets/setup_helm_version/library/test_helm_read_version.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2022, Aubin Bikouo <@abikouo> +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +DOCUMENTATION = r""" + +module: test_helm_read_version + +short_description: Retrieve helm version. + +author: + - Aubin Bikouo (@abikouo) + +description: + - This module is used for integration testing only for this collection. + - The module runs the command to retrieve the helm version. + +options: + binary_path: + description: + - The path of a helm binary to use. + required: false + type: path +""" + + +RETURN = """ +helm_version: + description: + - The helm version. + returned: always + type: str +""" + +from ansible_collections.kubernetes.core.plugins.module_utils.helm import ( + AnsibleHelmModule, +) + + +def main(): + module = AnsibleHelmModule( + argument_spec=dict( + binary_path=dict(type="path"), + ), + supports_check_mode=True, + ) + + helm_version = module.get_helm_version() + module.exit_json(changed=False, helm_version=helm_version) + + +if __name__ == "__main__": + main() diff --git a/tests/integration/targets/setup_helm_version/tasks/main.yml b/tests/integration/targets/setup_helm_version/tasks/main.yml new file mode 100644 index 00000000..a056aa7e --- /dev/null +++ b/tests/integration/targets/setup_helm_version/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Read version for current helm binary + test_helm_read_version: + binary_path: "{{ setup_helm_binary_path | default('helm') }}" + register: result + +- name: Set helm version + ansible.builtin.set_fact: + helm_version: "{{ result.helm_version }}"