forked from mipearlska/Predictive_TrafficStatCRD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_createTrafficStatCRD.py
57 lines (47 loc) · 1.25 KB
/
test_createTrafficStatCRD.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
51
52
53
54
55
56
57
from kubernetes import client, config
from pprint import pprint
def main():
config.load_kube_config()
api = client.CustomObjectsApi()
TrafficStat_resource = {
"apiVersion": "hybridscaling.knativescaling.dcn.ssu.ac.kr/v1",
"kind": "TrafficStat",
"metadata": {"name": "deploy-a-trafficstat-test"},
"spec": {
"servicename": "deploy-a",
"scalinginputtraffic": "100"
}
}
list = api.list_namespaced_custom_object(
group="hybridscaling.knativescaling.dcn.ssu.ac.kr",
version="v1",
namespace="default",
plural="trafficstats"
)
if len(list['items']) == 0:
flag = False
else:
flag = False
for item in list['items']:
if "deploy-a" in item['metadata']['name']:
flag = True
if flag != True:
api.create_namespaced_custom_object(
group="hybridscaling.knativescaling.dcn.ssu.ac.kr",
version="v1",
namespace="default",
plural="trafficstats",
body=TrafficStat_resource,
)
print("Resource created")
else:
api.patch_namespaced_custom_object(
group="hybridscaling.knativescaling.dcn.ssu.ac.kr",
version="v1",
name="deploy-a-trafficstat-test",
namespace="default",
plural="trafficstats",
body=TrafficStat_resource,
)
if __name__ == "__main__":
main()