Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kraken:
kubeconfig_path: ~/.kube/config # Path to kubeconfig
kubeconfig_path: ~/Scrap/test-cluster/auth/kubeconfig # Path to kubeconfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put this back to .kube/config as the default

exit_on_failure: False # Exit when a post action scenario fails
auto_rollback: True # Enable auto rollback for scenarios.
rollback_versions_directory: /tmp/kraken-rollback # Directory to store rollback version files.
Expand All @@ -17,9 +17,6 @@ kraken:
- scenarios/openshift/app_outage.yaml
- container_scenarios: # List of chaos pod scenarios to load
- scenarios/openshift/container_etcd.yml
- pod_network_scenarios:
- scenarios/openshift/network_chaos_ingress.yml
- scenarios/openshift/pod_network_outage.yml
- pod_disruption_scenarios:
- scenarios/openshift/etcd.yml
- scenarios/openshift/regex_openshift_pod_kill.yml
Expand Down Expand Up @@ -48,8 +45,13 @@ kraken:
- syn_flood_scenarios:
- scenarios/kube/syn_flood.yaml
- network_chaos_ng_scenarios:
- scenarios/kube/pod-network-filter.yml
- scenarios/kube/node-network-filter.yml
- scenarios/kube/pod-network-filter.yml
- scenarios/kube/pod-ingress-shaping.yml
- scenarios/kube/pod-egress-shaping.yml
- pod_network_scenarios:
- scenarios/openshift/network_chaos_ingress.yml
- scenarios/openshift/pod_network_outage.yml
- kubevirt_vm_outage:
- scenarios/kubevirt/kubevirt-vm-outage.yaml

Expand Down
157 changes: 0 additions & 157 deletions krkn/scenario_plugins/native/pod_network_outage/cerberus.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from kubernetes import client
from kubernetes.client.api.apiextensions_v1_api import ApiextensionsV1Api
from kubernetes.client.api.custom_objects_api import CustomObjectsApi
from . import cerberus

from krkn import cerberus


def get_test_pods(
Expand Down
28 changes: 24 additions & 4 deletions krkn/scenario_plugins/network_chaos_ng/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from enum import Enum
from typing import Optional


class NetworkChaosScenarioType(Enum):
Expand All @@ -10,15 +11,17 @@ class NetworkChaosScenarioType(Enum):
@dataclass
class BaseNetworkChaosConfig:
supported_execution = ["serial", "parallel"]
taints: list[str]
id: str
wait_duration: int
test_duration: int
label_selector: str
service_account: str
instance_count: int
execution: str
namespace: str
taints: list[str]
target: str
service_account: str
image: str

def validate(self) -> list[str]:
errors = []
Expand All @@ -44,10 +47,9 @@ class NetworkFilterConfig(BaseNetworkChaosConfig):
ingress: bool
egress: bool
interfaces: list[str]
target: str
ports: list[int]
image: str
protocols: list[str]
force: bool

def validate(self) -> list[str]:
errors = super().validate()
Expand All @@ -58,3 +60,21 @@ def validate(self) -> list[str]:
f"{self.protocols} contains not allowed protocols only tcp and udp is allowed"
)
return errors


@dataclass
class PodNetworkShaping(BaseNetworkChaosConfig):
network_shaping_execution: str
latency: str
loss: str
bandwidth: str

def __iter__(self):
if self.network_shaping_execution:
yield "network_shaping_execution"
if self.latency:
yield "latency"
if self.loss:
yield "loss"
if self.bandwidth:
yield "bandwidth"
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_config(self) -> (NetworkChaosScenarioType, BaseNetworkChaosConfig):
"""
pass

@abc.abstractmethod
def get_targets(self) -> list[str]:
"""
checks and returns the targets based on the common scenario configuration
Expand All @@ -48,3 +49,42 @@ def __init__(
):
self.kubecli = kubecli
self.base_network_config = base_network_config


def get_pod_targets(self) -> list[str]:
if not self.base_network_config.namespace:
raise Exception("namespace not specified, aborting")
if self.base_network_config.label_selector:
return self.kubecli.get_lib_kubernetes().list_pods(
self.base_network_config.namespace, self.base_network_config.label_selector
)
else:
if not self.base_network_config.target:
raise Exception(
"neither pod selector nor pod name (target) specified, aborting."
)
if not self.kubecli.get_lib_kubernetes().check_if_pod_exists(
self.base_network_config.target, self.base_network_config.namespace
):
raise Exception(
f"pod {self.base_network_config.target} not found in namespace {self.base_network_config.namespace}"
)

return [self.base_network_config.target]

def get_node_targets(self) -> list[str]:
if self.base_network_config.label_selector:
return self.kubecli.get_lib_kubernetes().list_nodes(
self.base_network_config.label_selector
)
else:
if not self.base_network_config.target:
raise Exception(
"neither node selector nor node_name (target) specified, aborting."
)
node_info = self.kubecli.get_lib_kubernetes().list_nodes()
if self.base_network_config.target not in node_info:
raise Exception(f"node {self.base_network_config.target} not found, aborting")

return [self.base_network_config.target]

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def run(self, target: str, error_queue: queue.Queue = None):
else:
interfaces = self.config.interfaces

input_rules, output_rules = generate_rules(interfaces, self.config)
input_rules, output_rules = generate_rules(
interfaces, self.config, NetworkChaosScenarioType.Node, parallel, target
)

apply_network_rules(
self.kubecli.get_lib_kubernetes(),
Expand Down Expand Up @@ -112,17 +114,4 @@ def get_config(self) -> (NetworkChaosScenarioType, BaseNetworkChaosConfig):
return NetworkChaosScenarioType.Node, self.config

def get_targets(self) -> list[str]:
if self.base_network_config.label_selector:
return self.kubecli.get_lib_kubernetes().list_nodes(
self.base_network_config.label_selector
)
else:
if not self.config.target:
raise Exception(
"neither node selector nor node_name (target) specified, aborting."
)
node_info = self.kubecli.get_lib_kubernetes().list_nodes()
if self.config.target not in node_info:
raise Exception(f"node {self.config.target} not found, aborting")

return [self.config.target]
return self.get_node_targets()
Loading
Loading