From f5c64100878d4cc88fd345a8bcfdb99a054f1b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gull=C3=B3n?= Date: Tue, 1 Mar 2022 10:09:42 +0100 Subject: [PATCH] Adding support to run commands on more pod containers --- kraken/kubernetes/client.py | 4 ++-- kraken/pvc/pvc_scenario.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kraken/kubernetes/client.py b/kraken/kubernetes/client.py index eb0024d9..5c713c2f 100644 --- a/kraken/kubernetes/client.py +++ b/kraken/kubernetes/client.py @@ -135,9 +135,9 @@ def get_all_pods(label_selector=None): # Execute command in pod -def exec_cmd_in_pod(command, pod_name, namespace, container=None): +def exec_cmd_in_pod(command, pod_name, namespace, container=None, base_command="bash"): - exec_command = ["bash", "-c", command] + exec_command = [base_command, "-c", command] try: if container: ret = stream( diff --git a/kraken/pvc/pvc_scenario.py b/kraken/pvc/pvc_scenario.py index 7fbddee5..27d216a9 100644 --- a/kraken/pvc/pvc_scenario.py +++ b/kraken/pvc/pvc_scenario.py @@ -104,7 +104,7 @@ pvc_name: '%s'\npod_name: '%s'\nnamespace: '%s'\ntarget_fill_percentage: '%s%%'\ # Get used bytes in PVC command = "du -sk %s | grep -Eo '^[0-9]*'" % (str(mount_path)) logging.debug("Get used bytes in PVC command:\n %s" % command) - pvc_used = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name) + pvc_used = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name, "sh") logging.info("PVC used: %s KB" % pvc_used) # Check valid fill percentage @@ -134,7 +134,7 @@ pvc_name: '%s'\npod_name: '%s'\nnamespace: '%s'\ntarget_fill_percentage: '%s%%'\ full_path = "%s/%s" % (str(mount_path), str(file_name)) command = "dd bs=1024 count=%s %s" % (str(file_size), str(full_path)) logging.debug("Create temp file in the PVC command:\n %s" % command) - response = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name) + response = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name, "sh") logging.info("\n" + str(response)) if "copied" in str(response).lower(): logging.info("%s file successfully created" % (str(full_path))) @@ -150,10 +150,10 @@ pvc_name: '%s'\npod_name: '%s'\nnamespace: '%s'\ntarget_fill_percentage: '%s%%'\ # Remove the temp file from the PVC command = "rm %s" % (str(full_path)) logging.debug("Remove temp file from the PVC command:\n %s" % command) - kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name) + kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name, "sh") command = "ls %s" % (str(mount_path)) logging.debug("Check temp file is removed command:\n %s" % command) - response = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name) + response = kubecli.exec_cmd_in_pod(command, pod_name, namespace, container_name, "sh") logging.info("\n" + str(response)) if not (file_name in str(response).lower()): logging.info("Temp file successfully removed")