-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.py
50 lines (40 loc) · 1.9 KB
/
cleanup.py
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
50
from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
import yaml
from kubernetes import client
from kubernetes.config.kube_config import KubeConfigLoader
import os
credential = DefaultAzureCredential()
container_service_client = ContainerServiceClient(credential, '60f3ac75-ce11-4deb-9030-d3896b73c46c')
rg_name = ""
cluster_name = ""
with open(os.path.join(os.path.dirname(__file__), "cluster_config.yaml")) as f:
cluster_config = yaml.safe_load(f)
rg_name = cluster_config["rg_name"]
cluster_name = cluster_config["cluster_name"]
kubeconfig = container_service_client.managed_clusters.list_cluster_user_credentials(rg_name, cluster_name).kubeconfigs[0].value.decode("utf-8")
cfg_dict = yaml.safe_load(kubeconfig)
loader = KubeConfigLoader(cfg_dict)
config = client.Configuration()
loader.load_and_set(config)
client.Configuration.set_default(config)
core_v1 = client.CoreV1Api()
apps_v1 = client.AppsV1Api()
print("Deleting config map ")
with open(os.path.join(os.path.dirname(__file__), "configs.yaml")) as f:
dep = yaml.safe_load(f)
import pdb
resp = core_v1.delete_namespaced_config_map(dep['metadata']['name'], "default")
print("Deleting Volume")
with open(os.path.join(os.path.dirname(__file__), "fio_pv.yaml")) as f:
dep = yaml.safe_load(f)
resp = core_v1.delete_persistent_volume(dep['metadata']['name'])
print("Deleting Persistent Volume Claim")
with open(os.path.join(os.path.dirname(__file__), "fio_pvc.yaml")) as f:
dep = yaml.safe_load(f)
resp = core_v1.delete_namespaced_persistent_volume_claim(dep['metadata']['name'], "default")
print("Deleting fio deployment")
with open(os.path.join(os.path.dirname(__file__), "fio_deployment_pvc.yaml")) as f:
dep = yaml.safe_load(f)
resp = apps_v1.delete_namespaced_deployment(
dep['metadata']['name'], namespace="default")