Skip to content

Commit 104572f

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

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-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: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,53 +100,63 @@
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"
111+
112+
- nane: Ensure that tinyproxy is running
113+
ansible.builtin.uri:
114+
host: http://tinyproxy.stats/
115+
use_proxy: true
116+
status_code: 200
117+
environment:
118+
HTTPS_PROXY: http://localhost:8888
119+
register: result
120+
retries: 3
121+
delay: 10
122+
until: result.status == 200
125123

126124
- name: Test kustomize lookup plugin with environment variables in the string format
127125
set_fact:
128-
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='TEST_APP=testpassed VAR2=Flase') }}"
126+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:8888 VAR2=Flase') }}"
127+
ignore_errors: true
129128

130129
- ansible.builtin.debug:
131130
var: resource_kustomize
132131

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-
138132
- name: Test kustomize lookup plugin with environment variables in the list format
139133
set_fact:
140-
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={TEST_APP=testpassed, VAR2=Flase}) }}"
134+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:8888, VAR2=Flase}) }}"
135+
ignore_errors: true
141136

142137
- ansible.builtin.debug:
143138
var: resource_kustomize
144139

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"
140+
- name: Stop tinyproxy
141+
ansible.builtin.command: "docker stop tinyproxy"
142+
143+
- name: Ensure kustomize lookup plugin fail with proxy down
144+
set_fact:
145+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment='HTTPS_PROXY=http://localhost:{{ proxy_port }} VAR2=Flase') }}"
146+
ignore_errors: true
147+
register: result
148+
149+
- ansible.builtin.debug:
150+
var: result
149151

152+
- name: Ensure kustomize lookup plugin fail with proxy down
153+
set_fact:
154+
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', dir=_tmp_dir_kustomize.path, environment={HTTPS_PROXY=http://localhost:{{ proxy_port }}, VAR2=Flase}) }}"
155+
ignore_errors: true
156+
register: result
157+
158+
- ansible.builtin.debug:
159+
var: result
150160

151161
always:
152162
- name: Delete namespace
@@ -163,3 +173,7 @@
163173
with_items:
164174
- "{{ tmp_dir_path }}"
165175
- "{{ _tmp_dir_kustomize.path }}"
176+
177+
- name: Stop tinyproxy
178+
ansible.builtin.command: "docker stop tinyproxy"
179+
ignore_errors: true

0 commit comments

Comments
 (0)