From f868000ebda787038605b1159620c39cb4520c58 Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Tue, 22 Aug 2023 18:41:40 +0200 Subject: [PATCH] Switched from krkn_lib_kubernetes to krkn_lib v1.0.0 (#469) * changed all the references to krkn_lib_kubernetes to the new krkn_lib changed all the references * added krkn-lib pointer in documentation --- docs/installation.md | 5 +++ kraken/application_outage/actions.py | 3 +- kraken/arcaflow_plugin/arcaflow_plugin.py | 5 +-- kraken/litmus/common_litmus.py | 31 +++++++------- .../common_managedcluster_functions.py | 14 +++---- .../managedcluster_scenarios.py | 10 ++--- kraken/managedcluster_scenarios/run.py | 15 ++++--- .../common_namespace_functions.py | 15 +++---- kraken/network_chaos/actions.py | 29 ++++++------- .../node_actions/abstract_node_scenarios.py | 8 ++-- kraken/node_actions/alibaba_node_scenarios.py | 14 +++---- kraken/node_actions/aws_node_scenarios.py | 7 ++-- kraken/node_actions/az_node_scenarios.py | 17 ++++---- kraken/node_actions/bm_node_scenarios.py | 7 ++-- kraken/node_actions/common_node_functions.py | 17 ++++---- kraken/node_actions/docker_node_scenarios.py | 5 +-- kraken/node_actions/gcp_node_scenarios.py | 7 ++-- .../general_cloud_node_scenarios.py | 7 ++-- .../node_actions/openstack_node_scenarios.py | 7 ++-- kraken/node_actions/run.py | 14 +++---- kraken/plugins/__init__.py | 4 +- .../pod_network_outage_plugin.py | 42 +++++++++---------- kraken/pod_scenarios/setup.py | 25 ++++++----- kraken/pvc/pvc_scenario.py | 16 +++---- kraken/shut_down/common_shut_down_func.py | 16 ++++--- kraken/time_actions/common_time_functions.py | 26 ++++++------ kraken/zone_outage/actions.py | 4 +- requirements.txt | 2 +- run_kraken.py | 24 ++++++----- 29 files changed, 199 insertions(+), 197 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index eaa9c017..e182d778 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -11,6 +11,11 @@ The following ways are supported to run Kraken: **NOTE**: To run Kraken on Power (ppc64le) architecture, build and run a containerized version by following the instructions given [here](https://github.com/redhat-chaos/krkn/blob/main/containers/build_own_image-README.md). +**NOTE**: Helper functions for interactions in Krkn are part of [krkn-lib](https://github.com/redhat-chaos/krkn-lib). +Please feel free to reuse and expand them as you see fit when adding a new scenario or expanding +the capabilities of the current supported scenarios. + + ### Git #### Clone the repository diff --git a/kraken/application_outage/actions.py b/kraken/application_outage/actions.py index 4d2ae0c6..71844e8a 100644 --- a/kraken/application_outage/actions.py +++ b/kraken/application_outage/actions.py @@ -4,7 +4,8 @@ import kraken.cerberus.setup as cerberus from jinja2 import Template import kraken.invoke.command as runcommand -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry # Reads the scenario config, applies and deletes a network policy to # block the traffic for the specified duration diff --git a/kraken/arcaflow_plugin/arcaflow_plugin.py b/kraken/arcaflow_plugin/arcaflow_plugin.py index 52c33baf..18799613 100644 --- a/kraken/arcaflow_plugin/arcaflow_plugin.py +++ b/kraken/arcaflow_plugin/arcaflow_plugin.py @@ -1,14 +1,13 @@ import time - import arcaflow import os import yaml import logging -import sys from pathlib import Path from typing import List from .context_auth import ContextAuth -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry def run(scenarios_list: List[str], kubeconfig_path: str, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): diff --git a/kraken/litmus/common_litmus.py b/kraken/litmus/common_litmus.py index 25d23b97..5b26909d 100644 --- a/kraken/litmus/common_litmus.py +++ b/kraken/litmus/common_litmus.py @@ -1,14 +1,13 @@ import kraken.invoke.command as runcommand -import krkn_lib_kubernetes import logging import time import sys import requests import yaml import kraken.cerberus.setup as cerberus +from krkn_lib.k8s import KrknKubernetes - -# krkn_lib_kubernetes +# krkn_lib # Inject litmus scenarios defined in the config def run( scenarios_list, @@ -16,7 +15,7 @@ def run( litmus_uninstall, wait_duration, litmus_namespace, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes + kubecli: KrknKubernetes ): # Loop to run the scenarios starts here for l_scenario in scenarios_list: @@ -94,8 +93,8 @@ def deploy_all_experiments(version_string, namespace): ) -# krkn_lib_kubernetes -def wait_for_initialized(engine_name, experiment_name, namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def wait_for_initialized(engine_name, experiment_name, namespace, kubecli: KrknKubernetes): chaos_engine = kubecli.get_litmus_chaos_object(kind='chaosengine', name=engine_name, namespace=namespace).engineStatus @@ -119,13 +118,13 @@ def wait_for_initialized(engine_name, experiment_name, namespace, kubecli: krkn_ return True -# krkn_lib_kubernetes +# krkn_lib def wait_for_status( engine_name, expected_status, experiment_name, namespace, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes + kubecli: KrknKubernetes ): if expected_status == "running": @@ -156,8 +155,8 @@ def wait_for_status( # Check status of experiment -# krkn_lib_kubernetes -def check_experiment(engine_name, experiment_name, namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def check_experiment(engine_name, experiment_name, namespace, kubecli: KrknKubernetes): wait_response = wait_for_status(engine_name, "running", experiment_name, namespace, kubecli) @@ -183,8 +182,8 @@ def check_experiment(engine_name, experiment_name, namespace, kubecli: krkn_lib_ # Delete all chaos engines in a given namespace -# krkn_lib_kubernetes -def delete_chaos_experiments(namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def delete_chaos_experiments(namespace, kubecli: KrknKubernetes): if kubecli.check_if_namespace_exists(namespace): chaos_exp_exists = runcommand.invoke_no_exit("kubectl get chaosexperiment") @@ -194,8 +193,8 @@ def delete_chaos_experiments(namespace, kubecli: krkn_lib_kubernetes.KrknLibKube # Delete all chaos engines in a given namespace -# krkn_lib_kubernetes -def delete_chaos(namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def delete_chaos(namespace, kubecli:KrknKubernetes): if kubecli.check_if_namespace_exists(namespace): logging.info("Deleting all litmus run objects") @@ -209,8 +208,8 @@ def delete_chaos(namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): logging.info(namespace + " namespace doesn't exist") -# krkn_lib_kubernetes -def uninstall_litmus(version, litmus_namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def uninstall_litmus(version, litmus_namespace, kubecli: KrknKubernetes): if kubecli.check_if_namespace_exists(litmus_namespace): logging.info("Uninstalling Litmus operator") diff --git a/kraken/managedcluster_scenarios/common_managedcluster_functions.py b/kraken/managedcluster_scenarios/common_managedcluster_functions.py index 88e00598..b4a17c4c 100644 --- a/kraken/managedcluster_scenarios/common_managedcluster_functions.py +++ b/kraken/managedcluster_scenarios/common_managedcluster_functions.py @@ -1,14 +1,14 @@ import random import logging -import krkn_lib_kubernetes +from krkn_lib.k8s import KrknKubernetes -# krkn_lib_kubernetes +# krkn_lib # Pick a random managedcluster with specified label selector def get_managedcluster( managedcluster_name, label_selector, instance_kill_count, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + kubecli: KrknKubernetes): if managedcluster_name in kubecli.list_killable_managedclusters(): return [managedcluster_name] @@ -30,12 +30,12 @@ def get_managedcluster( # Wait until the managedcluster status becomes Available -# krkn_lib_kubernetes -def wait_for_available_status(managedcluster, timeout, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def wait_for_available_status(managedcluster, timeout, kubecli: KrknKubernetes): kubecli.watch_managedcluster_status(managedcluster, "True", timeout) # Wait until the managedcluster status becomes Not Available -# krkn_lib_kubernetes -def wait_for_unavailable_status(managedcluster, timeout, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def wait_for_unavailable_status(managedcluster, timeout, kubecli: KrknKubernetes): kubecli.watch_managedcluster_status(managedcluster, "Unknown", timeout) diff --git a/kraken/managedcluster_scenarios/managedcluster_scenarios.py b/kraken/managedcluster_scenarios/managedcluster_scenarios.py index 59a79c44..b2478067 100644 --- a/kraken/managedcluster_scenarios/managedcluster_scenarios.py +++ b/kraken/managedcluster_scenarios/managedcluster_scenarios.py @@ -4,19 +4,17 @@ import logging import sys import yaml -import html -import krkn_lib_kubernetes import kraken.managedcluster_scenarios.common_managedcluster_functions as common_managedcluster_functions - +from krkn_lib.k8s import KrknKubernetes class GENERAL: def __init__(self): pass -# krkn_lib_kubernetes +# krkn_lib class managedcluster_scenarios(): - kubecli: krkn_lib_kubernetes.KrknLibKubernetes - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + kubecli: KrknKubernetes + def __init__(self, kubecli: KrknKubernetes): self.kubecli = kubecli self.general = GENERAL() diff --git a/kraken/managedcluster_scenarios/run.py b/kraken/managedcluster_scenarios/run.py index 03d2dc72..17d0de9b 100644 --- a/kraken/managedcluster_scenarios/run.py +++ b/kraken/managedcluster_scenarios/run.py @@ -1,20 +1,19 @@ import yaml import logging import time -import krkn_lib_kubernetes from kraken.managedcluster_scenarios.managedcluster_scenarios import managedcluster_scenarios import kraken.managedcluster_scenarios.common_managedcluster_functions as common_managedcluster_functions import kraken.cerberus.setup as cerberus - +from krkn_lib.k8s import KrknKubernetes # Get the managedcluster scenarios object of specfied cloud type -# krkn_lib_kubernetes -def get_managedcluster_scenario_object(managedcluster_scenario, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def get_managedcluster_scenario_object(managedcluster_scenario, kubecli: KrknKubernetes): return managedcluster_scenarios(kubecli) # Run defined scenarios -# krkn_lib_kubernetes -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def run(scenarios_list, config, wait_duration, kubecli: KrknKubernetes): for managedcluster_scenario_config in scenarios_list: with open(managedcluster_scenario_config, "r") as f: managedcluster_scenario_config = yaml.full_load(f) @@ -32,8 +31,8 @@ def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.Krkn # Inject the specified managedcluster scenario -# krkn_lib_kubernetes -def inject_managedcluster_scenario(action, managedcluster_scenario, managedcluster_scenario_object, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def inject_managedcluster_scenario(action, managedcluster_scenario, managedcluster_scenario_object, kubecli: KrknKubernetes): # Get the managedcluster scenario configurations run_kill_count = managedcluster_scenario.get("runs", 1) instance_kill_count = managedcluster_scenario.get("instance_count", 1) diff --git a/kraken/namespace_actions/common_namespace_functions.py b/kraken/namespace_actions/common_namespace_functions.py index 7d7212d6..4981efa7 100644 --- a/kraken/namespace_actions/common_namespace_functions.py +++ b/kraken/namespace_actions/common_namespace_functions.py @@ -1,21 +1,22 @@ import time import random import logging -import krkn_lib_kubernetes import kraken.cerberus.setup as cerberus import kraken.post_actions.actions as post_actions import yaml -import sys -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry -# krkn_lib_kubernetes + +# krkn_lib def run( scenarios_list, config, wait_duration, failed_post_scenarios, kubeconfig_path, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes, + kubecli: KrknKubernetes, telemetry: KrknTelemetry ) -> (list[str], list[ScenarioTelemetry]): scenario_telemetries: list[ScenarioTelemetry] = [] @@ -106,8 +107,8 @@ def run( scenario_telemetries.append(scenario_telemetry) return failed_scenarios, scenario_telemetries -# krkn_lib_kubernetes -def check_active_namespace(killed_namespaces, wait_time, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def check_active_namespace(killed_namespaces, wait_time, kubecli: KrknKubernetes): active_namespace = [] timer = 0 while timer < wait_time and killed_namespaces: diff --git a/kraken/network_chaos/actions.py b/kraken/network_chaos/actions.py index 0b209c72..e2921b97 100644 --- a/kraken/network_chaos/actions.py +++ b/kraken/network_chaos/actions.py @@ -1,18 +1,19 @@ import yaml import logging import time -import sys import os import random -import krkn_lib_kubernetes -from jinja2 import Environment, FileSystemLoader import kraken.cerberus.setup as cerberus import kraken.node_actions.common_node_functions as common_node_functions -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from jinja2 import Environment, FileSystemLoader +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry + -# krkn_lib_kubernetes +# krkn_lib # Reads the scenario config and introduces traffic variations in Node's host network interface. -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): +def run(scenarios_list, config, wait_duration, kubecli: KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): failed_post_scenarios = "" logging.info("Runing the Network Chaos tests") failed_post_scenarios = "" @@ -108,8 +109,8 @@ def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.Krkn return failed_scenarios, scenario_telemetries -# krkn_lib_kubernetes -def verify_interface(test_interface, nodelst, template, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def verify_interface(test_interface, nodelst, template, kubecli: KrknKubernetes): pod_index = random.randint(0, len(nodelst) - 1) pod_body = yaml.safe_load(template.render(nodename=nodelst[pod_index])) logging.info("Creating pod to query interface on node %s" % nodelst[pod_index]) @@ -134,16 +135,16 @@ def verify_interface(test_interface, nodelst, template, kubecli: krkn_lib_kubern kubecli.delete_pod("fedtools", "default") -# krkn_lib_kubernetes -def get_job_pods(api_response, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def get_job_pods(api_response, kubecli: KrknKubernetes): controllerUid = api_response.metadata.labels["controller-uid"] pod_label_selector = "controller-uid=" + controllerUid pods_list = kubecli.list_pods(label_selector=pod_label_selector, namespace="default") return pods_list[0] -# krkn_lib_kubernetes -def wait_for_job(joblst, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, timeout=300): +# krkn_lib +def wait_for_job(joblst, kubecli: KrknKubernetes, timeout=300): waittime = time.time() + timeout count = 0 joblen = len(joblst) @@ -161,8 +162,8 @@ def wait_for_job(joblst, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, timeout time.sleep(5) -# krkn_lib_kubernetes -def delete_job(joblst, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def delete_job(joblst, kubecli: KrknKubernetes): for jobname in joblst: try: api_response = kubecli.get_job_status(jobname, namespace="default") diff --git a/kraken/node_actions/abstract_node_scenarios.py b/kraken/node_actions/abstract_node_scenarios.py index 2cc1c200..19d15c14 100644 --- a/kraken/node_actions/abstract_node_scenarios.py +++ b/kraken/node_actions/abstract_node_scenarios.py @@ -2,12 +2,12 @@ import logging import kraken.invoke.command as runcommand import kraken.node_actions.common_node_functions as nodeaction -import krkn_lib_kubernetes +from krkn_lib.k8s import KrknKubernetes -# krkn_lib_kubernetes +# krkn_lib class abstract_node_scenarios: - kubecli: krkn_lib_kubernetes.KrknLibKubernetes - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + kubecli: KrknKubernetes + def __init__(self, kubecli: KrknKubernetes): self.kubecli = kubecli # Node scenario to start the node def node_start_scenario(self, instance_kill_count, node, timeout): diff --git a/kraken/node_actions/alibaba_node_scenarios.py b/kraken/node_actions/alibaba_node_scenarios.py index 0785a058..47c2f226 100644 --- a/kraken/node_actions/alibaba_node_scenarios.py +++ b/kraken/node_actions/alibaba_node_scenarios.py @@ -1,14 +1,14 @@ import sys import time -import krkn_lib_kubernetes -from aliyunsdkcore.client import AcsClient -from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest, DeleteInstanceRequest -from aliyunsdkecs.request.v20140526 import StopInstanceRequest, StartInstanceRequest, RebootInstanceRequest import logging import kraken.node_actions.common_node_functions as nodeaction -from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios import os import json +from aliyunsdkcore.client import AcsClient +from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest, DeleteInstanceRequest +from aliyunsdkecs.request.v20140526 import StopInstanceRequest, StartInstanceRequest, RebootInstanceRequest +from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios +from krkn_lib.k8s import KrknKubernetes class Alibaba: @@ -180,9 +180,9 @@ def wait_until_released(self, instance_id, timeout): logging.info("ECS %s is released" % instance_id) return True -# krkn_lib_kubernetes +# krkn_lib class alibaba_node_scenarios(abstract_node_scenarios): - def __init__(self,kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self,kubecli: KrknKubernetes): self.alibaba = Alibaba() # Node scenario to start the node diff --git a/kraken/node_actions/aws_node_scenarios.py b/kraken/node_actions/aws_node_scenarios.py index d53ff5a3..0107065b 100644 --- a/kraken/node_actions/aws_node_scenarios.py +++ b/kraken/node_actions/aws_node_scenarios.py @@ -2,10 +2,9 @@ import time import boto3 import logging -import krkn_lib_kubernetes import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios - +from krkn_lib.k8s import KrknKubernetes class AWS: def __init__(self): @@ -166,9 +165,9 @@ def delete_network_acl(self, acl_id): # sys.exit(1) raise RuntimeError() -# krkn_lib_kubernetes +# krkn_lib class aws_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, kubecli: KrknKubernetes): super().__init__(kubecli) self.aws = AWS() diff --git a/kraken/node_actions/az_node_scenarios.py b/kraken/node_actions/az_node_scenarios.py index adffb79d..bcec871a 100644 --- a/kraken/node_actions/az_node_scenarios.py +++ b/kraken/node_actions/az_node_scenarios.py @@ -1,13 +1,14 @@ -import sys + import time -from azure.mgmt.compute import ComputeManagementClient -from azure.identity import DefaultAzureCredential +import yaml +import kraken.invoke.command as runcommand import logging -import krkn_lib_kubernetes import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios -import kraken.invoke.command as runcommand -import yaml +from azure.mgmt.compute import ComputeManagementClient +from azure.identity import DefaultAzureCredential +from krkn_lib.k8s import KrknKubernetes + class Azure: @@ -129,9 +130,9 @@ def wait_until_terminated(self, resource_group, vm_name, timeout): logging.info("Vm %s is terminated" % vm_name) return True -# krkn_lib_kubernetes +# krkn_lib class azure_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, kubecli: KrknKubernetes): super().__init__(kubecli) logging.info("init in azure") self.azure = Azure() diff --git a/kraken/node_actions/bm_node_scenarios.py b/kraken/node_actions/bm_node_scenarios.py index 6f7cbeda..6904c0e6 100644 --- a/kraken/node_actions/bm_node_scenarios.py +++ b/kraken/node_actions/bm_node_scenarios.py @@ -1,6 +1,5 @@ import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios -import krkn_lib_kubernetes import logging import openshift as oc import pyipmi @@ -8,7 +7,7 @@ import sys import time import traceback - +from krkn_lib.k8s import KrknKubernetes class BM: def __init__(self, bm_info, user, passwd): @@ -105,9 +104,9 @@ def wait_until_stopped(self, bmc_addr, node_name): while self.get_ipmi_connection(bmc_addr, node_name).get_chassis_status().power_on: time.sleep(1) -# krkn_lib_kubernetes +# krkn_lib class bm_node_scenarios(abstract_node_scenarios): - def __init__(self, bm_info, user, passwd, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, bm_info, user, passwd, kubecli: KrknKubernetes): super().__init__(kubecli) self.bm = BM(bm_info, user, passwd) diff --git a/kraken/node_actions/common_node_functions.py b/kraken/node_actions/common_node_functions.py index f78d0d9e..39827854 100644 --- a/kraken/node_actions/common_node_functions.py +++ b/kraken/node_actions/common_node_functions.py @@ -2,14 +2,13 @@ import random import logging import paramiko -import krkn_lib_kubernetes import kraken.invoke.command as runcommand - +from krkn_lib.k8s import KrknKubernetes node_general = False # Pick a random node with specified label selector -def get_node(node_name, label_selector, instance_kill_count, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def get_node(node_name, label_selector, instance_kill_count, kubecli: KrknKubernetes): if node_name in kubecli.list_killable_nodes(): return [node_name] elif node_name: @@ -29,21 +28,21 @@ def get_node(node_name, label_selector, instance_kill_count, kubecli: krkn_lib_k return nodes_to_return -# krkn_lib_kubernetes +# krkn_lib # Wait until the node status becomes Ready -def wait_for_ready_status(node, timeout, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def wait_for_ready_status(node, timeout, kubecli: KrknKubernetes): resource_version = kubecli.get_node_resource_version(node) kubecli.watch_node_status(node, "True", timeout, resource_version) -# krkn_lib_kubernetes +# krkn_lib # Wait until the node status becomes Not Ready -def wait_for_not_ready_status(node, timeout, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def wait_for_not_ready_status(node, timeout, kubecli: KrknKubernetes): resource_version = kubecli.get_node_resource_version(node) kubecli.watch_node_status(node, "False", timeout, resource_version) -# krkn_lib_kubernetes +# krkn_lib # Wait until the node status becomes Unknown -def wait_for_unknown_status(node, timeout, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def wait_for_unknown_status(node, timeout, kubecli: KrknKubernetes): resource_version = kubecli.get_node_resource_version(node) kubecli.watch_node_status(node, "Unknown", timeout, resource_version) diff --git a/kraken/node_actions/docker_node_scenarios.py b/kraken/node_actions/docker_node_scenarios.py index 29aa154c..e77cce80 100644 --- a/kraken/node_actions/docker_node_scenarios.py +++ b/kraken/node_actions/docker_node_scenarios.py @@ -1,10 +1,9 @@ import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios -import krkn_lib_kubernetes import logging import sys import docker - +from krkn_lib.k8s import KrknKubernetes class Docker: def __init__(self): @@ -37,7 +36,7 @@ def terminate_instances(self, node_name): class docker_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, kubecli: KrknKubernetes): super().__init__(kubecli) self.docker = Docker() diff --git a/kraken/node_actions/gcp_node_scenarios.py b/kraken/node_actions/gcp_node_scenarios.py index 64711a2a..81d07ae8 100644 --- a/kraken/node_actions/gcp_node_scenarios.py +++ b/kraken/node_actions/gcp_node_scenarios.py @@ -1,13 +1,12 @@ import sys import time import logging -import krkn_lib_kubernetes import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios from googleapiclient import discovery from oauth2client.client import GoogleCredentials import kraken.invoke.command as runcommand - +from krkn_lib.k8s import KrknKubernetes class GCP: def __init__(self): @@ -143,9 +142,9 @@ def wait_until_terminated(self, zone, instance_id, timeout): return True -# krkn_lib_kubernetes +# krkn_lib class gcp_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, kubecli: KrknKubernetes): super().__init__(kubecli) self.gcp = GCP() diff --git a/kraken/node_actions/general_cloud_node_scenarios.py b/kraken/node_actions/general_cloud_node_scenarios.py index 55611589..62419048 100644 --- a/kraken/node_actions/general_cloud_node_scenarios.py +++ b/kraken/node_actions/general_cloud_node_scenarios.py @@ -1,15 +1,14 @@ import logging -import krkn_lib_kubernetes from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios - +from krkn_lib.k8s import KrknKubernetes class GENERAL: def __init__(self): pass -# krkn_lib_kubernetes +# krkn_lib class general_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes ): + def __init__(self, kubecli: KrknKubernetes): super().__init__(kubecli) self.general = GENERAL() diff --git a/kraken/node_actions/openstack_node_scenarios.py b/kraken/node_actions/openstack_node_scenarios.py index bae44e90..b4a33489 100644 --- a/kraken/node_actions/openstack_node_scenarios.py +++ b/kraken/node_actions/openstack_node_scenarios.py @@ -1,11 +1,10 @@ import sys import time import logging -import krkn_lib_kubernetes import kraken.invoke.command as runcommand import kraken.node_actions.common_node_functions as nodeaction from kraken.node_actions.abstract_node_scenarios import abstract_node_scenarios - +from krkn_lib.k8s import KrknKubernetes class OPENSTACKCLOUD: def __init__(self): @@ -93,9 +92,9 @@ def get_openstack_nodename(self, os_node_ip): return node_name counter += 1 -# krkn_lib_kubernetes +# krkn_lib class openstack_node_scenarios(abstract_node_scenarios): - def __init__(self, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): + def __init__(self, kubecli: KrknKubernetes): self.openstackcloud = OPENSTACKCLOUD() # Node scenario to start the node diff --git a/kraken/node_actions/run.py b/kraken/node_actions/run.py index c7e0bf5c..188b29e6 100644 --- a/kraken/node_actions/run.py +++ b/kraken/node_actions/run.py @@ -2,7 +2,6 @@ import logging import sys import time -import krkn_lib_kubernetes from kraken.node_actions.aws_node_scenarios import aws_node_scenarios from kraken.node_actions.general_cloud_node_scenarios import general_node_scenarios from kraken.node_actions.az_node_scenarios import azure_node_scenarios @@ -13,14 +12,15 @@ from kraken.node_actions.docker_node_scenarios import docker_node_scenarios import kraken.node_actions.common_node_functions as common_node_functions import kraken.cerberus.setup as cerberus -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry, ScenarioTelemetry node_general = False # Get the node scenarios object of specfied cloud type -# krkn_lib_kubernetes -def get_node_scenario_object(node_scenario, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def get_node_scenario_object(node_scenario, kubecli: KrknKubernetes): if "cloud_type" not in node_scenario.keys() or node_scenario["cloud_type"] == "generic": global node_general node_general = True @@ -52,8 +52,8 @@ def get_node_scenario_object(node_scenario, kubecli: krkn_lib_kubernetes.KrknLib # Run defined scenarios -# krkn_lib_kubernetes -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): +# krkn_lib +def run(scenarios_list, config, wait_duration, kubecli: KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): scenario_telemetries: list[ScenarioTelemetry] = [] failed_scenarios = [] for node_scenario_config in scenarios_list: @@ -89,7 +89,7 @@ def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.Krkn # Inject the specified node scenario -def inject_node_scenario(action, node_scenario, node_scenario_object, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def inject_node_scenario(action, node_scenario, node_scenario_object, kubecli: KrknKubernetes): generic_cloud_scenarios = ("stop_kubelet_scenario", "node_crash_scenario") # Get the node scenario configurations run_kill_count = node_scenario.get("runs", 1) diff --git a/kraken/plugins/__init__.py b/kraken/plugins/__init__.py index aff7beb0..a6f86001 100644 --- a/kraken/plugins/__init__.py +++ b/kraken/plugins/__init__.py @@ -13,7 +13,9 @@ from kraken.plugins.network.ingress_shaping import network_chaos from kraken.plugins.pod_network_outage.pod_network_outage_plugin import pod_outage from kraken.plugins.pod_network_outage.pod_network_outage_plugin import pod_egress_shaping -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry + @dataclasses.dataclass diff --git a/kraken/plugins/pod_network_outage/pod_network_outage_plugin.py b/kraken/plugins/pod_network_outage/pod_network_outage_plugin.py index 4c590762..4c5fafab 100755 --- a/kraken/plugins/pod_network_outage/pod_network_outage_plugin.py +++ b/kraken/plugins/pod_network_outage/pod_network_outage_plugin.py @@ -10,7 +10,7 @@ from dataclasses import dataclass, field from traceback import format_exc from jinja2 import Environment, FileSystemLoader -from krkn_lib_kubernetes import KrknLibKubernetes +from krkn_lib.k8s import KrknKubernetes from arcaflow_plugin_sdk import plugin, validation from kubernetes import client from kubernetes.client.api.apiextensions_v1_api import ApiextensionsV1Api @@ -19,7 +19,7 @@ def get_test_pods( - pod_name: str, pod_label: str, namespace: str, kubecli: KrknLibKubernetes + pod_name: str, pod_label: str, namespace: str, kubecli: KrknKubernetes ) -> typing.List[str]: """ Function that returns a list of pods to apply network policy @@ -35,7 +35,7 @@ def get_test_pods( namepsace (string) - namespace in which the pod is present - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client Returns: @@ -54,12 +54,12 @@ def get_test_pods( return pods_list -def get_job_pods(kubecli: KrknLibKubernetes, api_response): +def get_job_pods(kubecli: KrknKubernetes, api_response): """ Function that gets the pod corresponding to the job Args: - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client api_response @@ -78,12 +78,12 @@ def get_job_pods(kubecli: KrknLibKubernetes, api_response): return pods_list[0] -def delete_jobs(kubecli: KrknLibKubernetes, job_list: typing.List[str]): +def delete_jobs(kubecli: KrknKubernetes, job_list: typing.List[str]): """ Function that deletes jobs Args: - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client job_list (List of strings) @@ -109,7 +109,7 @@ def delete_jobs(kubecli: KrknLibKubernetes, job_list: typing.List[str]): def wait_for_job( - job_list: typing.List[str], kubecli: KrknLibKubernetes, timeout: int = 300 + job_list: typing.List[str], kubecli: KrknKubernetes, timeout: int = 300 ) -> None: """ Function that waits for a list of jobs to finish within a time period @@ -118,7 +118,7 @@ def wait_for_job( job_list (List of strings) - The list of jobs to check for completion - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client timeout (int) @@ -195,7 +195,7 @@ def apply_outage_policy( direction: str, duration: str, bridge_name: str, - kubecli: KrknLibKubernetes, + kubecli: KrknKubernetes, ) -> typing.List[str]: """ Function that applies filters(ingress or egress) to block traffic. @@ -278,7 +278,7 @@ def apply_net_policy( network_params: typing.Dict[str, str], duration: str, bridge_name: str, - kubecli: KrknLibKubernetes, + kubecli: KrknKubernetes, test_execution: str, ) -> typing.List[str]: """ @@ -312,7 +312,7 @@ def apply_net_policy( bridge_name (string): - bridge to which filter rules need to be applied - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client test_execution (String) @@ -393,7 +393,7 @@ def get_egress_cmd( def list_bridges( - node: str, pod_template, kubecli: KrknLibKubernetes + node: str, pod_template, kubecli: KrknKubernetes ) -> typing.List[str]: """ Function that returns a list of bridges on the node @@ -406,7 +406,7 @@ def list_bridges( - The YAML template used to instantiate a pod to query the node's interface - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client Returns: @@ -437,7 +437,7 @@ def list_bridges( def check_cookie( - node: str, pod_template, br_name, cookie, kubecli: KrknLibKubernetes + node: str, pod_template, br_name, cookie, kubecli: KrknKubernetes ) -> str: """ Function to check for matching flow rules @@ -496,7 +496,7 @@ def check_cookie( def get_pod_interface( - node: str, ip: str, pod_template, br_name, kubecli: KrknLibKubernetes + node: str, ip: str, pod_template, br_name, kubecli: KrknKubernetes ) -> str: """ Function to query the pod interface on a node @@ -515,7 +515,7 @@ def get_pod_interface( br_name (string): - bridge against which the flows rules need to be checked - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client Returns @@ -576,7 +576,7 @@ def get_pod_interface( def check_bridge_interface( - node_name: str, pod_template, bridge_name: str, kubecli: KrknLibKubernetes + node_name: str, pod_template, bridge_name: str, kubecli: KrknKubernetes ) -> bool: """ Function is used to check if the required OVS or OVN bridge is found in @@ -593,7 +593,7 @@ def check_bridge_interface( bridge_name (string): - bridge name to check for in the node. - kubecli (KrknLibKubernetes) + kubecli (KrknKubernetes) - Object to interact with Kubernetes Python client Returns: @@ -815,7 +815,7 @@ def pod_outage( node_dict = {} label_set = set() - kubecli = KrknLibKubernetes(kubeconfig_path=params.kubeconfig_path) + kubecli = KrknKubernetes(kubeconfig_path=params.kubeconfig_path) api_ext = client.ApiextensionsV1Api(kubecli.api_client) custom_obj = client.CustomObjectsApi(kubecli.api_client) @@ -1073,7 +1073,7 @@ def pod_egress_shaping( param_lst = ["latency", "loss", "bandwidth"] mod_lst = [i for i in param_lst if i in params.network_params] - kubecli = KrknLibKubernetes(kubeconfig_path=params.kubeconfig_path) + kubecli = KrknKubernetes(kubeconfig_path=params.kubeconfig_path) api_ext = client.ApiextensionsV1Api(kubecli.api_client) custom_obj = client.CustomObjectsApi(kubecli.api_client) diff --git a/kraken/pod_scenarios/setup.py b/kraken/pod_scenarios/setup.py index 2c02a5fd..05538dcd 100644 --- a/kraken/pod_scenarios/setup.py +++ b/kraken/pod_scenarios/setup.py @@ -1,16 +1,15 @@ import logging - -from arcaflow_plugin_sdk import serialization -import arcaflow_plugin_kill_pod - -import kraken.cerberus.setup as cerberus -import kraken.post_actions.actions as post_actions -import krkn_lib_kubernetes import time import yaml import sys import random -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +import arcaflow_plugin_kill_pod +import kraken.cerberus.setup as cerberus +import kraken.post_actions.actions as post_actions +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry +from arcaflow_plugin_sdk import serialization # Run pod based scenarios def run(kubeconfig_path, scenarios_list, config, failed_post_scenarios, wait_duration): @@ -66,13 +65,13 @@ def run(kubeconfig_path, scenarios_list, config, failed_post_scenarios, wait_dur cerberus.publish_kraken_status(config, failed_post_scenarios, start_time, end_time) return failed_post_scenarios -# krkn_lib_kubernetes +# krkn_lib def container_run(kubeconfig_path, scenarios_list, config, failed_post_scenarios, wait_duration, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes, + kubecli: KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): failed_scenarios = [] @@ -129,7 +128,7 @@ def container_run(kubeconfig_path, -def container_killing_in_pod(cont_scenario, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def container_killing_in_pod(cont_scenario, kubecli: KrknKubernetes): scenario_name = cont_scenario.get("name", "") namespace = cont_scenario.get("namespace", "*") label_selector = cont_scenario.get("label_selector", None) @@ -196,7 +195,7 @@ def container_killing_in_pod(cont_scenario, kubecli: krkn_lib_kubernetes.KrknLib return killed_container_list -def retry_container_killing(kill_action, podname, namespace, container_name, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def retry_container_killing(kill_action, podname, namespace, container_name, kubecli: KrknKubernetes): i = 0 while i < 5: logging.info("Killing container %s in pod %s (ns %s)" % (str(container_name), str(podname), str(namespace))) @@ -213,7 +212,7 @@ def retry_container_killing(kill_action, podname, namespace, container_name, kub continue -def check_failed_containers(killed_container_list, wait_time, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +def check_failed_containers(killed_container_list, wait_time, kubecli: KrknKubernetes): container_ready = [] timer = 0 diff --git a/kraken/pvc/pvc_scenario.py b/kraken/pvc/pvc_scenario.py index de062212..28e393c2 100644 --- a/kraken/pvc/pvc_scenario.py +++ b/kraken/pvc/pvc_scenario.py @@ -1,16 +1,16 @@ import logging import random import re -import sys import time -import krkn_lib_kubernetes import yaml - from ..cerberus import setup as cerberus -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry + -# krkn_lib_kubernetes -def run(scenarios_list, config, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): +# krkn_lib +def run(scenarios_list, config, kubecli: KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): """ Reads the scenario config and creates a temp file to fill up the PVC """ @@ -317,7 +317,7 @@ def run(scenarios_list, config, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, -# krkn_lib_kubernetes +# krkn_lib def remove_temp_file( file_name, full_path, @@ -326,7 +326,7 @@ def remove_temp_file( container_name, mount_path, file_size_kb, - kubecli: krkn_lib_kubernetes.KrknLibKubernetes + kubecli: KrknKubernetes ): command = "rm -f %s" % (str(full_path)) logging.debug("Remove temp file from the PVC command:\n %s" % command) diff --git a/kraken/shut_down/common_shut_down_func.py b/kraken/shut_down/common_shut_down_func.py index e498b819..72e78609 100644 --- a/kraken/shut_down/common_shut_down_func.py +++ b/kraken/shut_down/common_shut_down_func.py @@ -1,19 +1,17 @@ #!/usr/bin/env python -import os -import sys import yaml import logging import time -import krkn_lib_kubernetes from multiprocessing.pool import ThreadPool - from ..cerberus import setup as cerberus from ..post_actions import actions as post_actions from ..node_actions.aws_node_scenarios import AWS from ..node_actions.openstack_node_scenarios import OPENSTACKCLOUD from ..node_actions.az_node_scenarios import Azure from ..node_actions.gcp_node_scenarios import GCP -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry def multiprocess_nodes(cloud_object_function, nodes): try: @@ -40,8 +38,8 @@ def multiprocess_nodes(cloud_object_function, nodes): # Inject the cluster shut down scenario -# krkn_lib_kubernetes -def cluster_shut_down(shut_down_config, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def cluster_shut_down(shut_down_config, kubecli: KrknKubernetes): runs = shut_down_config["runs"] shut_down_duration = shut_down_config["shut_down_duration"] cloud_type = shut_down_config["cloud_type"] @@ -128,9 +126,9 @@ def cluster_shut_down(shut_down_config, kubecli: krkn_lib_kubernetes.KrknLibKube logging.info("Successfully injected cluster_shut_down scenario!") -# krkn_lib_kubernetes +# krkn_lib -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): +def run(scenarios_list, config, wait_duration, kubecli: KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): failed_post_scenarios = [] failed_scenarios = [] scenario_telemetries: list[ScenarioTelemetry] = [] diff --git a/kraken/time_actions/common_time_functions.py b/kraken/time_actions/common_time_functions.py index 5ace3c2c..656bb90e 100644 --- a/kraken/time_actions/common_time_functions.py +++ b/kraken/time_actions/common_time_functions.py @@ -2,16 +2,16 @@ import time import logging import re -import sys import yaml import random -import krkn_lib_kubernetes from ..cerberus import setup as cerberus from ..invoke import command as runcommand -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry -# krkn_lib_kubernetes -def pod_exec(pod_name, command, namespace, container_name, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def pod_exec(pod_name, command, namespace, container_name, kubecli:KrknKubernetes): for i in range(5): response = kubecli.exec_cmd_in_pod( command, @@ -40,8 +40,8 @@ def node_debug(node_name, command): return response -# krkn_lib_kubernetes -def get_container_name(pod_name, namespace, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, container_name=""): +# krkn_lib +def get_container_name(pod_name, namespace, kubecli:KrknKubernetes, container_name=""): container_names = kubecli.get_containers_in_pod(pod_name, namespace) if container_name != "": @@ -63,8 +63,8 @@ def get_container_name(pod_name, namespace, kubecli: krkn_lib_kubernetes.KrknLib return container_name -# krkn_lib_kubernetes -def skew_time(scenario, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def skew_time(scenario, kubecli:KrknKubernetes): skew_command = "date --set " if scenario["action"] == "skew_date": skewed_date = "00-01-01" @@ -231,8 +231,8 @@ def string_to_date(obj_datetime): return datetime.datetime(datetime.MINYEAR, 1, 1) -# krkn_lib_kubernetes -def check_date_time(object_type, names, kubecli: krkn_lib_kubernetes.KrknLibKubernetes): +# krkn_lib +def check_date_time(object_type, names, kubecli:KrknKubernetes): skew_command = "date" not_reset = [] max_retries = 30 @@ -307,8 +307,8 @@ def check_date_time(object_type, names, kubecli: krkn_lib_kubernetes.KrknLibKube return not_reset -# krkn_lib_kubernetes -def run(scenarios_list, config, wait_duration, kubecli: krkn_lib_kubernetes.KrknLibKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): +# krkn_lib +def run(scenarios_list, config, wait_duration, kubecli:KrknKubernetes, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]): failed_scenarios = [] scenario_telemetries: list[ScenarioTelemetry] = [] for time_scenario_config in scenarios_list: diff --git a/kraken/zone_outage/actions.py b/kraken/zone_outage/actions.py index 96690068..6ed3de49 100644 --- a/kraken/zone_outage/actions.py +++ b/kraken/zone_outage/actions.py @@ -3,7 +3,9 @@ import time from ..node_actions.aws_node_scenarios import AWS from ..cerberus import setup as cerberus -from krkn_lib_kubernetes import ScenarioTelemetry, KrknTelemetry +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ScenarioTelemetry + def run(scenarios_list, config, wait_duration, telemetry: KrknTelemetry) -> (list[str], list[ScenarioTelemetry]) : """ diff --git a/requirements.txt b/requirements.txt index 223d6ca0..6e1e28d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,4 +37,4 @@ prometheus_api_client ibm_cloud_sdk_core ibm_vpc pytest -krkn-lib-kubernetes >= 0.1.3 \ No newline at end of file +krkn-lib >= 1.0.0 \ No newline at end of file diff --git a/run_kraken.py b/run_kraken.py index 816f9b09..ecdc8316 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -25,7 +25,11 @@ import server as server import kraken.prometheus.client as promcli from kraken import plugins -from krkn_lib_kubernetes import KrknLibKubernetes, KrknTelemetry, ChaosRunTelemetry, SafeLogger + +from krkn_lib.k8s import KrknKubernetes +from krkn_lib.telemetry import KrknTelemetry +from krkn_lib.models.telemetry import ChaosRunTelemetry +from krkn_lib.utils import SafeLogger KUBE_BURNER_URL = ( "https://github.com/cloud-bulldozer/kube-burner/" @@ -119,7 +123,7 @@ def main(cfg): kubeconfig_path os.environ["KUBECONFIG"] = str(kubeconfig_path) # krkn-lib-kubernetes init - kubecli = KrknLibKubernetes(kubeconfig_path=kubeconfig_path) + kubecli = KrknKubernetes(kubeconfig_path=kubeconfig_path) except: kubecli.initialize_clients(None) @@ -233,7 +237,7 @@ def main(cfg): telemetry ) chaos_telemetry.scenarios.extend(scenario_telemetries) - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "container_scenarios": logging.info("Running container scenarios") failed_post_scenarios, scenario_telemetries = pod_scenarios.container_run( @@ -248,13 +252,13 @@ def main(cfg): chaos_telemetry.scenarios.extend(scenario_telemetries) # Inject node chaos scenarios specified in the config - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "node_scenarios": logging.info("Running node scenarios") failed_post_scenarios, scenario_telemetries = nodeaction.run(scenarios_list, config, wait_duration, kubecli, telemetry) chaos_telemetry.scenarios.extend(scenario_telemetries) # Inject managedcluster chaos scenarios specified in the config - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "managedcluster_scenarios": logging.info("Running managedcluster scenarios") managedcluster_scenarios.run( @@ -263,7 +267,7 @@ def main(cfg): # Inject time skew chaos scenarios specified # in the config - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "time_scenarios": if distribution == "openshift": logging.info("Running time skew scenarios") @@ -316,13 +320,13 @@ def main(cfg): sys.exit(1) # Inject cluster shutdown scenarios - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "cluster_shut_down_scenarios": failed_post_scenarios, scenario_telemetries = shut_down.run(scenarios_list, config, wait_duration, kubecli, telemetry) chaos_telemetry.scenarios.extend(scenario_telemetries) # Inject namespace chaos scenarios - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "namespace_scenarios": logging.info("Running namespace scenarios") failed_post_scenarios, scenario_telemetries = namespace_actions.run( @@ -349,14 +353,14 @@ def main(cfg): chaos_telemetry.scenarios.extend(scenario_telemetries) # PVC scenarios - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "pvc_scenarios": logging.info("Running PVC scenario") failed_post_scenarios, scenario_telemetries = pvc_scenario.run(scenarios_list, config, kubecli, telemetry) chaos_telemetry.scenarios.extend(scenario_telemetries) # Network scenarios - # krkn_lib_kubernetes + # krkn_lib elif scenario_type == "network_chaos": logging.info("Running Network Chaos") failed_post_scenarios, scenario_telemetries = network_chaos.run(scenarios_list, config, wait_duration, kubecli, telemetry)