-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
64 lines (56 loc) · 1.84 KB
/
Copy pathutil.py
File metadata and controls
64 lines (56 loc) · 1.84 KB
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
import subprocess
import time
from kubernetes import client, config
def deployment_exists(name, namespace):
config.load_kube_config()
v1 = client.AppsV1Api()
resp = v1.list_namespaced_deployment(namespace=namespace)
for i in resp.items:
if i.metadata.name == name:
return True
return False
def service_exists(name, namespace):
config.load_kube_config()
v1 = client.CoreV1Api()
resp = v1.list_namespaced_service(namespace=namespace)
for i in resp.items:
if i.metadata.name == name:
return True
return False
# 能用就行
def check_pod_node(pod_str = "redis-deployment"):
'''
返回集群中相关pod对应node的数量
'''
par_dict = {}
config.load_kube_config()
api_read = client.CoreV1Api()
ret = api_read.list_pod_for_all_namespaces(watch=False)
replicas_137 = 0
replicas_234 = 0
replicas_192 = 0
for itm in ret.items:
if pod_str in itm.metadata.name:
if "192.168.0.137" in itm.spec.node_name:
replicas_137 += 1
if "192.168.0.234" in itm.spec.node_name:
replicas_234 += 1
if "192.168.0.192" in itm.spec.node_name:
replicas_192 += 1
par_dict["192.168.0.137"] = replicas_137
par_dict["192.168.0.234"] = replicas_234
par_dict["192.168.0.192"] = replicas_192
return par_dict
def wait_name_space_deployments_ready(namespace:str, args:list):
# 是否所有的Pod都Ready
# Deployment ——> ReplicaSet ——> Pods
api = client.AppsV1Api()
if_ready = True
while True:
time.sleep(1)
for itm in args:
info = api.read_namespaced_deployment(itm, namespace=namespace)
if info.status.ready_replicas != info.spec.replicas:
if_ready = False
if if_ready:
break