Skip to content
Snippets Groups Projects
Commit 4bc16f37 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 760d39c6 0f36678a
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,10 @@ def default_parser(description):
default=os.environ.get('DURATION', 5),
help='Duration in minutes subexperiments should be \
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',
action="store_true",
help='Resets the environment before execution')
......
......
......@@ -15,6 +15,8 @@ coreApi = None # acces kubernetes core api
appsApi = None # acces kubernetes apps api
customApi = None # acces kubernetes custom object api
namespace = None
def load_variables():
"""Load the CLI variables given at the command line"""
......@@ -67,7 +69,7 @@ def create_topics(topics):
]
resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client",
'default',
namespace,
command=exec_command,
stderr=True, stdin=False,
stdout=True, tty=False)
......@@ -144,7 +146,7 @@ def start_workload_generator(wg_yaml, dim_value, uc_id):
try:
wg_ss = appsApi.create_namespaced_deployment(
namespace="default",
namespace=namespace,
body=wg_yaml
)
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
# Create Service
try:
svc = coreApi.create_namespaced_service(
namespace="default", body=svc_yaml)
namespace=namespace, body=svc_yaml)
print("Service '%s' created." % svc.metadata.name)
except client.rest.ApiException as e:
svc = svc_yaml
......@@ -189,7 +191,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
svc_monitor = customApi.create_namespaced_custom_object(
group="monitoring.coreos.com",
version="v1",
namespace="default",
namespace=namespace,
plural="servicemonitors", # CustomResourceDef of ServiceMonitor
body=svc_monitor_yaml,
)
......@@ -201,7 +203,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
# Apply jmx config map for aggregation service
try:
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)
except client.rest.ApiException as e:
jmx_cm = jmx_yaml
......@@ -219,7 +221,7 @@ def start_application(svc_yaml, svc_monitor_yaml, jmx_yaml, deploy_yaml, instanc
app_container['resources']['limits']['cpu'] = cpu_limit
try:
app_deploy = appsApi.create_namespaced_deployment(
namespace="default",
namespace=namespace,
body=deploy_yaml
)
print("Deployment '%s' created." % app_deploy.metadata.name)
......@@ -272,12 +274,12 @@ def delete_resource(obj, del_func):
:param del_func: The function that need to be executed for deletion
"""
try:
del_func(obj.metadata.name, 'default')
del_func(obj.metadata.name, namespace)
except Exception as e:
logging.debug(
'Error deleting resource with api object, try with dict.')
try:
del_func(obj['metadata']['name'], 'default')
del_func(obj['metadata']['name'], namespace)
except Exception as e:
logging.error("Error deleting resource")
logging.error(e)
......@@ -306,7 +308,7 @@ def stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy):
customApi.delete_namespaced_custom_object(
group="monitoring.coreos.com",
version="v1",
namespace="default",
namespace=namespace,
plural="servicemonitors",
name=app_svc_monitor['metadata']['name'])
print('Resource deleted')
......@@ -349,7 +351,7 @@ def delete_topics(topics):
# topic deletion, sometimes a second deletion seems to be required
resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client",
'default',
namespace,
command=topics_deletion_command,
stderr=True, stdin=False,
stdout=True, tty=False)
......@@ -359,7 +361,7 @@ def delete_topics(topics):
time.sleep(2)
resp = stream(coreApi.connect_get_namespaced_pod_exec,
"kafka-client",
'default',
namespace,
command=num_topics_command,
stderr=True, stdin=False,
stdout=True, tty=False)
......@@ -393,7 +395,7 @@ def reset_zookeeper():
# Delete Zookeeper configuration data
resp = stream(coreApi.connect_get_namespaced_pod_exec,
"zookeeper-client",
'default',
namespace,
command=delete_zoo_data_command,
stderr=True, stdin=False,
stdout=True, tty=False)
......@@ -402,7 +404,7 @@ def reset_zookeeper():
# Check data is deleted
client = stream(coreApi.connect_get_namespaced_pod_exec,
"zookeeper-client",
'default',
namespace,
command=check_zoo_data_command,
stderr=True, stdin=False,
stdout=True, tty=False,
......@@ -427,11 +429,11 @@ def stop_lag_exporter():
try:
# 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
# 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:
logging.error('Exception while stopping lag exporter')
logging.error(e)
......@@ -454,7 +456,7 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics):
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.
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
:param boolean reset: Flag for reset of cluster before execution.
: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()
print('---------------------')
......@@ -534,4 +538,4 @@ if __name__ == '__main__':
main(args.exp_id, args.uc, args.load, args.instances,
args.partitions, args.cpu_limit, args.memory_limit,
args.commit_ms, args.duration, args.prometheus, args.reset,
args.reset_only)
args.reset_only, args.namespace)
......@@ -29,7 +29,7 @@ def load_variables():
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"Chosen search strategy: {search_strategy}")
......@@ -175,4 +175,4 @@ if __name__ == '__main__':
main(args.uc, args.loads, args.instances_list, args.partitions, args.cpu_limit,
args.memory_limit, args.commit_ms, args.duration,
args.domain_restriction, args.search_strategy, args.reset,
args.reset_only)
args.reset_only, args.namespace)
......@@ -30,6 +30,8 @@ spec:
# value: ""
- name: PROMETHEUS_BASE_URL
value: "http://prometheus-operated:9090"
# - name: NAMESPACE
# value: "default"
- name: PYTHONUNBUFFERED
value: "1"
restartPolicy: Never
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment