diff --git a/tests/integration/targets/helm_diff/files/test-chart-deployment-time/Chart.yaml b/tests/integration/targets/helm_diff/files/test-chart-deployment-time/Chart.yaml new file mode 100644 index 0000000000..895d86a259 --- /dev/null +++ b/tests/integration/targets/helm_diff/files/test-chart-deployment-time/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: test-chart-deployment-time +description: A chart with a config map containing the deployment time in data +type: application +version: 0.1.0 +appVersion: "default" diff --git a/tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml b/tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml new file mode 100644 index 0000000000..e585295091 --- /dev/null +++ b/tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ default "ansible-configmap" .Values.myConfigmapName }} +data: + myValue: {{ default "test" .Values.myValue }} + deploymentTime: {{ now }} diff --git a/tests/integration/targets/helm_diff/meta/main.yml b/tests/integration/targets/helm_diff/meta/main.yml index 10d989e78a..b700f8c191 100644 --- a/tests/integration/targets/helm_diff/meta/main.yml +++ b/tests/integration/targets/helm_diff/meta/main.yml @@ -2,3 +2,4 @@ dependencies: - remove_namespace - install_helm + - setup_helm_registry diff --git a/tests/integration/targets/helm_diff/tasks/main.yml b/tests/integration/targets/helm_diff/tasks/main.yml index c37d947f5f..c2228e9afd 100644 --- a/tests/integration/targets/helm_diff/tasks/main.yml +++ b/tests/integration/targets/helm_diff/tasks/main.yml @@ -2,7 +2,6 @@ - name: Test helm diff functionality vars: test_chart_ref: "/tmp/test-chart" - redis_chart_version: '17.0.5' block: @@ -24,7 +23,7 @@ name: test-chart namespace: "{{ helm_namespace }}" chart_ref: "{{ test_chart_ref }}" - create_namespace: yes + create_namespace: true register: install - assert: @@ -49,8 +48,8 @@ name: test-chart namespace: "{{ helm_namespace }}" chart_ref: "{{ test_chart_ref }}" - check_mode: yes - diff: yes + check_mode: true + diff: true register: diff_result - name: Check if helm diff check is correct @@ -79,7 +78,7 @@ namespace: "{{ helm_namespace }}" chart_ref: "{{ test_chart_ref }}" check_mode: yes - diff: yes + diff: true register: diff_result - name: Check if no diff in check mode when no change @@ -101,7 +100,7 @@ - name: Modify values blockinfile: - create: yes + create: true path: "{{ test_chart_ref }}/values.yml" block: | --- @@ -206,52 +205,76 @@ - install is not changed # Test helm diff with chart_repo_url - - name: Define Redis chart values + - name: Uninstall helm diff + helm_plugin: + binary_path: "{{ helm_binary }}" + state: absent + plugin_name: diff + ignore_errors: true + + - name: Define chart variables set_fact: - redis_chart_values: - commonLabels: - phase: testing - company: RedHat - image: - tag: 6.2.6-debian-10-r135 - architecture: standalone - - - name: Install Redis chart + test_chart_values: + myValue: 'Some ConfigMap data value' + myConfigmapName: 'ansible-config-from-url' + test_chart_version: 0.1.0 + test_chart_ref_url: "oci://localhost:6035/testing/test-chart-deployment-time" + + - name: Deploy chart to remote registry + block: + - name: Create local directory to copy chart in + ansible.builtin.tempfile: + suffix: .chart + state: directory + register: _tmpd + + - name: Copy local registry + ansible.builtin.copy: + dest: "{{ _tmpd.path }}" + src: '{{ role_path }}/files/test-chart-deployment-time' + + - name: Push chart to helm registry + ansible.builtin.include_role: + name: push_to_helm_registry + vars: + chart_local_path: '{{ _tmpd.path }}/test-chart-deployment-time' + chart_repo_path: 'testing' + always: + - name: Delete temporary directory + ansible.builtin.file: + state: absent + path: '{{ _tmpd.path }}' + + - name: Log into Helm registry + ansible.builtin.command: "{{ helm_binary }} registry login -u testuser -p 'pass123!' localhost:6035" + + - name: Install chart from remote URL helm: binary_path: "{{ helm_binary }}" - chart_repo_url: https://charts.bitnami.com/bitnami - chart_ref: redis + chart_ref: "{{ test_chart_ref_url }}" + chart_version: 0.1.0 namespace: "{{ helm_namespace }}" - name: redis-chart - chart_version: "{{ redis_chart_version }}" - release_values: "{{ redis_chart_values }}" + name: another-chart + release_values: "{{ test_chart_values }}" - - name: Upgrade Redis chart + - name: Upgrade chart helm: binary_path: "{{ helm_binary }}" - chart_repo_url: https://charts.bitnami.com/bitnami - chart_ref: redis + chart_ref: "{{ test_chart_ref_url }}" + chart_version: 0.1.0 namespace: "{{ helm_namespace }}" - name: redis-chart - chart_version: "{{ redis_chart_version }}" - release_values: "{{ redis_chart_values }}" - check_mode: yes - register: redis_upgrade + name: another-chart + release_values: "{{ test_chart_values }}" + check_mode: true + register: _upgrade - name: Assert that module raised a warning assert: that: - - not redis_upgrade.changed - - redis_upgrade.warnings is defined - - redis_upgrade.warnings | length == 1 - - redis_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: Uninstall helm diff - helm_plugin: - binary_path: "{{ helm_binary }}" - state: absent - plugin_name: diff - ignore_errors: yes + - 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: @@ -260,37 +283,36 @@ plugin_path: https://github.com/databus23/helm-diff plugin_version: 3.4.1 - - name: Upgrade Redis chart once again + - name: Upgrade chart once again helm: binary_path: "{{ helm_binary }}" - chart_repo_url: https://charts.bitnami.com/bitnami - chart_ref: redis + chart_ref: "{{ test_chart_ref_url }}" + chart_version: 0.1.0 namespace: "{{ helm_namespace }}" - name: redis-chart - chart_version: "{{ redis_chart_version }}" - release_values: "{{ redis_chart_values }}" - check_mode: yes - register: redis_upgrade_2 + name: another-chart + release_values: "{{ test_chart_values }}" + check_mode: true + register: _upgrade_2 - name: Assert that module raised a warning assert: that: - - redis_upgrade_2.changed - - redis_upgrade_2.warnings is not defined + - _upgrade_2.changed + - _upgrade_2.warnings is not defined always: - name: Remove chart directory file: path: "{{ test_chart_ref }}" state: absent - ignore_errors: yes + ignore_errors: true - name: Uninstall helm diff helm_plugin: binary_path: "{{ helm_binary }}" state: absent plugin_name: diff - ignore_errors: yes + ignore_errors: true - name: Remove helm namespace k8s: @@ -299,6 +321,6 @@ name: "{{ helm_namespace }}" state: absent wait: true - ignore_errors: yes + ignore_errors: true - include_tasks: reuse_values.yml diff --git a/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml b/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml index 8599b66a92..5b66660914 100644 --- a/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml +++ b/tests/integration/targets/helm_kubeconfig/tasks/tests_helm_auth.yml @@ -18,7 +18,12 @@ - set_fact: saved_kubeconfig_path: "{{ _dir.path }}/config" -- block: +- vars: + helm_repo_name: autoscaler + helm_repo_url: "https://kubernetes.github.io/autoscaler" + helm_release_name: "autoscaler" + helm_chart_name: "cluster-autoscaler" + block: - name: Copy default kubeconfig copy: remote_src: true @@ -59,14 +64,14 @@ - plugin_info.plugin_list != [] # helm_repository, helm, helm_info - - name: Add test_bitnami chart repository + - name: 'Add "{{ helm_repo_name }}" chart repository' helm_repository: binary_path: "{{ helm_binary }}" - name: test_bitnami + name: "{{ helm_repo_name }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}" - repo_url: https://charts.bitnami.com/bitnami + repo_url: "{{ helm_repo_url }}" register: repository - name: Assert that repository was added @@ -77,8 +82,8 @@ - name: Install chart from repository added before helm: binary_path: "{{ helm_binary }}" - name: rabbitmq - chart_ref: test_bitnami/rabbitmq + name: "{{ helm_release_name }}" + chart_ref: "{{ helm_repo_name }}/{{ helm_chart_name }}" namespace: "{{ helm_namespace }}" update_repo_cache: true kubeconfig: "{{ test_kubeconfig | default(omit) }}" @@ -98,7 +103,7 @@ kubeconfig: "{{ test_kubeconfig | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}" - name: "rabbitmq" + name: "{{ helm_release_name }}" namespace: "{{ helm_namespace }}" register: chart_info @@ -112,7 +117,7 @@ - name: Remove chart helm: binary_path: "{{ helm_binary }}" - name: rabbitmq + name: "{{ helm_release_name }}" namespace: "{{ helm_namespace }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}" @@ -131,7 +136,7 @@ kubeconfig: "{{ test_kubeconfig | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}" - name: "rabbitmq" + name: "{{ helm_release_name }}" namespace: "{{ helm_namespace }}" register: chart_info @@ -143,7 +148,7 @@ - name: Remove chart repository helm_repository: binary_path: "{{ helm_binary }}" - name: test_bitnami + name: "{{ helm_repo_name }}" kubeconfig: "{{ test_kubeconfig | default(omit) }}" validate_certs: "{{ test_validate_certs | default(omit) }}" ca_cert: "{{ test_ca_cert | default(omit) }}" @@ -192,6 +197,6 @@ - name: Delete helm repository helm_repository: binary_path: "{{ helm_binary }}" - name: test_bitnami + name: "{{ helm_repo_name }}" state: absent ignore_errors: true diff --git a/tests/integration/targets/push_to_helm_registry/aliases b/tests/integration/targets/push_to_helm_registry/aliases new file mode 100644 index 0000000000..87e7bdaaec --- /dev/null +++ b/tests/integration/targets/push_to_helm_registry/aliases @@ -0,0 +1 @@ +disabled \ No newline at end of file diff --git a/tests/integration/targets/push_to_helm_registry/defaults/main.yml b/tests/integration/targets/push_to_helm_registry/defaults/main.yml new file mode 100644 index 0000000000..4b5df41389 --- /dev/null +++ b/tests/integration/targets/push_to_helm_registry/defaults/main.yml @@ -0,0 +1,5 @@ +--- +helm_binary_path: "helm" +chart_repo_url: 'localhost:6035' +chart_repo_username: testuser +chart_repo_password: 'pass123!' diff --git a/tests/integration/targets/push_to_helm_registry/tasks/main.yml b/tests/integration/targets/push_to_helm_registry/tasks/main.yml new file mode 100644 index 0000000000..d3dfda18f8 --- /dev/null +++ b/tests/integration/targets/push_to_helm_registry/tasks/main.yml @@ -0,0 +1,38 @@ +--- +- name: Ensure we can log into the helm registry + command: >- + {{ helm_binary_path }} registry login + -u {{ chart_repo_username }} + -p {{ chart_repo_password }} + {{ chart_repo_url }} + +- name: Package chart and push to helm registry + block: + - name: Create temporary directory to store chart + ansible.builtin.tempfile: + state: directory + suffix: .chart + register: _tmpfile + + - name: Package helm chart + command: '{{ helm_binary_path }} package {{ chart_local_path }} --destination {{ _tmpfile.path }}' + + - name: Locate helm chart package + ansible.builtin.find: + paths: "{{ _tmpfile.path }}" + patterns: '*.tgz' + 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 }}' + + always: + - name: Logout from registry + command: '{{ helm_binary_path }} registry logout {{ chart_repo_url }}' + ignore_errors: true + + - name: Delete temporary directory + ansible.builtin.file: + state: absent + path: '{{ _tmpfile.path }}' + ignore_errors: true diff --git a/tests/integration/targets/setup_helm_registry/aliases b/tests/integration/targets/setup_helm_registry/aliases new file mode 100644 index 0000000000..7a68b11da8 --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/aliases @@ -0,0 +1 @@ +disabled diff --git a/tests/integration/targets/setup_helm_registry/defaults/main.yml b/tests/integration/targets/setup_helm_registry/defaults/main.yml new file mode 100644 index 0000000000..0d8c3ba4c8 --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# user: testuser, password: pass123! +registry_credentials: testuser:$2y$05$d8tw6L1hojRFW.FjHOAnIOihJWAvFb0/Pu/30hLbQNJIYzCmlyBCi +registry_name: helm_registry +registry_port: 6035 diff --git a/tests/integration/targets/setup_helm_registry/handlers/main.yml b/tests/integration/targets/setup_helm_registry/handlers/main.yml new file mode 100644 index 0000000000..92bbe5978b --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Teardown registry + include_tasks: teardown_registry.yml diff --git a/tests/integration/targets/setup_helm_registry/tasks/main.yml b/tests/integration/targets/setup_helm_registry/tasks/main.yml new file mode 100644 index 0000000000..4c84898680 --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: Ensure we can talk to docker daemon + ansible.builtin.shell: + cmd: docker ps + +- name: Create temporary directory to store file in + tempfile: + state: directory + suffix: .helm_registry + register: _tmpfile + # notify: + # - Teardown registry + +- name: Create authentication file + copy: + content: "{{ registry_credentials }}" + dest: "{{ _tmpfile.path }}/htpasswd" + +- name: Remove existing registry + ansible.builtin.include_tasks: remove_docker_container.yml + +- name: Create registry container + command: >- + docker run -d + -p {{ registry_port }}:5000 + --restart=always + --name "{{ registry_name }}" + -v "{{ _tmpfile.path }}:/auth" + -e "REGISTRY_AUTH=htpasswd" + -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" + -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd + registry:2 diff --git a/tests/integration/targets/setup_helm_registry/tasks/remove_docker_container.yml b/tests/integration/targets/setup_helm_registry/tasks/remove_docker_container.yml new file mode 100644 index 0000000000..77d33b61ac --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/tasks/remove_docker_container.yml @@ -0,0 +1,15 @@ +--- +- name: Inspect docker container + command: docker container inspect {{ registry_name }} -f '{{ '{{' }} .State.Running {{ '}}' }}' + register: _inspect + ignore_errors: true + +- name: Remove container + when: _inspect.rc == 0 + block: + - name: Stop running container + command: docker container stop {{ registry_name }} + when: _inspect.stdout == "true" + + - name: Remove container + command: docker container rm {{ registry_name }} diff --git a/tests/integration/targets/setup_helm_registry/tasks/teardown_registry.yml b/tests/integration/targets/setup_helm_registry/tasks/teardown_registry.yml new file mode 100644 index 0000000000..7382a8bb00 --- /dev/null +++ b/tests/integration/targets/setup_helm_registry/tasks/teardown_registry.yml @@ -0,0 +1,9 @@ +--- +- name: Remove Docker container + ansible.builtin.include_tasks: remove_docker_container.yml + +- name: Delete temporary directory + file: + state: absent + path: '{{ _tmpfile.path }}' + ignore_errors: true diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 5f1713d7dc..66d03d7b21 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -25,3 +25,4 @@ plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index 7eee4a23c7..cfcff02404 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -26,3 +26,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index c154baaf2d..c8e746f58d 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -29,3 +29,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt index c154baaf2d..c8e746f58d 100644 --- a/tests/sanity/ignore-2.17.txt +++ b/tests/sanity/ignore-2.17.txt @@ -29,3 +29,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip diff --git a/tests/sanity/ignore-2.18.txt b/tests/sanity/ignore-2.18.txt index 39dca9ac9c..615376934a 100644 --- a/tests/sanity/ignore-2.18.txt +++ b/tests/sanity/ignore-2.18.txt @@ -26,3 +26,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip diff --git a/tests/sanity/ignore-2.19.txt b/tests/sanity/ignore-2.19.txt index 39dca9ac9c..615376934a 100644 --- a/tests/sanity/ignore-2.19.txt +++ b/tests/sanity/ignore-2.19.txt @@ -26,3 +26,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error plugins/modules/k8s_service.py validate-modules:return-syntax-error plugins/modules/k8s_taint.py validate-modules:return-syntax-error tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip +tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip