Skip to content

Commit 1f62e46

Browse files
committed
Refactor integration test for kustomize environ support
1 parent ad60093 commit 1f62e46

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
---
22
test_namespace: "kustomize"
3+
proxy_port: 8888

tests/integration/targets/lookup_kustomize/tasks/main.yml

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,53 +100,49 @@
100100
suffix: .testkustomize
101101
register: _tmp_dir_kustomize
102102

103-
# - name: Create a base directory
104-
# ansible.builtin.file:
105-
# path: "{{ _tmp_dir_kustomize.path }}/base"
106-
# state: directory
107-
# mode: '0755'
108-
109103
- name: Download helloWorld example
110104
ansible.builtin.get_url:
111-
url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/{{ item }}.yaml"
105+
url: "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/refs/heads/master/examples/loadHttp/kustomization.yaml"
112106
dest: "{{ _tmp_dir_kustomize.path }}"
113-
with_items:
114-
- configMap
115-
- deployment
116-
- kustomization
117-
- service
118107

119-
- name: Replace label in kustomization.yaml
108+
- name: Run tinyproxy in docker
120109
# Replace the 'app: hello' with 'app: ${TEST_APP}'
121-
ansible.builtin.replace:
122-
path: "{{ _tmp_dir_kustomize.path }}/kustomization.yaml"
123-
regexp: 'app: hello'
124-
replace: 'app: ${TEST_APP}'
110+
ansible.builtin.command: "docker run --rm -d -p {{ proxy_port }}:8888 --name=tinyproxy dannydirect/tinyproxy"
125111

126112
- name: Test kustomize lookup plugin with environment variables in the string format
127113
set_fact:
128-
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}"
114+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:8888 VAR2=Flase') }}"
129115

130116
- ansible.builtin.debug:
131117
var: resource_kustomize
132118

133-
- name: Assest that TEST_APP is replaced with testpassed
134-
assert:
135-
that: "'app: testpassed' in resource_kustomize.string"
136-
fail_msg: "kustomize lookup plugin with environment variables in the string format failed"
137-
138119
- name: Test kustomize lookup plugin with environment variables in the list format
139120
set_fact:
140-
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}"
121+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:8888, VAR2=Flase}) }}"
141122

142123
- ansible.builtin.debug:
143124
var: resource_kustomize
144125

145-
- name: Assest that TEST_APP is replaced with testpassed
146-
assert:
147-
that: "'app: testpassed' in resource_kustomize.string"
148-
fail_msg: "kustomize lookup plugin with environment variables in the list format failed"
126+
- name: Stop tinyproxy
127+
ansible.builtin.command: "docker stop tinyproxy"
149128

129+
- name: Ensure kustomize lookup plugin fail with proxy down
130+
set_fact:
131+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:{{ proxy_port }} VAR2=Flase') }}"
132+
ignore_errors: true
133+
register: result
134+
135+
- ansible.builtin.debug:
136+
var: result
137+
138+
- name: Ensure kustomize lookup plugin fail with proxy down
139+
set_fact:
140+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:{{ proxy_port }}, VAR2=Flase}) }}"
141+
ignore_errors: true
142+
register: result
143+
144+
- ansible.builtin.debug:
145+
var: result
150146

151147
always:
152148
- name: Delete namespace
@@ -163,3 +159,6 @@
163159
with_items:
164160
- "{{ tmp_dir_path }}"
165161
- "{{ _tmp_dir_kustomize.path }}"
162+
163+
- name: Stop tinyproxy
164+
ansible.builtin.command: "docker stop tinyproxy"

0 commit comments

Comments
 (0)