-
Notifications
You must be signed in to change notification settings - Fork 8
/
custom-node-list
executable file
·48 lines (41 loc) · 1.37 KB
/
custom-node-list
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
#!/usr/bin/env python3
import os
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from prettytable import PrettyTable
kubeconfig = os.getenv("K8S_AUTH_KUBECONFIG") or os.getenv("KUBECONFIG")
config.load_kube_config(kubeconfig)
def get_items():
t = PrettyTable(['Name', 'Status', 'Roles'])
t.align['Name'] = 'l'
t.align['Status'] = 'l'
t.align['Roles'] = 'l'
t.border = False
t.right_padding_width = 3
t.left_padding_width = 0
v1 = client.CoreV1Api()
out = v1.list_node()
for item in out.items:
cMap = {}
for cond in item.status.conditions:
cMap[cond.type] = cond
status = ""
if cMap.get('Ready'):
if cMap['Ready'].status:
status = "Ready"
else:
status = "NotReady"
else:
status = "Unknown"
if item.spec.unschedulable:
status += ",SchedulingDisabled"
role = ''
for k,v in item.metadata.labels.items():
if "node-role.kubernetes.io" in k:
if role:
role += ","
role += k.split("/")[1]
t.add_row([item.metadata.name, status, role])
print(t)
if __name__ == "__main__":
get_items()