Skip to content

Commit

Permalink
Refactor integration test for kustomize environ support
Browse files Browse the repository at this point in the history
  • Loading branch information
yurnov committed Nov 21, 2024
1 parent ad60093 commit fbfcadf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
test_namespace: "kustomize"
proxy_port: 8888
70 changes: 42 additions & 28 deletions tests/integration/targets/lookup_kustomize/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,53 +100,63 @@
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: Ensure that tinyproxy is running
ansible.builtin.uri:
host: http://tinyproxy.stats/
use_proxy: true
status_code: 200
environment:
HTTP_PROXY: http://localhost:8888
register: result
retries: 3
delay: 10
until: result is ansible.builtin.successful

- 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
Expand All @@ -163,3 +173,7 @@
with_items:
- "{{ tmp_dir_path }}"
- "{{ _tmp_dir_kustomize.path }}"

- name: Stop tinyproxy
ansible.builtin.command: "docker stop tinyproxy"
ignore_errors: true

0 comments on commit fbfcadf

Please sign in to comment.