Skip to content

Commit

Permalink
Add testcase for multi resource template
Browse files Browse the repository at this point in the history
User can combine multiple resources in the given template
file, which can be consumed by k8s module to create multiple
resources at once.

Fixes: ansible-collections#243

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Oct 1, 2020
1 parent 7946b39 commit 86bb7d8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/243_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- k8s - add testcase for adding multiple resources using template parameter (https://github.com/ansible-collections/community.kubernetes/issues/243).
24 changes: 18 additions & 6 deletions molecule/default/tasks/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,32 @@
that:
- r is successful

- name: Create pods using multi-resource template
community.kubernetes.k8s:
template:
path: "pod_template_three.j2"
wait: yes
vars:
k8s_pod_name_one: pod-5
k8s_pod_name_two: pod-6
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 }}"
name: "pod-{{ item }}"
namespace: "{{ template_namespace }}"
state: absent
wait: yes
ignore_errors: yes
with_items:
- pod-1
- pod-2
- pod-3
- pod-4
loop: "{{ range(1, 7) | list }}"

always:
- name: Remove namespace (Cleanup)
Expand Down
35 changes: 35 additions & 0 deletions molecule/default/templates/pod_template_three.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_name_one }}"
name: '{{ k8s_pod_name_one }}'
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_one }}'

---
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_name_two }}"
name: '{{ k8s_pod_name_two }}'
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_two }}'

0 comments on commit 86bb7d8

Please sign in to comment.