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..b623b45ca5 100644 --- a/tests/integration/targets/lookup_kustomize/tasks/main.yml +++ b/tests/integration/targets/lookup_kustomize/tasks/main.yml @@ -100,53 +100,49 @@ 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" - 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') }}" - 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}) }}" - 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 +159,6 @@ with_items: - "{{ tmp_dir_path }}" - "{{ _tmp_dir_kustomize.path }}" + + - name: Stop tinyproxy + ansible.builtin.command: "docker stop tinyproxy"