-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor.py
24 lines (19 loc) · 971 Bytes
/
executor.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
from kubernetes.client import ApiException
def execute(deploys):
from kubernetes import client, config
from time import time
configuration = config.load_kube_config()
api_instance = client.AppsV1Api(client.ApiClient(configuration))
for dname, deploy in deploys.items():
if deploy['adaptation_command'] != '':
name = dname
replicas_neeeded = deploy['replicas']['needed']
namespace = deploy['namespace']
body = {'spec': {'replicas': replicas_neeeded}}
pretty = 'true'
try:
api_instance.patch_namespaced_deployment_scale(name, namespace, body, pretty=pretty)
deploy['stabilization'][deploy['adaptation_command']] = time()
print(name + ' have a scale operation', replicas_neeeded)
except ApiException as e:
print("Exception when calling AppsV1Api->patch_namespaced_deployment_scale: %s\n" % e)