Skip to content
Snippets Groups Projects
Commit c6fa5785 authored by Björn Vonheiden's avatar Björn Vonheiden
Browse files

Use kubernetes api to apply the workload generatorin kubernetes

Use the kubernetes api in python to run the kubernetes creation
operations instead of the default platform commands.
parent 2d8edbfa
No related branches found
No related tags found
No related merge requests found
...@@ -110,35 +110,26 @@ def start_workload_generator(): ...@@ -110,35 +110,26 @@ def start_workload_generator():
# TODO: How is this calculation done? # TODO: How is this calculation done?
wl_instances = int(((num_sensors + (wl_max_records - 1)) / wl_max_records)) wl_instances = int(((num_sensors + (wl_max_records - 1)) / wl_max_records))
parameters_path = 'uc-workload-generator/overlay/uc' + args.uc_id\
+ '-workload-generator'
f = open(parameters_path + '/set_paramters.yaml', 'w')
f.write('\
apiVersion: apps/v1\n\
kind: StatefulSet\n\
metadata:\n\
name: titan-ccp-load-generator\n\
spec:\n\
replicas: ' + str(wl_instances) + '\n\
template:\n\
spec:\n\
containers:\n\
- name: workload-generator\n\
env:\n\
- name: NUM_SENSORS\n\
value: "' + str(num_sensors) + '"\n\
- name: INSTANCES\n\
value: "' + str(wl_instances) + '"\n')
f.close()
exec_command = [ # Create statefull set
'kubectl', with open(path.join(path.dirname(__file__), "uc-workload-generator/base/workloadGenerator.yaml")) as f:
'apply', dep = yaml.safe_load(f)
'-k', dep['spec']['replicas'] = wl_instances
parameters_path # TODO: acces over name of container
] wg_containter = dep['spec']['template']['spec']['containers'][0]
output = subprocess.run(exec_command, capture_output=True, text=True) wg_containter['image'] = 'soerenhenning/uc' + args.uc_id + '-wg:latest'
print(output) # TODO: acces over name of attribute
wg_containter['env'][1]['value'] = str(num_sensors)
wg_containter['env'][2]['value'] = str(wl_instances)
print(dep)
try:
resp = appsApi.create_namespaced_stateful_set(
namespace="default",
body=dep
)
print("StatefulSet '%s' created." % resp.metadata.name)
except client.rest.ApiException as e:
print("StatefulSet creation error: %s" % e.reason)
return return
...@@ -184,11 +175,13 @@ def start_application(): ...@@ -184,11 +175,13 @@ def start_application():
with open(path.join(path.dirname(__file__), "uc-application/base/aggregation-deployment.yaml")) as f: with open(path.join(path.dirname(__file__), "uc-application/base/aggregation-deployment.yaml")) as f:
dep = yaml.safe_load(f) dep = yaml.safe_load(f)
dep['spec']['replicas'] = args.instances dep['spec']['replicas'] = args.instances
uc_container = dep['spec']['template']['spec']['containers'][0] # TODO: acces over name of container
uc_container['image'] = 'soerenhenning/uc1-app:latest' app_container = dep['spec']['template']['spec']['containers'][0]
uc_container['env'][1]['value'] = str(args.commit_interval_ms) app_container['image'] = 'soerenhenning/uc' + args.uc_id + '-app:latest'
uc_container['resources']['limits']['memory'] = str(args.memory_limit) # TODO: acces over name of attribute
uc_container['resources']['limits']['cpu'] = str(args.cpu_limit) # cpu limit is already str app_container['env'][1]['value'] = str(args.commit_interval_ms)
app_container['resources']['limits']['memory'] = str(args.memory_limit)
app_container['resources']['limits']['cpu'] = str(args.cpu_limit) # cpu limit is already str
try: try:
resp = appsApi.create_namespaced_deployment( resp = appsApi.create_namespaced_deployment(
namespace="default", namespace="default",
......
...@@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1 ...@@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
- deployment.yaml - workloadGenerator.yaml
...@@ -22,9 +22,9 @@ spec: ...@@ -22,9 +22,9 @@ spec:
value: "my-confluent-cp-kafka:9092" value: "my-confluent-cp-kafka:9092"
- name: NUM_SENSORS - name: NUM_SENSORS
value: "25000" value: "25000"
- name: INSTANCES
value: "1"
- name: POD_NAME - name: POD_NAME
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.name fieldPath: metadata.name
- name: INSTANCES
value: "1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment