-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup_node_items
executable file
·80 lines (68 loc) · 2.57 KB
/
cleanup_node_items
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import argparse
import helpers as hp
CMD_DELETE_POD = "kubectl delete {api} -n {namespace} {app_name}"
POD_DELIMITER = "-"
def main(opts):
hp.acknowledge_deletion()
namespaces = hp.STANDARD_NAMESPACES
if not opts.clean_daemons:
del namespaces[namespaces.index("ospl-daemon")]
for namespace in namespaces:
command = hp.GET_PODS_CMD + f" -n {namespace}"
output = hp.run_cmd(command, as_lines=True)
for line in output:
if line == "":
continue
values = line.strip().split()
if values[0] == "NODE":
continue
if opts.node_name not in values[0]:
continue
parts = values[1].split(POD_DELIMITER)
api = hp.API_MAPPING[namespace]
if namespace == "kafka-producers":
app_name = POD_DELIMITER.join(parts[:3])
elif namespace == "ospl-daemon":
app_name = POD_DELIMITER.join(parts)
# For the daemons we want the pod not the daemonset
# since we are only deleting the one on the node.
api = "pod"
elif namespace == "love":
if parts[1] == "commander":
api = "job"
app_name = POD_DELIMITER.join(parts[:-1])
elif parts[1] == "producer":
api = "pod"
app_name = POD_DELIMITER.join(parts)
else:
continue
elif namespace == "uws":
if parts[1] == "server":
continue
else:
app_name = POD_DELIMITER.join(parts[:-1])
else:
app_name = POD_DELIMITER.join(parts[:-1])
command = CMD_DELETE_POD.format(
api=api, namespace=namespace, app_name=app_name
)
output1 = hp.run_cmd(command)
print(output1)
if __name__ == "__main__":
description = ["This program cleans up all deployed systems on a given node."]
description.append("It does not clean up the OSPL daemon by default.")
parser = argparse.ArgumentParser(
description=" ".join(description),
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("node_name", help="Name of the node to clean.")
parser.add_argument(
"-d",
"--clean-daemons",
dest="clean_daemons",
action="store_true",
help="Clean up the OSPL daemons.",
)
args = parser.parse_args()
main(args)