Skip to content

Commit

Permalink
Add ci_kustomize action plugin
Browse files Browse the repository at this point in the history
This action plugin is a direct replacement of the edpm_kustomize role.
It takes a path to the file you want to kustomize and applies a set of
kustomizations given though it's kustomizations parameter or through
file ones placed on the same directory where the target manifest is
placed.
  • Loading branch information
pablintino committed Sep 20, 2023
1 parent c987b0c commit 299054e
Show file tree
Hide file tree
Showing 24 changed files with 2,333 additions and 0 deletions.
762 changes: 762 additions & 0 deletions ci_framework/plugins/action/ci_kustomize.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-1
value: "cifmw-label-1-value"
- op: replace
path: /metadata/labels/cifmw-label-2
value: "cifmw-label-2-value"
- op: replace
path: /metadata/labels/cifmw-label-3
value: "cifmw-label-3-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-1
value: "cifmw-label-1-value-override-b"
- op: replace
path: /metadata/labels/cifmw-label-2
value: "cifmw-label-2-value-override-b"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-2
value: "cifmw-label-2-value-override-c"
- op: replace
path: /metadata/labels/cifmw-label-3
value: "cifmw-label-3-value-override-c"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-1
value: "cifmw-label-1-value"
target:
kind: ConfigMap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-2
value: "cifmw-label-2-value"
target:
kind: ConfigMap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-1
value: "cifmw-label-1-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-2
value: "cifmw-label-2-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-4
value: "cifmw-label-4-value"
target:
kind: Deployment
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-5
value: "cifmw-label-5-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-3
value: "cifmw-label-3-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |-
- op: replace
path: /metadata/labels/cifmw-label-6
value: "cifmw-label-6-value"
target:
kind: Deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: testing-cm
labels:
app: test
data:
test1.properties: |
test-var=test-value
test2.properties: |
test-var2=test-value2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Secret
metadata:
name: testing-secret
labels:
app: test
data:
.secret-file: dmFsdWUtMg0KDQo=
---
apiVersion: batch/v1
kind: Job
metadata:
name: testing-job
labels:
app: test
spec:
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: testing-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
53 changes: 53 additions & 0 deletions ci_framework/tests/integration/targets/kustomize/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
- name: "Create a directory to download each kustomization tool"
ansible.builtin.tempfile:
state: directory
suffix: cifmw-ci-kustomize-bins-dir
register: _ci_kustomize_temporal_bins_dir

- name: Set files dir as a fact
vars:
role_test_dir: "{{ ansible_env.HOME }}/code/ansible_collections/cifmw/general/tests/integration/targets/kustomize"
ansible.builtin.set_fact:
ci_kustomize_scenarios_dir_path: "{{ role_test_dir }}/tasks/scenarios"
ci_kustomize_files_dir_path: "{{ role_test_dir }}/files"
ci_kustomize_oc_bin_path: "{{ _ci_kustomize_temporal_bins_dir.path }}/oc"
ci_kustomize_kustomize_bin_path: "{{ _ci_kustomize_temporal_bins_dir.path }}/kustomize"

- name: Create OC and kustomize binaries path
ansible.builtin.file:
path: "{{ item }}"
state: directory
loop:
- "{{ ci_kustomize_oc_bin_path }}"
- "{{ ci_kustomize_kustomize_bin_path }}"

- name: Fetch oc from OCP mirror
ansible.builtin.unarchive:
src: https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux.tar.gz
dest: "{{ ci_kustomize_oc_bin_path }}"
remote_src: true

- name: Fetch kustomize from sigs Github
ansible.builtin.unarchive:
src: https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.1/kustomize_v5.1.1_linux_amd64.tar.gz
dest: "{{ ci_kustomize_kustomize_bin_path }}"
remote_src: true

- name: Recursively find scenario files
ansible.builtin.find:
paths: "{{ ci_kustomize_scenarios_dir_path }}"
patterns: '*.yml'
register: ci_kustomize_scenarios_find

- name: Run scenario file
ansible.builtin.include_tasks: "{{ scenario_path }}"
loop: "{{ ci_kustomize_scenarios_find.files | map(attribute='path') }}"
loop_control:
label: "{{ scenario_path }}"
loop_var: "scenario_path"

- name: "Delete the temporal bins directory"
ansible.builtin.file:
path: "{{ _ci_kustomize_temporal_bins_dir.path }}"
state: absent
Loading

0 comments on commit 299054e

Please sign in to comment.