[backport/2.2] Move integration test suite from molecule to ansible-test (#392) (#457)

[backport/2.2] Move integration test suite from molecule to ansible-test (#392)

Move integration test suite from molecule to ansible-test
SUMMARY
molecule has been replaced with ansible-test
some test cases have been updated
k8s_apply : remove duplicated tasks increasing the running time of the test
helm: use different namespaces for different test cases in order to wait for the namespace deletion before moving to the next test.
all: remove wait: yes at the end of each test when deleting namespace, the role used to create namespace will ensure that it is deleted before if existing.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
integration testing
Reviewed-by: Mike Graves mgraves@redhat.com
Reviewed-by: Gonéri Le Bouder goneri@lebouder.net
Reviewed-by: None 
(cherry picked from commit fd61f8b)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION
This commit is contained in:
Mike Graves
2022-05-11 14:56:23 -04:00
committed by GitHub
parent 0d9c4d3459
commit 11c800d6ed
190 changed files with 1261 additions and 1768 deletions

View File

@@ -0,0 +1,3 @@
context/target
time=44
k8s

View File

@@ -0,0 +1,2 @@
---
test_namespace: "kustomize"

View File

@@ -0,0 +1,2 @@
dependencies:
- setup_namespace

View File

@@ -0,0 +1,99 @@
---
- block:
- set_fact:
kustomize_ns: "{{ test_namespace }}"
- name: create environment for test
block:
- name: Create temp directory
tempfile:
state: directory
suffix: .test
register: _tmp_dir
- set_fact:
tmp_dir_path: "{{ _tmp_dir.path }}"
- set_fact:
kustomize_dir: "{{ tmp_dir_path }}/kustomization"
- name: create kustomize directory
file:
path: "{{ kustomize_dir }}"
state: directory
- name: create kustomization file
copy:
content: '{{ item.content }}'
dest: '{{ item.dest }}'
with_items:
- content: |
configMapGenerator:
- name: test-confmap-
files:
- data.properties
dest: "{{ kustomize_dir }}/kustomization.yaml"
- content: "project=ansible"
dest: "{{ kustomize_dir }}/data.properties"
- name: copy script to install kustomize
get_url:
url: https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh
dest: "{{ tmp_dir_path }}"
- name: make script as executable
file:
path: "{{ tmp_dir_path }}/install_kustomize.sh"
mode: 0755
- name: Install kustomize
command: "{{ tmp_dir_path }}/install_kustomize.sh"
args:
chdir: "{{ tmp_dir_path }}"
register: _install
- set_fact:
kustomize_binary: "{{ _install.stdout | regex_search('kustomize installed to (.*)', '\\1') | list | join('') }}"
kubectl_binary: "{{ tmp_dir_path }}/kubectl"
- name: Download kubeclt executable used to compare results
get_url:
url: https://dl.k8s.io/release/v1.21.3/bin/linux/amd64/kubectl
dest: "{{ kubectl_binary }}"
- name: make kubectl executable
ansible.builtin.file:
path: "{{ kubectl_binary }}"
mode: "+x"
- name: Run lookup using kustomize binary
set_fact:
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', binary_path=kustomize_binary, dir=kustomize_dir) }}"
- name: Run lookup using kubectl binary
set_fact:
resource_kubectl: "{{ lookup('kubernetes.core.kustomize', binary_path=kubectl_binary, dir=kustomize_dir) }}"
- name: assert output are the same
assert:
that:
- resource_kubectl == resource_kustomize
- name: create kubernetes resource using lookup plugin
k8s:
namespace: "{{ kustomize_ns }}"
definition: "{{ lookup('kubernetes.core.kustomize', dir=kustomize_dir, opt_dirs=tmp_dir_path) }}"
always:
- name: Delete namespace
k8s:
kind: Namespace
name: "{{ kustomize_ns }}"
state: absent
ignore_errors: true
- name: Delete temporary directory
file:
state: absent
path: "{{ tmp_dir_path }}"