This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
- Loading branch information
Showing
7 changed files
with
346 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
- block: | ||
- set_fact: | ||
template_namespace: template-test | ||
|
||
- name: Ensure namespace exists | ||
k8s: | ||
definition: | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: "{{ template_namespace }}" | ||
|
||
- name: Check if k8s_service does not inherit parameter | ||
community.kubernetes.k8s_service: | ||
template: "pod_template_one.j2" | ||
state: present | ||
ignore_errors: yes | ||
register: r | ||
|
||
- name: Check for expected failures in last tasks | ||
assert: | ||
that: | ||
- r.failed | ||
- "'is only supported parameter for' in r.msg" | ||
|
||
- name: Specify both definition and template | ||
community.kubernetes.k8s: | ||
state: present | ||
template: "pod_template_one.j2" | ||
definition: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: apply-deploy | ||
namespace: "{{ template_namespace }}" | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: "{{ k8s_pod_name }}" | ||
vars: | ||
k8s_pod_name: pod | ||
k8s_pod_namespace: "{{ template_namespace }}" | ||
register: r | ||
ignore_errors: yes | ||
|
||
- name: Check if definition and template are mutually exclusive | ||
assert: | ||
that: | ||
- r.failed | ||
- "'parameters are mutually exclusive' in r.msg" | ||
|
||
- name: Specify both src and template | ||
community.kubernetes.k8s: | ||
state: present | ||
src: "../templates/pod_template_one.j2" | ||
template: "pod_template_one.j2" | ||
vars: | ||
k8s_pod_name: pod | ||
k8s_pod_namespace: "{{ template_namespace }}" | ||
register: r | ||
ignore_errors: yes | ||
|
||
- name: Check if src and template are mutually exclusive | ||
assert: | ||
that: | ||
- r.failed | ||
- "'parameters are mutually exclusive' in r.msg" | ||
|
||
- name: Create pod using template (direct specification) | ||
community.kubernetes.k8s: | ||
template: "pod_template_one.j2" | ||
wait: yes | ||
vars: | ||
k8s_pod_name: pod-1 | ||
k8s_pod_namespace: "{{ template_namespace }}" | ||
register: r | ||
|
||
- name: Assert that pod creation succeeded using template | ||
assert: | ||
that: | ||
- r is successful | ||
|
||
- name: Create pod using template with wrong parameter | ||
community.kubernetes.k8s: | ||
template: | ||
- default | ||
wait: yes | ||
vars: | ||
k8s_pod_name: pod-2 | ||
k8s_pod_namespace: "{{ template_namespace }}" | ||
register: r | ||
ignore_errors: True | ||
|
||
- name: Assert that pod creation failed using template due to wrong parameter | ||
assert: | ||
that: | ||
- r is failed | ||
- "'Error while reading template file' in r.msg" | ||
|
||
- name: Create pod using template (path parameter) | ||
community.kubernetes.k8s: | ||
template: | ||
path: "pod_template_one.j2" | ||
wait: yes | ||
vars: | ||
k8s_pod_name: pod-3 | ||
k8s_pod_namespace: "{{ template_namespace }}" | ||
register: r | ||
|
||
- name: Assert that pod creation succeeded using template | ||
assert: | ||
that: | ||
- r is successful | ||
|
||
- name: Create pod using template (different variable string) | ||
community.kubernetes.k8s: | ||
template: | ||
path: "pod_template_two.j2" | ||
variable_start_string: '[[' | ||
variable_end_string: ']]' | ||
wait: yes | ||
vars: | ||
k8s_pod_name: pod-4 | ||
k8s_pod_namespace: "[[ template_namespace ]]" | ||
register: r | ||
|
||
- name: Assert that pod creation succeeded using template | ||
assert: | ||
that: | ||
- r is successful | ||
|
||
- name: Remove Pod (Cleanup) | ||
k8s: | ||
api_version: v1 | ||
kind: Pod | ||
name: "{{ item }}" | ||
namespace: "{{ template_namespace }}" | ||
state: absent | ||
wait: yes | ||
ignore_errors: yes | ||
with_items: | ||
- pod-1 | ||
- pod-2 | ||
- pod-3 | ||
- pod-4 | ||
|
||
always: | ||
- name: Remove namespace (Cleanup) | ||
k8s: | ||
kind: Namespace | ||
name: "{{ template_namespace }}" | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
app: "{{ k8s_pod_name }}" | ||
name: '{{ k8s_pod_name }}' | ||
namespace: '{{ k8s_pod_namespace }}' | ||
spec: | ||
containers: | ||
- args: | ||
- /bin/sh | ||
- -c | ||
- while true; do echo $(date); sleep 10; done | ||
image: python:3.7-alpine | ||
imagePullPolicy: Always | ||
name: '{{ k8s_pod_name }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
app: '[[ k8s_pod_name ]]' | ||
name: '[[ k8s_pod_name ]]' | ||
namespace: '[[ k8s_pod_namespace ]]' | ||
spec: | ||
containers: | ||
- args: | ||
- /bin/sh | ||
- -c | ||
- while true; do echo $(date); sleep 10; done | ||
image: python:3.7-alpine | ||
imagePullPolicy: Always | ||
name: '[[ k8s_pod_name ]]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.