Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-lint - Fixing integration tests issues #844

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/integration/targets/helm/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: Init Helm folders
file:
ansible.builtin.file:
path: /tmp/helm/
state: directory

- name: Unarchive Helm binary
unarchive:
ansible.builtin.unarchive:
src: 'https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}'
dest: /tmp/helm/
remote_src: yes
remote_src: true
retries: 10
delay: 5
register: result
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/helm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Run tests
include_tasks: run_test.yml
ansible.builtin.include_tasks: run_test.yml
loop_control:
loop_var: helm_version
with_items:
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/targets/helm/tasks/run_test.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
---
- name: Ensure helm is not installed
file:
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
- "/tmp/helm"

- name: Check failed if helm is not installed
include_tasks: test_helm_not_installed.yml
ansible.builtin.include_tasks: test_helm_not_installed.yml

- name: "Install {{ helm_version }}"
include_role:
ansible.builtin.include_role:
name: install_helm

- 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:
- from_local_path
- 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 dependency update
include_tasks: test_up_dep.yml
- name: Test helm dependency update
ansible.builtin.include_tasks: test_up_dep.yml

- name: Test helm uninstall
include_tasks: test_helm_uninstall.yml
ansible.builtin.include_tasks: test_helm_uninstall.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: Clean helm install
file:
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
Expand Down
37 changes: 20 additions & 17 deletions tests/integration/targets/helm/tasks/test_crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
helm_namespace: "{{ test_namespace[0] }}"
block:
- name: Create namespace
k8s:
kubernetes.core.k8s:
kind: Namespace
name: "{{ helm_namespace }}"

- name: Copy test chart
copy:
ansible.builtin.copy:
src: "{{ test_chart }}"
dest: "/tmp/helm_test_crds/"

- name: Install chart while skipping CRDs
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary }}"
chart_ref: "/tmp/helm_test_crds/{{ test_chart }}"
namespace: "{{ helm_namespace }}"
name: test-crds
skip_crds: true
register: install

- assert:
- name: Assert that installation succeed
ansible.builtin.assert:
that:
- install is changed
- install.status.name == "test-crds"

- name: Fail to create custom resource
k8s:
kubernetes.core.k8s:
definition:
apiVersion: ansible.com/v1
kind: Foo
Expand All @@ -38,30 +39,31 @@
name: test-foo
foobar: footest
ignore_errors: true
register: result
failed_when: result is successful

- assert:
- name: Assert that module failed
ansible.builtin.assert:
that:
- result is failed
- "result.msg.startswith('Failed to find exact match for ansible.com/v1.Foo')"

# Helm won't install CRDs into an existing release, so we need to delete this, first
- name: Uninstall chart
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary }}"
namespace: "{{ helm_namespace }}"
name: test-crds
state: absent

- name: Install chart with CRDs
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary }}"
chart_ref: "/tmp/helm_test_crds/{{ test_chart }}"
namespace: "{{ helm_namespace }}"
name: test-crds

- name: Create custom resource
k8s:
kubernetes.core.k8s:
definition:
apiVersion: ansible.com/v1
kind: Foo
Expand All @@ -71,29 +73,30 @@
foobar: footest
register: result

- assert:
- name: Assert that module succeed
ansible.builtin.assert:
that:
- result is changed
- result.result.foobar == "footest"

always:
- name: Remove chart
file:
ansible.builtin.file:
path: "/tmp/helm_test_crds"
state: absent
ignore_errors: true
failed_when: false

- name: Remove namespace
k8s:
kubernetes.core.k8s:
kind: Namespace
name: "{{ helm_namespace }}"
state: absent
ignore_errors: true
failed_when: false

# CRDs aren't deleted with a namespace, so we need to manually delete it
- name: Remove CRD
k8s:
kubernetes.core.k8s:
kind: CustomResourceDefinition
name: foos.ansible.com
state: absent
ignore_errors: true
failed_when: false
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
- name: Failed test when helm is not installed
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary}}_fake"
name: test
chart_ref: "{{ chart_test }}"
namespace: "helm-test"
ignore_errors: yes
failed_when: helm_missing_binary is successful
register: helm_missing_binary

- name: Assert that helm is not installed
assert:
ansible.builtin.assert:
that:
- helm_missing_binary is failed
- "'No such file or directory' in helm_missing_binary.msg"
14 changes: 7 additions & 7 deletions tests/integration/targets/helm/tasks/test_helm_reuse_values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
count: 3
block:
- name: Initial chart installation
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary }}"
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
release_name: test-redis
Expand All @@ -25,21 +25,21 @@
register: install

- name: Get value set as string
helm_info:
kubernetes.core.helm_info:
binary_path: "{{ helm_binary }}"
release_name: test-redis
release_namespace: "{{ helm_namespace }}"
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'
- release_value["status"]["values"] == chart_release_values

- name: Upgrade chart using reuse_values=true
helm:
kubernetes.core.helm:
binary_path: "{{ helm_binary }}"
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
release_name: test-redis
Expand All @@ -50,14 +50,14 @@
register: upgrade

- name: Get value set as string
helm_info:
kubernetes.core.helm_info:
binary_path: "{{ helm_binary }}"
release_name: test-redis
release_namespace: "{{ helm_namespace }}"
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'
Expand All @@ -66,7 +66,7 @@

always:
- name: Remove helm namespace
k8s:
kubernetes.core.k8s:
api_version: v1
kind: Namespace
name: "{{ helm_namespace }}"
Expand Down
Loading
Loading