Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor integration test for kustomize environ support
Browse files Browse the repository at this point in the history
yurnov committed Nov 21, 2024
1 parent ad60093 commit 8983d31
Showing 2 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
test_namespace: "kustomize"
proxy_port: 8888
64 changes: 36 additions & 28 deletions tests/integration/targets/lookup_kustomize/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8983d31

Please sign in to comment.