@ -1,16 +1,16 @@
# TODO: This is the only way I could get the kubeconfig, I don't know why. Running the lookup outside of debug seems to return an empty string
# TODO: This is the only way I could get the kubeconfig, I don't know why. Running the lookup outside of debug seems to return an empty string
- debug : msg={{ lookup('env', 'K8S_AUTH_KUBECONFIG') }}
# - debug: msg={{ lookup('env', 'K8S_AUTH_KUBECONFIG') }}
register : kubeconfig
# register: kubeconfig
# Kubernetes resources
# Kubernetes resources
- block:
- name : Create a namespace
- name : Create a namespace
k8s:
k8s:
name : testing
name : testing
kind : namespace
kind : namespace
register : output
register : output
- debug : msg={{ lookup("k8s", kind="Namespace", api_version="v1", resource_name='testing', kubeconfig=kubeconfig.msg) }}
- name : show output
- name : show output
debug:
debug:
var : output
var : output
@ -202,8 +202,12 @@
name : testing1
name : testing1
- name : Namespace should exist
- name : Namespace should exist
assert:
k8s_facts:
that : '{{ lookup("k8s", kind="Namespace", api_version="v1", resource_name="testing1", kubeconfig=kubeconfig.msg).status.phase == "Active" }}'
kind : Namespace
api_version : v1
name : testing1
register : k8s_facts_testing1
failed_when : not k8s_facts_testing1.resources or k8s_facts_testing1.resources[0].status.phase != "Active"
- name : Create resources from a multidocument yaml string
- name : Create resources from a multidocument yaml string
k8s:
k8s:
@ -219,12 +223,20 @@
metadata:
metadata:
name : testing3
name : testing3
- name : Resources should exist
- name : Lookup namespaces
assert:
k8s_facts:
that : lookup("k8s", kind="Namespace", api_version="v1", resource_name=item, kubeconfig=kubeconfig.msg).status.phase == "Active"
api_version : v1
kind : Namespace
name : "{{ item }}"
loop:
loop:
- testing2
- testing2
- testing3
- testing3
register : k8s_namespaces
- name : Resources should exist
assert:
that : item.resources[0].status.phase == 'Active'
loop : "{{ k8s_namespaces.results }}"
- name : Delete resources from a multidocument yaml string
- name : Delete resources from a multidocument yaml string
k8s:
k8s:
@ -241,14 +253,21 @@
metadata:
metadata:
name : testing3
name : testing3
- name : Resources should not exist
- name : Lookup namespaces
assert:
k8s_facts:
that : not ns or ns.status.phase == "Terminating"
api_version : v1
kind : Namespace
name : "{{ item }}"
loop:
loop:
- testing2
- testing2
- testing3
- testing3
vars:
register : k8s_namespaces
ns : '{{ lookup("k8s", kind="Namespace", api_version="v1", resource_name=item, kubeconfig=kubeconfig.msg) }}'
- name : Resources should not exist
assert:
that:
- not item.resources or item.resources[0].status.phase == "Terminating"
loop : "{{ k8s_namespaces.results }}"
- name : Create resources from a list
- name : Create resources from a list
k8s:
k8s:
@ -262,12 +281,64 @@
metadata:
metadata:
name : testing5
name : testing5
- name : Resources should exist
- name : Lookup namespaces
assert:
k8s_facts:
that : lookup("k8s", kind="Namespace", api_version="v1", resource_name=item, kubeconfig=kubeconfig.msg).status.phase == "Active"
api_version : v1
kind : Namespace
name : "{{ item }}"
loop:
loop:
- testing4
- testing4
- testing5
- testing5
register : k8s_namespaces
- name : Resources should exist
assert:
that : item.resources[0].status.phase == 'Active'
loop : "{{ k8s_namespaces.results }}"
- name : install custom resource definitions
k8s:
definition : "{{ lookup('file', role_path + '/files/setup-crd.yml') }}"
- name : create custom resource definition
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
namespace : testing4
register : create_crd
- name : recreate custom resource definition
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
namespace : testing4
register : recreate_crd
ignore_errors : yes
- name : assert that recreating crd fails
assert:
that:
- recreate_crd is failed
- name : recreate custom resource definition with merge_type
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
merge_type : merge
namespace : testing4
register : recreate_crd_with_merge
- name : recreate custom resource definition with merge_type list
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
merge_type:
- strategic-merge
- merge
namespace : testing4
register : recreate_crd_with_merge_list
- name : remove crd
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
namespace : testing4
state : absent
- name : Delete resources from a list
- name : Delete resources from a list
k8s:
k8s:
@ -282,11 +353,50 @@
metadata:
metadata:
name : testing5
name : testing5
- name : Resources should not exist
- k8s_facts:
assert:
api_version : v1
that : not ns or ns.status.phase == "Terminating"
kind : Namespace
name : "{{ item }}"
loop:
loop:
- testing4
- testing4
- testing5
- testing5
vars:
register : k8s_facts
ns : '{{ lookup("k8s", kind="Namespace", api_version="v1", resource_name=item, kubeconfig=kubeconfig.msg) }}'
- name : Resources are terminating if still in results
assert:
that : not item.resources or item.resources[0].status.phase == "Terminating"
loop : "{{ k8s_facts.results }}"
always:
- name : remove crd
k8s:
definition : "{{ lookup('file', role_path + '/files/crd-resource.yml') }}"
namespace : testing4
state : absent
ignore_errors : yes
- name : Delete all namespaces
k8s:
state : absent
definition:
- kind : Namespace
apiVersion : v1
metadata:
name : testing1
- kind : Namespace
apiVersion : v1
metadata:
name : testing2
- kind : Namespace
apiVersion : v1
metadata:
name : testing3
- kind : Namespace
apiVersion : v1
metadata:
name : testing4
- kind : Namespace
apiVersion : v1
metadata:
name : testing5
ignore_errors : yes