Files
kubernetes.core/molecule/default/tasks/lookup_k8s.yml
Abhijeet Kasurde cf0b71f93e lookup: return list even if single item found (#117)
Always return list from k8s lookup plugin

Fixes: #9

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-06-04 10:23:21 +05:30

55 lines
1.6 KiB
YAML

---
- block:
# https://github.com/ansible-collections/kubernetes.core/issues/9
- name: Create a namespace with label
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: Namespace
metadata:
name: "app-development-one"
labels:
namespace_label: "app_development"
- set_fact:
namespace_info: "{{ lookup('kubernetes.core.k8s', kind='Namespace', label_selector='namespace_label=app_development') }}"
- name: Check if the returned value is list with a single element
assert:
that:
- namespace_info is iterable
- not namespace_info is string
- not namespace_info is mapping
- namespace_info | length == 1
- name: Create another namespace with label
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: Namespace
metadata:
name: "app-development-two"
labels:
namespace_label: "app_development"
- set_fact:
namespace_info: "{{ lookup('kubernetes.core.k8s', kind='Namespace', label_selector='namespace_label=app_development') }}"
- name: Check if the returned value is list with 2 elements
assert:
that:
- namespace_info is iterable
- not namespace_info is string
- not namespace_info is mapping
- namespace_info | length == 2
always:
- name: Ensure that namespace is removed
k8s:
kind: Namespace
name: "{{ item }}"
state: absent
with_items:
- app-development-one
- app-development-two