Reputation: 18187
I am trying to validate that the pod is deleted.
- name: Verify whether the POD is deleted
command: "{{ local_kubectl }} get pod {{ pod_name}}"
but the task is failing as the command displays error as below
'Error from server (NotFound): pods ....'
But this is expected when i am checking for deletion of pod.
How to pass this task when it returns an error message?
Upvotes: 0
Views: 3446
Reputation: 41
Late response. Hope it is helpful to someone. https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html
- name: Delete pod
kubernetes.core.k8s:
state: absent
kind: Pod
name: "{{pod_name}}"
namespace: "{{test_ns}}"
kubeconfig: "{{ config }}"
wait: true
wait_condition:
status: False #wait for status to be false
wait_sleep: 2 #check every 2 secs
Upvotes: 1
Reputation: 68104
Try k8s_facts
- k8s_facts:
kind: Pod
name: "{{ pod_name}}"
register: result
- debug:
var: result
(not tested)
Upvotes: 1
Reputation: 159242
You can just directly specify this using the k8s module
- name: Delete the POD
k8s:
api_version: v1
kind: Pod
namespace: "{{ k8s_namespace }}"
name: "{{ pod_name }}"
state: absent
Another path is to redefine "failure" to check for the expected result string.
- name: Verify whether the POD is deleted
command: "{{ local_kubectl }} get pod {{ pod_name}}"
register: verify
failed_when: "'NotFound' not in verify.stderr"
Upvotes: 4