From 8983d31ed82141de275ba37f4ba2b5b9dc4215ae Mon Sep 17 00:00:00 2001 From: Yuriy Novostavskiy Date: Thu, 21 Nov 2024 20:12:42 +0000 Subject: [PATCH] Refactor integration test for kustomize environ support --- .../lookup_kustomize/defaults/main.yml | 1 + .../targets/lookup_kustomize/tasks/main.yml | 64 +++++++++++-------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/integration/targets/lookup_kustomize/defaults/main.yml b/tests/integration/targets/lookup_kustomize/defaults/main.yml index bc7e6fbe63..32face2d41 100644 --- a/tests/integration/targets/lookup_kustomize/defaults/main.yml +++ b/tests/integration/targets/lookup_kustomize/defaults/main.yml @@ -1,2 +1,3 @@ --- test_namespace: "kustomize" +proxy_port: 8888 diff --git a/tests/integration/targets/lookup_kustomize/tasks/main.yml b/tests/integration/targets/lookup_kustomize/tasks/main.yml index 055fa2e434..31e49fbfe6 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -100,53 +100,57 @@ suffix: .testkustomize register: _tmp_dir_kustomize - # - name: Create a base directory - # ansible.builtin.file: - # path: "{{ _tmp_dir_kustomize.path }}/base" - # state: directory - # mode: '0755' - - name: Download helloWorld example ansible.builtin.get_url: - url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml" + url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/refs/heads/master/examples/loadHttp/kustomization.yaml" dest: "{{ _tmp_dir_kustomize.path }}" - with_items: - - configMap - - deployment - - kustomization - - service - - name: Replace label in kustomization.yaml + - name: Run tinyproxy in docker # Replace the 'app: hello' with 'app: ${TEST_APP}' - ansible.builtin.replace: - path: "{{ _tmp_dir_kustomize.path }}/kustomization.yaml" - regexp: 'app: hello' - replace: 'app: ${TEST_APP}' + ansible.builtin.command: "docker run --rm -d -p {{ proxy_port }}:8888 --name=tinyproxy dannydirect/tinyproxy ANY" + + - name: Ensure that tinyproxy is running + ansible.builtin.wait_for: + host: localhost + port: "{{ proxy_port }}" + state: started - name: Test kustomize lookup plugin with environment variables in the string format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:8888 VAR2=Flase') }}" + ignore_errors: true - ansible.builtin.debug: var: resource_kustomize - - name: Assest that TEST_APP is replaced with testpassed - assert: - that: "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the string format failed" - - name: Test kustomize lookup plugin with environment variables in the list format set_fact: - resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}" + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:8888, VAR2=Flase}) }}" + ignore_errors: true - ansible.builtin.debug: var: resource_kustomize - - name: Assest that TEST_APP is replaced with testpassed - assert: - that: "'app: testpassed' in resource_kustomize.string" - fail_msg: "kustomize lookup plugin with environment variables in the list format failed" + - name: Stop tinyproxy + ansible.builtin.command: "docker stop tinyproxy" + - name: Ensure kustomize lookup plugin fail with proxy down + set_fact: + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:{{ proxy_port }} VAR2=Flase') }}" + ignore_errors: true + register: result + + - ansible.builtin.debug: + var: result + + - name: Ensure kustomize lookup plugin fail with proxy down + set_fact: + resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:{{ proxy_port }}, VAR2=Flase}) }}" + ignore_errors: true + register: result + + - ansible.builtin.debug: + var: result always: - name: Delete namespace @@ -163,3 +167,7 @@ with_items: - "{{ tmp_dir_path }}" - "{{ _tmp_dir_kustomize.path }}" + + - name: Stop tinyproxy + ansible.builtin.command: "docker stop tinyproxy" + ignore_errors: true