-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdelete_namespace.yml
49 lines (42 loc) · 1.46 KB
/
delete_namespace.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
# This playbook deletes a K8S namespace for a particular
# customer/environment
- name: Delete namespace
hosts: local
gather_facts: false
pre_tasks:
- name: Check configuration
ansible.builtin.import_tasks: tasks/check_configuration.yml
tasks:
- name: Display playbook name
ansible.builtin.debug: msg="==== Starting delete_namespace playbook ===="
tags: deploy
- name: Set vars
ansible.builtin.import_tasks: tasks/set_vars.yml
# We must check if the namespace exists first. Without this condition, k8s
# will try to delete a missing namespace and returns a 403 ¯\_(ツ)_/¯
- name: Check if namespace exists
kubernetes.core.k8s_info:
api_version: v1
kind: Namespace
field_selectors:
- metadata.name={{ namespace_name }}
register: namespace
- name: Delete the namespace
kubernetes.core.k8s:
api_version: v1
kind: Namespace
name: "{{ namespace_name }}"
state: absent
when: namespace.resources | length > 0
- name: Wait for namespace to be terminated
kubernetes.core.k8s_info:
api_version: "v1"
kind: Namespace
field_selectors:
- metadata.name={{ namespace_name }}
register: terminating_namespaces
until: terminating_namespaces.resources is defined and (terminating_namespaces.resources | length) == 0
retries: 120
delay: 5
when: namespace.resources | length > 0