diff --git a/changelogs/fragments/243_template.yml b/changelogs/fragments/243_template.yml new file mode 100644 index 00000000..9a1630eb --- /dev/null +++ b/changelogs/fragments/243_template.yml @@ -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). diff --git a/molecule/default/tasks/template.yml b/molecule/default/tasks/template.yml index ea9344b3..4d76d799 100644 --- a/molecule/default/tasks/template.yml +++ b/molecule/default/tasks/template.yml @@ -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) diff --git a/molecule/default/templates/pod_template_three.j2 b/molecule/default/templates/pod_template_three.j2 new file mode 100644 index 00000000..06e4686e --- /dev/null +++ b/molecule/default/templates/pod_template_three.j2 @@ -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 }}'