From f04f1f1101208e06850cb4a9893a1034a40fa260 Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Wed, 25 Jun 2025 17:08:59 +0200 Subject: [PATCH] added workload image as scenario parameter (#854) * added workload image as scenario parameter Signed-off-by: Tullio Sebastiani * renamed workload_image to image Signed-off-by: Tullio Sebastiani --------- Signed-off-by: Tullio Sebastiani --- krkn/scenario_plugins/network_chaos_ng/models.py | 11 +++++++++-- .../network_chaos_ng/modules/node_network_filter.py | 1 + .../modules/templates/network-chaos.j2 | 2 +- scenarios/kube/network-filter.yml | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/krkn/scenario_plugins/network_chaos_ng/models.py b/krkn/scenario_plugins/network_chaos_ng/models.py index e8efbcfe..0ba42a37 100644 --- a/krkn/scenario_plugins/network_chaos_ng/models.py +++ b/krkn/scenario_plugins/network_chaos_ng/models.py @@ -6,6 +6,7 @@ class NetworkChaosScenarioType(Enum): Node = 1 Pod = 2 + @dataclass class BaseNetworkChaosConfig: supported_execution = ["serial", "parallel"] @@ -20,13 +21,18 @@ class BaseNetworkChaosConfig: def validate(self) -> list[str]: errors = [] if self.execution is None: - errors.append(f"execution cannot be None, supported values are: {','.join(self.supported_execution)}") + errors.append( + f"execution cannot be None, supported values are: {','.join(self.supported_execution)}" + ) if self.execution not in self.supported_execution: - errors.append(f"{self.execution} is not in supported execution mod: {','.join(self.supported_execution)}") + errors.append( + f"{self.execution} is not in supported execution mod: {','.join(self.supported_execution)}" + ) if self.label_selector is None: errors.append("label_selector cannot be None") return errors + @dataclass class NetworkFilterConfig(BaseNetworkChaosConfig): ingress: bool @@ -34,6 +40,7 @@ class NetworkFilterConfig(BaseNetworkChaosConfig): interfaces: list[str] target: str ports: list[int] + image: str def validate(self) -> list[str]: errors = super().validate() diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py index 96d1b399..c6ee062e 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py @@ -41,6 +41,7 @@ class NodeNetworkFilterModule(AbstractNetworkChaosModule): namespace=self.config.namespace, host_network=True, target=target, + workload_image=self.config.image, ) ) self.log_info( diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/templates/network-chaos.j2 b/krkn/scenario_plugins/network_chaos_ng/modules/templates/network-chaos.j2 index 5d14b098..93edf2ed 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/templates/network-chaos.j2 +++ b/krkn/scenario_plugins/network_chaos_ng/modules/templates/network-chaos.j2 @@ -12,6 +12,6 @@ spec: containers: - name: fedora imagePullPolicy: Always - image: quay.io/krkn-chaos/krkn-network-chaos:latest + image: {{workload_image}} securityContext: privileged: true diff --git a/scenarios/kube/network-filter.yml b/scenarios/kube/network-filter.yml index 68259e24..73cc111a 100644 --- a/scenarios/kube/network-filter.yml +++ b/scenarios/kube/network-filter.yml @@ -1,7 +1,8 @@ - id: node_network_filter + image: "quay.io/krkn-chaos/krkn-network-chaos:latest" wait_duration: 300 test_duration: 100 - label_selector: "kubernetes.io/hostname=ip-10-0-39-182.us-east-2.compute.internal" + label_selector: "kubernetes.io/hostname=minikube" namespace: 'default' instance_count: 1 execution: parallel