mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-06-10 10:36:16 +00:00
kustomize lookup plugin SUMMARY new lookup plugin to support kustomize feature for kubernetes ISSUE TYPE Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: None <None> Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: None <None>
104 lines
2.9 KiB
YAML
104 lines
2.9 KiB
YAML
---
|
|
- block:
|
|
- set_fact:
|
|
kustomize_ns: "kustomize"
|
|
|
|
- name: create environment for test
|
|
block:
|
|
- name: Ensure namespace
|
|
k8s:
|
|
kind: Namespace
|
|
name: "{{ kustomize_ns }}"
|
|
|
|
- name: Create temp directory
|
|
tempfile:
|
|
state: directory
|
|
suffix: .test
|
|
register: _tmp_dir
|
|
|
|
- set_fact:
|
|
tmp_dir_path: "{{ _tmp_dir.path }}"
|
|
|
|
- set_fact:
|
|
kustomize_dir: "{{ tmp_dir_path }}/kustomization"
|
|
|
|
- name: create kustomize directory
|
|
file:
|
|
path: "{{ kustomize_dir }}"
|
|
state: directory
|
|
|
|
- name: create kustomization file
|
|
copy:
|
|
content: '{{ item.content }}'
|
|
dest: '{{ item.dest }}'
|
|
with_items:
|
|
- content: |
|
|
configMapGenerator:
|
|
- name: test-confmap-
|
|
files:
|
|
- data.properties
|
|
dest: "{{ kustomize_dir }}/kustomization.yaml"
|
|
- content: "project=ansible"
|
|
dest: "{{ kustomize_dir }}/data.properties"
|
|
|
|
- name: copy script to install kustomize
|
|
get_url:
|
|
url: https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh
|
|
dest: "{{ tmp_dir_path }}"
|
|
|
|
- name: make script as executable
|
|
file:
|
|
path: "{{ tmp_dir_path }}/install_kustomize.sh"
|
|
mode: 0755
|
|
|
|
- name: Install kustomize
|
|
command: "{{ tmp_dir_path }}/install_kustomize.sh"
|
|
args:
|
|
chdir: "{{ tmp_dir_path }}"
|
|
register: _install
|
|
|
|
- set_fact:
|
|
kustomize_binary: "{{ _install.stdout | regex_search('kustomize installed to (.*)', '\\1') | list | join('') }}"
|
|
kubectl_binary: "{{ tmp_dir_path }}/kubectl"
|
|
|
|
- name: Download kubeclt executable used to compare results
|
|
get_url:
|
|
url: https://dl.k8s.io/release/v1.21.3/bin/linux/amd64/kubectl
|
|
dest: "{{ kubectl_binary }}"
|
|
|
|
- name: make kubectl executable
|
|
ansible.builtin.file:
|
|
path: "{{ kubectl_binary }}"
|
|
mode: "+x"
|
|
|
|
- name: Run lookup using kustomize binary
|
|
set_fact:
|
|
resource_kustomize: "{{ lookup('kubernetes.core.kustomize', binary_path=kustomize_binary, dir=kustomize_dir) }}"
|
|
|
|
- name: Run lookup using kubectl binary
|
|
set_fact:
|
|
resource_kubectl: "{{ lookup('kubernetes.core.kustomize', binary_path=kubectl_binary, dir=kustomize_dir) }}"
|
|
|
|
- name: assert output are the same
|
|
assert:
|
|
that:
|
|
- resource_kubectl == resource_kustomize
|
|
|
|
- name: create kubernetes resource using lookup plugin
|
|
k8s:
|
|
namespace: "{{ kustomize_ns }}"
|
|
definition: "{{ lookup('kubernetes.core.kustomize', dir=kustomize_dir, opt_dirs=tmp_dir_path) }}"
|
|
|
|
always:
|
|
- name: Delete namespace
|
|
k8s:
|
|
kind: Namespace
|
|
name: "{{ kustomize_ns }}"
|
|
state: absent
|
|
ignore_errors: true
|
|
|
|
- name: Delete temporary directory
|
|
file:
|
|
state: absent
|
|
path: "{{ tmp_dir_path }}"
|