mirror of
https://github.com/krkn-chaos/krkn.git
synced 2026-02-14 18:10:00 +00:00
Adding namespace or label selector error; delete_count option
This commit is contained in:
committed by
Naga Ravi Chaitanya Elluri
parent
67b0f2de8c
commit
01f1075eb3
@@ -6,11 +6,15 @@ Configuration Options:
|
||||
|
||||
**action:** default is `delete`
|
||||
|
||||
**namespace:** specific namespace or regex style namespace of what you want to delete, gets all namespaces if not specified
|
||||
**namespace:** specific namespace or regex style namespace of what you want to delete, gets all namespaces if not specified; set to "" if you want to use the label_selector field
|
||||
|
||||
**label_selector:** label on the namespace you want to delete
|
||||
Set to '^.*$' and label_selector to "" to randomly select any namespace in your cluster
|
||||
|
||||
**runs:** number of runs to kill namespaces, based on matching namespace and label specified, default is 1
|
||||
**label_selector:** label on the namespace you want to delete, set to "" if you are using the namespace variable
|
||||
|
||||
**delete_count:** number of namespaces to kill in each run, based on matching namespace and label specified, default is 1
|
||||
|
||||
**runs:** number of runs/iterations to kill namespaces, default is 1
|
||||
|
||||
**sleep:** number of seconds to wait between each iteration/count of killing namespaces. Defaults to 10 seconds if not set
|
||||
|
||||
|
||||
@@ -18,49 +18,64 @@ def run(scenarios_list, config, wait_duration, failed_post_scenarios, kubeconfig
|
||||
with open(scenario_config[0], "r") as f:
|
||||
scenario_config_yaml = yaml.full_load(f)
|
||||
for scenario in scenario_config_yaml["scenarios"]:
|
||||
scenario_namespace = scenario.get("namespace", "^.*$")
|
||||
scenario_label = scenario.get("label_selector", None)
|
||||
scenario_namespace = scenario.get("namespace", "")
|
||||
scenario_label = scenario.get("label_selector", "")
|
||||
if scenario_namespace.strip() != "":
|
||||
if scenario_label.strip() != "":
|
||||
logging.error("You can only have namespace or label set in your namespace scenario")
|
||||
logging.error(
|
||||
"Current scenario config has namespace '%s' and label selector '%s'"
|
||||
% (scenario_namespace, scenario_label)
|
||||
)
|
||||
logging.error(
|
||||
"Please set either namespace to blank ('') or label_selector to blank ('') to continue"
|
||||
)
|
||||
sys.exit(1)
|
||||
delete_count = scenario.get("delete_count", 1)
|
||||
run_count = scenario.get("runs", 1)
|
||||
namespace_action = scenario.get("action", "delete")
|
||||
run_sleep = scenario.get("sleep", 10)
|
||||
wait_time = scenario.get("wait_time", 30)
|
||||
killed_namespaces = []
|
||||
namespaces = kubecli.check_namespaces([scenario_namespace], scenario_label)
|
||||
start_time = int(time.time())
|
||||
for i in range(run_count):
|
||||
if len(namespaces) == 0:
|
||||
logging.error(
|
||||
"Couldn't %s %s namespaces, not enough namespaces matching %s with label %s"
|
||||
% (namespace_action, str(run_count), scenario_namespace, str(scenario_label))
|
||||
)
|
||||
sys.exit(1)
|
||||
selected_namespace = namespaces[random.randint(0, len(namespaces) - 1)]
|
||||
killed_namespaces.append(selected_namespace)
|
||||
try:
|
||||
runcommand.invoke("oc %s project %s" % (namespace_action, selected_namespace))
|
||||
logging.info(namespace_action + " on namespace " + str(selected_namespace) + " was successful")
|
||||
except Exception as e:
|
||||
logging.info(
|
||||
namespace_action + " on namespace " + str(selected_namespace) + " was unsuccessful"
|
||||
)
|
||||
logging.info("Namespace action error: " + str(e))
|
||||
sys.exit(1)
|
||||
namespaces.remove(selected_namespace)
|
||||
logging.info("Waiting %s seconds between namespace deletions" % str(run_sleep))
|
||||
time.sleep(run_sleep)
|
||||
namespaces = kubecli.check_namespaces([scenario_namespace], scenario_label)
|
||||
for j in range(delete_count):
|
||||
if len(namespaces) == 0:
|
||||
logging.error(
|
||||
"Couldn't %s %s namespaces, not enough namespaces matching %s with label %s"
|
||||
% (namespace_action, str(run_count), scenario_namespace, str(scenario_label))
|
||||
)
|
||||
sys.exit(1)
|
||||
selected_namespace = namespaces[random.randint(0, len(namespaces) - 1)]
|
||||
killed_namespaces.append(selected_namespace)
|
||||
try:
|
||||
runcommand.invoke("oc %s project %s" % (namespace_action, selected_namespace))
|
||||
logging.info(
|
||||
namespace_action + " on namespace " + str(selected_namespace) + " was successful"
|
||||
)
|
||||
except Exception as e:
|
||||
logging.info(
|
||||
namespace_action + " on namespace " + str(selected_namespace) + " was unsuccessful"
|
||||
)
|
||||
logging.info("Namespace action error: " + str(e))
|
||||
sys.exit(1)
|
||||
namespaces.remove(selected_namespace)
|
||||
logging.info("Waiting %s seconds between namespace deletions" % str(run_sleep))
|
||||
time.sleep(run_sleep)
|
||||
|
||||
logging.info("Waiting for the specified duration: %s" % wait_duration)
|
||||
time.sleep(wait_duration)
|
||||
if len(scenario_config) > 1:
|
||||
try:
|
||||
failed_post_scenarios = post_actions.check_recovery(
|
||||
kubeconfig_path, scenario_config, failed_post_scenarios, pre_action_output
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error("Failed to run post action checks: %s" % e)
|
||||
sys.exit(1)
|
||||
else:
|
||||
failed_post_scenarios = check_active_namespace(killed_namespaces, wait_time)
|
||||
logging.info("Waiting for the specified duration: %s" % wait_duration)
|
||||
time.sleep(wait_duration)
|
||||
if len(scenario_config) > 1:
|
||||
try:
|
||||
failed_post_scenarios = post_actions.check_recovery(
|
||||
kubeconfig_path, scenario_config, failed_post_scenarios, pre_action_output
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error("Failed to run post action checks: %s" % e)
|
||||
sys.exit(1)
|
||||
else:
|
||||
failed_post_scenarios = check_active_namespace(killed_namespaces, wait_time)
|
||||
end_time = int(time.time())
|
||||
cerberus.publish_kraken_status(config, failed_post_scenarios, start_time, end_time)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
scenarios:
|
||||
- action: delete
|
||||
namespace: "^.*$"
|
||||
delete_count: 1
|
||||
runs: 2
|
||||
sleep: 15
|
||||
wait_time: 300
|
||||
|
||||
Reference in New Issue
Block a user