diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py index dc4a6599..8b1933b0 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py @@ -1,3 +1,4 @@ +import logging import queue import time @@ -12,10 +13,9 @@ from krkn.scenario_plugins.network_chaos_ng.models import ( from krkn.scenario_plugins.network_chaos_ng.modules.abstract_network_chaos_module import ( AbstractNetworkChaosModule, ) -from krkn.scenario_plugins.network_chaos_ng.modules.utils import log_info +from krkn.scenario_plugins.network_chaos_ng.modules.utils import log_info, log_error from krkn.scenario_plugins.network_chaos_ng.modules.utils_network_filter import ( deploy_network_filter_pod, - get_default_interface, generate_namespaced_rules, apply_network_rules, clean_network_rules_namespaced, @@ -56,23 +56,28 @@ class PodNetworkFilterModule(AbstractNetworkChaosModule): pod_name, self.kubecli.get_lib_kubernetes(), container_name, + host_network=False, ) if len(self.config.interfaces) == 0: - interfaces = [ - get_default_interface( - pod_name, - self.config.namespace, - self.kubecli.get_lib_kubernetes(), + interfaces = ( + self.kubecli.get_lib_kubernetes().list_pod_network_interfaces( + target, self.config.namespace ) - ] + ) + if len(interfaces) == 0: + log_error( + "no network interface found in pod, impossible to execute the network filter scenario", + parallel, + pod_name, + ) + return log_info( - f"detected default interface {interfaces[0]}", + f"detected network interfaces: {','.join(interfaces)}", parallel, pod_name, ) - else: interfaces = self.config.interfaces diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/utils.py b/krkn/scenario_plugins/network_chaos_ng/modules/utils.py index 35020eeb..7e6ab2a8 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/utils.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/utils.py @@ -11,7 +11,7 @@ def log_info(message: str, parallel: bool = False, node_name: str = ""): logging.info(message) -def log_error(self, message: str, parallel: bool = False, node_name: str = ""): +def log_error(message: str, parallel: bool = False, node_name: str = ""): """ log helper method for ERROR severity to be used in the scenarios """ @@ -21,7 +21,7 @@ def log_error(self, message: str, parallel: bool = False, node_name: str = ""): logging.error(message) -def log_warning(self, message: str, parallel: bool = False, node_name: str = ""): +def log_warning(message: str, parallel: bool = False, node_name: str = ""): """ log helper method for WARNING severity to be used in the scenarios """ diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py index 1bdefae4..136c2321 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py @@ -54,6 +54,7 @@ def deploy_network_filter_pod( pod_name: str, kubecli: KrknKubernetes, container_name: str = "fedora", + host_network: bool = True, ): file_loader = FileSystemLoader(os.path.abspath(os.path.dirname(__file__))) env = Environment(loader=file_loader, autoescape=True) @@ -78,17 +79,16 @@ def deploy_network_filter_pod( toleration["value"] = value tolerations.append(toleration) - pod_body = yaml.safe_load( pod_template.render( pod_name=pod_name, namespace=config.namespace, - host_network=True, + host_network=host_network, target=target_node, container_name=container_name, workload_image=config.image, taints=tolerations, - service_account=config.service_account + service_account=config.service_account, ) ) diff --git a/requirements.txt b/requirements.txt index 1e5147f6..5d074aa9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ google-cloud-compute==1.22.0 ibm_cloud_sdk_core==3.18.0 ibm_vpc==0.20.0 jinja2==3.1.6 -krkn-lib==5.1.8 +krkn-lib==5.1.9 lxml==5.1.0 kubernetes==28.1.0 numpy==1.26.4