Skip to content
Snippets Groups Projects
Commit af52a538 authored by Sören Henning's avatar Sören Henning
Browse files

Merge branch 'feature/kubernetesNamespace' into 'master'

Configurable Namespace in run uc python

See merge request !53
parents ebb8230b d970f47e
Branches
Tags
1 merge request!53Configurable Namespace in run uc python
Pipeline #1175 passed
...@@ -44,6 +44,10 @@ def default_parser(description): ...@@ -44,6 +44,10 @@ def default_parser(description):
default=os.environ.get('DURATION', 5), default=os.environ.get('DURATION', 5),
help='Duration in minutes subexperiments should be \ help='Duration in minutes subexperiments should be \
executed for') executed for')
parser.add_argument('--namespace',
metavar='<NS>',
default=os.environ.get('NAMESPACE', 'default'),
help='Defines the Kubernetes where the applications should run')
parser.add_argument('--reset', parser.add_argument('--reset',
action="store_true", action="store_true",
help='Resets the environment before execution') help='Resets the environment before execution')
......
...@@ -15,6 +15,8 @@ coreApi = None # acces kubernetes core api ...@@ -15,6 +15,8 @@ coreApi = None # acces kubernetes core api
appsApi = None # acces kubernetes apps api appsApi = None # acces kubernetes apps api
customApi = None # acces kubernetes custom object api customApi = None # acces kubernetes custom object api
namespace = None
def load_variables(): def load_variables():
"""Load the CLI variables given at the command line""" """Load the CLI variables given at the command line"""
...@@ -67,7 +69,7 @@ def create_topics(topics): ...@@ -67,7 +69,7 @@ def create_topics(topics):
] ]
resp = stream(coreApi.connect_get_namespaced_pod_exec, resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client", "kafka-client",
'default', namespace,
command=exec_command, command=exec_command,
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False) stdout=True, tty=False)
...@@ -144,7 +146,7 @@ def start_workload_generator(wg_yaml, dim_value, uc_id): ...@@ -144,7 +146,7 @@ def start_workload_generator(wg_yaml, dim_value, uc_id):
try: try:
wg_ss = appsApi.create_namespaced_deployment( wg_ss = appsApi.create_namespaced_deployment(
namespace="default", namespace=namespace,
body=wg_yaml body=wg_yaml
) )
print("Deployment '%s' created." % wg_ss.metadata.name) print("Deployment '%s' created." % wg_ss.metadata.name)
...@@ -178,7 +180,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc ...@@ -178,7 +180,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
# Create Service # Create Service
try: try:
svc = coreApi.create_namespaced_service( svc = coreApi.create_namespaced_service(
namespace="default", body=svc_yaml) namespace=namespace, body=svc_yaml)
print("Service '%s' created." % svc.metadata.name) print("Service '%s' created." % svc.metadata.name)
except client.rest.ApiException as e: except client.rest.ApiException as e:
svc = svc_yaml svc = svc_yaml
...@@ -189,7 +191,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc ...@@ -189,7 +191,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
svc_monitor = customApi.create_namespaced_custom_object( svc_monitor = customApi.create_namespaced_custom_object(
group="monitoring.coreos.com", group="monitoring.coreos.com",
version="v1", version="v1",
namespace="default", namespace=namespace,
plural="servicemonitors", # CustomResourceDef of ServiceMonitor plural="servicemonitors", # CustomResourceDef of ServiceMonitor
body=svc_monitor_yaml, body=svc_monitor_yaml,
) )
...@@ -201,7 +203,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc ...@@ -201,7 +203,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
# Apply jmx config map for aggregation service # Apply jmx config map for aggregation service
try: try:
jmx_cm = coreApi.create_namespaced_config_map( jmx_cm = coreApi.create_namespaced_config_map(
namespace="default", body=jmx_yaml) namespace=namespace, body=jmx_yaml)
print("ConfigMap '%s' created." % jmx_cm.metadata.name) print("ConfigMap '%s' created." % jmx_cm.metadata.name)
except client.rest.ApiException as e: except client.rest.ApiException as e:
jmx_cm = jmx_yaml jmx_cm = jmx_yaml
...@@ -219,7 +221,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc ...@@ -219,7 +221,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
app_container['resources']['limits']['cpu'] = cpu_limit app_container['resources']['limits']['cpu'] = cpu_limit
try: try:
app_deploy = appsApi.create_namespaced_deployment( app_deploy = appsApi.create_namespaced_deployment(
namespace="default", namespace=namespace,
body=deploy_yaml body=deploy_yaml
) )
print("Deployment '%s' created." % app_deploy.metadata.name) print("Deployment '%s' created." % app_deploy.metadata.name)
...@@ -272,12 +274,12 @@ def delete_resource(obj, del_func): ...@@ -272,12 +274,12 @@ def delete_resource(obj, del_func):
:param del_func: The function that need to be executed for deletion :param del_func: The function that need to be executed for deletion
""" """
try: try:
del_func(obj.metadata.name, 'default') del_func(obj.metadata.name, namespace)
except Exception as e: except Exception as e:
logging.debug( logging.debug(
'Error deleting resource with api object, try with dict.') 'Error deleting resource with api object, try with dict.')
try: try:
del_func(obj['metadata']['name'], 'default') del_func(obj['metadata']['name'], namespace)
except Exception as e: except Exception as e:
logging.error("Error deleting resource") logging.error("Error deleting resource")
logging.error(e) logging.error(e)
...@@ -306,7 +308,7 @@ def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy): ...@@ -306,7 +308,7 @@ def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy):
customApi.delete_namespaced_custom_object( customApi.delete_namespaced_custom_object(
group="monitoring.coreos.com", group="monitoring.coreos.com",
version="v1", version="v1",
namespace="default", namespace=namespace,
plural="servicemonitors", plural="servicemonitors",
name=app_svc_monitor['metadata']['name']) name=app_svc_monitor['metadata']['name'])
print('Resource deleted') print('Resource deleted')
...@@ -349,7 +351,7 @@ def delete_topics(topics): ...@@ -349,7 +351,7 @@ def delete_topics(topics):
# topic deletion, sometimes a second deletion seems to be required # topic deletion, sometimes a second deletion seems to be required
resp = stream(coreApi.connect_get_namespaced_pod_exec, resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client", "kafka-client",
'default', namespace,
command=topics_deletion_command, command=topics_deletion_command,
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False) stdout=True, tty=False)
...@@ -359,7 +361,7 @@ def delete_topics(topics): ...@@ -359,7 +361,7 @@ def delete_topics(topics):
time.sleep(2) time.sleep(2)
resp = stream(coreApi.connect_get_namespaced_pod_exec, resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client", "kafka-client",
'default', namespace,
command=num_topics_command, command=num_topics_command,
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False) stdout=True, tty=False)
...@@ -393,7 +395,7 @@ def reset_zookeeper(): ...@@ -393,7 +395,7 @@ def reset_zookeeper():
# Delete Zookeeper configuration data # Delete Zookeeper configuration data
resp = stream(coreApi.connect_get_namespaced_pod_exec, resp = stream(coreApi.connect_get_namespaced_pod_exec,
"zookeeper-client", "zookeeper-client",
'default', namespace,
command=delete_zoo_data_command, command=delete_zoo_data_command,
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False) stdout=True, tty=False)
...@@ -402,7 +404,7 @@ def reset_zookeeper(): ...@@ -402,7 +404,7 @@ def reset_zookeeper():
# Check data is deleted # Check data is deleted
client = stream(coreApi.connect_get_namespaced_pod_exec, client = stream(coreApi.connect_get_namespaced_pod_exec,
"zookeeper-client", "zookeeper-client",
'default', namespace,
command=check_zoo_data_command, command=check_zoo_data_command,
stderr=True, stdin=False, stderr=True, stdin=False,
stdout=True, tty=False, stdout=True, tty=False,
...@@ -427,11 +429,11 @@ def stop_lag_exporter(): ...@@ -427,11 +429,11 @@ def stop_lag_exporter():
try: try:
# Get lag exporter # Get lag exporter
pod_list = coreApi.list_namespaced_pod(namespace='default', label_selector='app.kubernetes.io/name=kafka-lag-exporter') pod_list = coreApi.list_namespaced_pod(namespace=namespace, label_selector='app.kubernetes.io/name=kafka-lag-exporter')
lag_exporter_pod = pod_list.items[0].metadata.name lag_exporter_pod = pod_list.items[0].metadata.name
# Delete lag exporter pod # Delete lag exporter pod
res = coreApi.delete_namespaced_pod(name=lag_exporter_pod, namespace='default') res = coreApi.delete_namespaced_pod(name=lag_exporter_pod, namespace=namespace)
except ApiException as e: except ApiException as e:
logging.error('Exception while stopping lag exporter') logging.error('Exception while stopping lag exporter')
logging.error(e) logging.error(e)
...@@ -454,7 +456,7 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics): ...@@ -454,7 +456,7 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics):
stop_lag_exporter() stop_lag_exporter()
def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limit, commit_interval_ms, execution_minutes, prometheus_base_url=None, reset=False, reset_only=False): def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limit, commit_interval_ms, execution_minutes, prometheus_base_url=None, reset=False, reset_only=False, ns=namespace):
""" """
Main method to execute one time the benchmark for a given use case. Main method to execute one time the benchmark for a given use case.
Start workload generator/application -> execute -> analyse -> stop all Start workload generator/application -> execute -> analyse -> stop all
...@@ -470,6 +472,8 @@ def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limi ...@@ -470,6 +472,8 @@ def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limi
:param boolean reset: Flag for reset of cluster before execution. :param boolean reset: Flag for reset of cluster before execution.
:param boolean reset_only: Flag to only reset the application. :param boolean reset_only: Flag to only reset the application.
""" """
global namespace
namespace = ns
wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files() wg, app_svc, app_svc_monitor, app_jmx, app_deploy = load_yaml_files()
print('---------------------') print('---------------------')
...@@ -534,4 +538,4 @@ if __name__ == '__main__': ...@@ -534,4 +538,4 @@ if __name__ == '__main__':
main(args.exp_id, args.uc, args.load, args.instances, main(args.exp_id, args.uc, args.load, args.instances,
args.partitions, args.cpu_limit, args.memory_limit, args.partitions, args.cpu_limit, args.memory_limit,
args.commit_ms, args.duration, args.prometheus, args.reset, args.commit_ms, args.duration, args.prometheus, args.reset,
args.reset_only) args.reset_only, args.namespace)
...@@ -29,7 +29,7 @@ def load_variables(): ...@@ -29,7 +29,7 @@ def load_variables():
return args return args
def main(uc, loads, instances_list, partitions, cpu_limit, memory_limit, commit_ms, duration, domain_restriction, search_strategy, reset, reset_only): def main(uc, loads, instances_list, partitions, cpu_limit, memory_limit, commit_ms, duration, domain_restriction, search_strategy, reset, reset_only, namespace):
print(f"Domain restriction of search space activated: {domain_restriction}") print(f"Domain restriction of search space activated: {domain_restriction}")
print(f"Chosen search strategy: {search_strategy}") print(f"Chosen search strategy: {search_strategy}")
...@@ -175,4 +175,4 @@ if __name__ == '__main__': ...@@ -175,4 +175,4 @@ if __name__ == '__main__':
main(args.uc, args.loads, args.instances_list, args.partitions, args.cpu_limit, main(args.uc, args.loads, args.instances_list, args.partitions, args.cpu_limit,
args.memory_limit, args.commit_ms, args.duration, args.memory_limit, args.commit_ms, args.duration,
args.domain_restriction, args.search_strategy, args.reset, args.domain_restriction, args.search_strategy, args.reset,
args.reset_only) args.reset_only, args.namespace)
...@@ -30,6 +30,8 @@ spec: ...@@ -30,6 +30,8 @@ spec:
# value: "" # value: ""
- name: PROMETHEUS_BASE_URL - name: PROMETHEUS_BASE_URL
value: "http://prometheus-operated:9090" value: "http://prometheus-operated:9090"
# - name: NAMESPACE
# value: "default"
- name: PYTHONUNBUFFERED - name: PYTHONUNBUFFERED
value: "1" value: "1"
restartPolicy: Never restartPolicy: Never
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment