k8s.krkn_kubernetes module

class k8s.krkn_kubernetes.KrknKubernetes(kubeconfig_path: str, request_chunk_size: int = 250)

Bases: object

__init__(kubeconfig_path: str, request_chunk_size: int = 250)

KrknKubernetes Constructor. Can be invoked with kubeconfig_path or, optionally, with a kubeconfig in string format using the keyword argument

Parameters:

kubeconfig_path – kubeconfig path

Param:

request_chunk_size: int of chunk size to limit requests to

Initialization with kubeconfig path:

>>> KrknKubernetes(log_writer, "/home/test/.kube/config")
property api_client: ApiClient
apply_yaml(path, namespace='default') list[str]

Apply yaml config to create Kubernetes resources

Parameters:
  • path – path to the YAML file

  • namespace – namespace to create the resource (optional default default)

Returns:

the list of names of created objects

property apps_api: AppsV1Api
archive_and_get_path_from_pod(pod_name: str, container_name: str, namespace: str, remote_archive_path: str, target_path: str, archive_files_prefix: str, download_path: str = '/tmp', archive_part_size: int = 30000, max_threads: int = 5, safe_logger: SafeLogger | None = None) list[int, str]

Archives and downloads a folder content from container in a base64 tarball. The function is designed to leverage multi-threading in order to maximize the download speed. a max_threads number of download_archive_part_from_pod calls will be made in parallel.

Parameters:
  • pod_name – pod name from which the folder must be downloaded

  • container_name – container name from which the folder must be downloaded

  • namespace – namespace of the pod

  • remote_archive_path – path in the container where the temporary archive will be stored (will be deleted once the download terminates, must be writable and must have enough space to temporarly store the archive)

  • target_path – the path that will be archived and downloaded from the container

  • archive_files_prefix – prefix string that will be added to the files

  • download_path – the local path where the archive will be saved

  • archive_part_size – the archive will be split into multiple files of the specified archive_part_size

  • max_threads – maximum number of threads that will be launched

  • safe_logger – SafeLogger, if omitted a default SafeLogger will be instantiated that will simply use the logging package to print logs to stdout.

Returns:

the list of the archive number and filenames downloaded

property batch_cli: BatchV1Api
check_if_namespace_exists(name: str) bool

Check if a namespace exists by parsing through

Parameters:

name – namespace name

Returns:

boolean value indicating whether the namespace exists or not

check_if_pod_exists(name: str, namespace: str = 'default') bool

Check if a pod exists in the given namespace

Parameters:
  • name – pod name

  • namespace – namespace (optional default default)

Returns:

boolean value indicating whether the pod exists or not

check_if_pvc_exists(name: str, namespace: str = 'default') bool

Check if a PVC exists by parsing through the list of projects.

Parameters:
  • name – PVC name

  • namespace – namespace (optional default default)

Returns:

boolean value indicating whether the Persistent Volume Claim exists or not

check_namespaces(namespaces: list[str], label_selector: str | None = None) list[str]

Check if all the watch_namespaces are valid

Parameters:
  • namespaces – list of namespaces to check

  • label_selector – filter by label_selector (optional default None)

Returns:

a list of matching namespaces

property cli: CoreV1Api
client_config: Configuration = None
collect_and_parse_cluster_events(start_timestamp: int, end_timestamp: int, local_timezone: str, cluster_timezone: str = 'UTC', limit: int = 500, namespace: str | None = None) list[ClusterEvent]

Collects cluster events querying /api/v1/events filtered in a given time interval and writes them in a temporary file in json format.

Parameters:
  • start_timestamp – timestamp of the minimum date after that the event is relevant

  • end_timestamp – timestamp of the maximum date before that the event is relevant

  • local_timezone – timezone of the local system

  • cluster_timezone – timezone of the remote cluster

  • limit – limit of the number of events to be fetched from the cluster

  • namespace – Namespace from which the events must be collected, if None all-namespaces will be selected

Returns:

Returns a list of parsed ClusterEvents

create_job(body: any, namespace: str = 'default') V1Job

Create a job in a namespace

Parameters:
  • body – an object representation of a valid job yaml manifest

  • namespace – namespace (optional default default), Note: if namespace is specified in the body won’t override

Returns:

V1Job API object

create_manifestwork(body: any, namespace: str = 'default') object

Create an open cluster management manifestwork in a namespace. ManifestWork is used to define a group of Kubernetes resources on the hub to be applied to the managed cluster.

Parameters:
  • body – an object representation of a valid manifestwork yaml manifest

  • namespace – namespace (optional default default)

Returns:

a custom object representing the newly created manifestwork

create_net_policy(body: str, namespace: str)

Create a network policy

Parameters:
  • body – json body of network policy to create

  • namespace – namespace to find daemonsets in

create_obj(obj_body: <module 'json' from '/opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/json/__init__.py'>, namespace: str, api_func)
create_pod(body: any, namespace: str, timeout: int = 120)

Create a pod in a namespace

Parameters:
  • body – an object representation of a valid pod yaml manifest

  • namespace – namespace where the pod is created

  • timeout – request timeout

create_token_for_sa(namespace: str, service_account: str, token_expiration=43200) str | None

Creates a token for an existing ServiceAccount in a namespace that will expire in <token_expiration> seconds (optional)

Parameters:
  • namespace – the namespace where the SA belongs

  • service_account – the name of the SA

  • token_expiration – the duration of the SA in seconds, default 12h

Returns:

the token or None if something went wrong.

property custom_object_client: CustomObjectsApi
delete_daemonset(name: str, namespace: str)

Delete a daemonset given a certain name and namespace

Parameters:
  • name – name of daemonset

  • namespace – namespace daemonset is in

delete_deployment(name: str, namespace: str)

Delete a deployments given a certain name and namespace

Parameters:
  • name – name of deployment

  • namespace – namespace deployment is in

delete_file_from_pod(pod_name: str, container_name: str, namespace: str, filename: str)

Deletes a file from a pod

Parameters:
  • pod_name – pod name

  • container_name – container name

  • namespace – namespace of the pod

  • filename – full-path of the file that will be removed from the pod

delete_job(name: str, namespace: str = 'default') V1Status

Delete a job from a namespace

Parameters:
  • name – job name

  • namespace – namespace (optional default default)

Returns:

V1Status API object

delete_manifestwork(namespace: str)

Delete a manifestwork from a namespace

Parameters:

namespace – namespace from where the manifestwork must be deleted

Returns:

a custom object representing the deleted resource

delete_namespace(namespace: str) V1Status

Delete a given namespace using k8s python client

Parameters:

namespace – namespace name

Returns:

V1Status API object

delete_net_policy(name: str, namespace: str)

Delete a network policy given a certain name and namespace

Parameters:
  • name – name of network policy

  • namespace – namespace network policy is in

delete_pod(name: str, namespace: str = 'default')

Delete a pod in a namespace

Parameters:
  • name – pod name

  • namespace – namespace (optional default default)

delete_replicaset(name: str, namespace: str)

Delete a replicaset given a certain name and namespace

Parameters:
  • name – name of replicaset

  • namespace – namespace replicaset is in

delete_services(name: str, namespace: str)

Delete a service given a certain name and namespace

Parameters:
  • name – name of service

  • namespace – namespace service is in

delete_statefulset(name: str, namespace: str)

Delete a statefulset given a certain name and namespace

Parameters:
  • name – name of statefulset

  • namespace – namespace statefulset is in

deploy_hog(pod_name: str, hog_config: HogConfig)

Deploys a Pod to run the Syn Flood scenario

Parameters:
  • pod_name – The name of the pod that will be deployed

  • hog_config – Hog Configuration

deploy_service_hijacking(namespace: str, plan: dict[any], image: str, port_number: int = 5000, port_name: str = 'flask', stats_route: str = '/stats') ServiceHijacking

Deploys a pod running the service-hijacking webservice along with the test plan deployed in krkn stored in a ConfigMap and bound as a file to the container

Parameters:
  • namespace – The namespace where the Pod and the ConfigMap will be deployed

  • plan – the dictionary converted test plan to be executed in the service

  • image – the image container image of the service

  • port_number – the port where the pod will be listening default 5000

  • port_name – the port name if the Service is pointing to a string name instead of a port number

  • stats_route – overrides the defautl route where the stats action will be mapped, change it only if you have a /stats route in your test_plan

Returns:

a structure containing all the infos of the Pod and the ConfigMap deployment

deploy_syn_flood(pod_name: str, namespace: str, image: str, target: str, target_port: int, packet_size: int, window_size: int, duration: int, node_selectors: dict[str, list[str]])

Deploys a Pod to run the Syn Flood scenario

Parameters:
  • pod_name – The name of the pod that will be deployed

  • namespace – The namespace where the pod will be deployed

  • image – the syn flood scenario container image

  • target – the target hostname or ip address

  • target_port – the target TCP port

  • packet_size – the SYN packet size in bytes

  • window_size – the TCP window size in bytes

  • duration – the duration of the flood in seconds

  • node_selectors – the node selectors of the node(s) where the pod will be scheduled by kubernetes

property dyn_client: DynamicClient
exec_cmd_in_pod(command: list[str], pod_name: str, namespace: str, container: str | None = None, base_command: str | None = None, std_err: bool = True) str

Executes a base command and its parameters in a pod or a container

Parameters:
  • command – command parameters list or full command string if the command must be piped to bash -c (in that case base_command parameter must is omitted`)

  • pod_name – pod where the command must be executed

  • namespace – namespace of the pod

  • container – container where the command must be executed (optional default None)

  • base_command – base command that must be executed along the parameters (optional, default bash -c is tested and if not present will fallback on sh -c )

Returns:

the command stdout

exec_command_on_node(node_name: str, command: [<class 'str'>], exec_pod_name: str, exec_pod_namespace: str = 'default', exec_pod_container: str | None = None) str

Creates a privileged pod on a specific node and executes a command on it to affect the node itself. The pod mounts also the dbus socket /run/dbus/system_bus_socket to exec kernel related commands like timedatectl. To see the pod spec check the template on src/krkn_lib/k8s/templates/

Parameters:
  • node_name – the name of the node where the command will be executed

  • command – the command and the options to be executed as a list of strings eg. [“ls”, “-al”]

  • exec_pod_name – the name of the pod that will be created

  • exec_pod_namespace – the namespace where the pod will be created (default “default”)

  • exec_pod_container – the container of the pod on which the pod will be executed (default None)

Returns:

the command output

find_kraken_node() str

Find the node kraken is deployed on Set global kraken node to not delete

Returns:

node where kraken is running (None if not found)

get_all_kubernetes_object_count(objects: list[str]) dict[str, int]
get_all_pod_info(namespace: str = 'default', label_selector: str | None = None) list[str]

Get details of all pods in a namespace

Parameters:

namespace – namespace (optional default default)

:return list of pod details

get_all_pods(label_selector: str | None = None) list[[<class 'str'>, <class 'str'>]]

Return a list of tuples containing pod name [0] and namespace [1]

Parameters:

label_selector – filter by label_selector (optional default None)

Returns:

list of tuples pod,namespace

get_all_replicasets(namespace: str) list[str]

Return a list of replicasets names

Parameters:

namespace – find only replicasets in given namespace

Returns:

list of replicasets names

get_all_services(namespace: str) list[str]

Return a list of service names

Parameters:

namespace – find only services in given namespace

Returns:

list of service names

get_all_statefulset(namespace) list[str]

Return a list of statefulset names

Parameters:

namespace – find only statefulset in given namespace

Returns:

list of statefulset names

get_api_resources_by_group(group, version)
get_archive_volume_from_pod_worker(pod_name: str, container_name: str, namespace: str, remote_archive_path: str, remote_archive_prefix: str, local_download_path: str, local_file_prefix: str, queue: Queue, queue_size: int, downloaded_file_list: list[int, str], delete_remote_after_download: bool, thread_number: int, safe_logger: SafeLogger)

Download worker for the create_download_multipart_archive method. The method will dequeue from the thread-safe queue parameter until the queue will be empty and will download the i-th tar volume popped from the queue itself. the file will be downloaded in base64 string format in order to avoid archive corruptions caused by the Kubernetes WebSocket API.

Parameters:
  • pod_name – pod name from which the tar volume must be downloaded

  • container_name – container name from which the tar volume be downloaded

  • namespace – namespace of the pod

  • remote_archive_path – remote path where the archive volume is stored

  • remote_archive_prefix – prefix of the file used to create the archive.to this prefix will be appended sequential number of the archive assigned to the worker in a two digit format and the tar exception (ex for a prefix like prefix - the remote filename will become prefix-00.tar)

  • local_download_path – local path where the tar volume will be download

  • local_file_prefix – local prefix to apply to the local file downloaded.To the prefix will be appended the sequential number of the archive assigned to the worker and the extension tar.b64

  • queue – the queue from which the sequential number wil be popped

  • queue_size – total size of the queue

  • downloaded_file_list – the list of archive number and local filename downloaded file will be appended once the download terminates shared between the threads

  • delete_remote_after_download – if set True once the download will terminate the remote file will be deleted.

  • thread_number – the assigned thread number

  • safe_logger – SafeLogger class, will allow thread-safe logging

get_containers_in_pod(pod_name: str, namespace: str = 'default') list[str]

Get container names of a pod

Parameters:
  • pod_name – pod name

  • namespace – namespace (optional default default)

Returns:

a list of container names

get_daemonset(namespace: str) list[str]

Return a list of daemon set names

Parameters:

namespace – namespace to find daemonsets in

Returns:

list of daemonset names

get_deployment_ns(namespace: str) list[str]

Return a list of deployment set names

Parameters:

namespace – namespace to find deployments in

Returns:

list of deployment names

get_deployment_ready(name: str, namespace: str)

Return a deployments detailed information

Parameters:
  • name – name of deployment

  • namespace – namespace deployment is in

get_host() str

Returns the Kubernetes server URL

Returns:

k8s server URL

get_job_status(name: str, namespace: str = 'default') V1Job

Get a job status

Parameters:
  • name – job name

  • namespace – namespace (optional default default)

Returns:

V1Job API object

get_kubeconfig_path() str

Returns a path of the kubeconfig with which has been initialized the class. If the class has been initialized with a kubeconfig string, a temporary file will be created and the path returned.

Returns:

a valid kubeconfig path

get_kubernetes_core_objects_count(api_version: str, objects: list[str]) dict[str, int]

Counts all the occurrences of Kinds contained in the object parameter in the CoreV1 Api

Parameters:
  • api_version – api version

  • objects – list of the kinds that must be counted

Returns:

a dictionary of Kinds and the number of objects counted

get_kubernetes_custom_objects_count(objects: list[str]) dict[str, int]

Counts all the occurrences of Kinds contained in the object parameter in the CustomObject Api

Parameters:

objects – list of Kinds that must be counted

Returns:

a dictionary of Kinds and number of objects counted

get_namespace_status(namespace_name: str) str

Get status of a given namespace

Parameters:

namespace_name – namespace name

Returns:

namespace status

get_namespaced_net_policy(namespace)

Return a list of network policy names

Parameters:

namespace – find only statefulset in given namespace

Returns:

list of network policy names

get_node(node_name: str, label_selector: str, instance_kill_count: int) list[str]

Gets active node(s)

Parameters:
  • node_name – node name

  • label_selector – filter by label

  • instance_kill_count

Returns:

active node(s)

get_node_cpu_count(node_name: str) int

Returns the number of cpus of a specified node

Parameters:

node_name – the name of the node

Returns:

the number of cpus or 0 if any exception is raised

get_node_resource_version(node: str) str

Get the resource version for the specified node

Parameters:

node – node name

Returns:

resource version

get_node_resources_info(node_name: str) NodeResources
get_nodes_infos()

Returns a list of NodeInfo objects :return: the list of NodeInfo objects

get_pod_info(name: str, namespace: str = 'default') Pod

Retrieve information about a specific pod

Parameters:
  • name – pod name

  • namespace – namespace (optional default default)

Returns:

Data class object of type Pod with the output of the above kubectl command in the given format if the pod exists. Returns None if the pod doesn’t exist

get_pod_log(name: str, namespace: str = 'default') HTTPResponse

Read the logs from a pod

Parameters:
  • name – pod name

  • namespace – namespace (optional default default)

Returns:

pod logs

get_pod_shell(pod_name: str, namespace: str, container: str | None = None) str | None

Gets the shell running on a Pod. Currently checking against /bin/bash and /bin/sh.

Parameters:
  • pod_name – pod where the command must be executed

  • namespace – namespace of the pod

  • container – container where the command must be executed (optional default None)

get_pvc_info(name: str, namespace: str) PVC

Retrieve information about a Persistent Volume Claim in a given namespace

Parameters:
  • name – name of the persistent volume claim

  • namespace – namespace (optional default default)

Returns:

A PVC data class containing the name, capacity, volume name, namespace and associated pod names of the PVC if the PVC exists Returns None if the PVC doesn’t exist

get_version() str
is_kubernetes() bool

Checks if it’s a kubernetes cluster :return: true if it’s kubernetes false if not

is_pod_running(pod_name: str, namespace: str) bool

Checks if a pod and all its containers are running

Parameters:
  • pod_name:str – the name of the pod to check

  • namespace:str – the namespace of the pod to check

Returns:

True if is running or False if not

is_pod_terminating(pod_name: str, namespace: str) bool

Checks if a pod is scheduled for deletion so it’s terminating

Parameters:
  • pod_name:str – the name of the pod to check

  • namespace:str – the namespace of the pod to check

Returns:

True if is Terminating or False if not

list_all_namespaces(label_selector: str | None = None) list[str]

List all namespaces with info

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

list of namespaces json data

list_continue_helper(func, *args, **keyword_args)

List continue helper, be able to get all objects past the request limit

Parameters:
  • func – function to call of the kubernetes cli

  • args – any set arguments for the function

  • keyword_args – key value pair arguments to pass to the function

Returns:

list of all resources after segmentation

list_killable_managedclusters(label_selector: str | None = None) list[str]

List managed clusters attached to the hub that can be killed

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

a list of managed clusters names

list_killable_nodes(label_selector: str | None = None) list[str]

List nodes in the cluster that can be killed

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

a list of node names that can be killed

list_namespaces(label_selector: str | None = None) list[str]

List all namespaces

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

list of namespaces names

list_namespaces_by_regex(regex: str) list[str]

Lists all the namespaces matching a regex

Parameters:

regex – The regular expression against which the namespaces will be compared

Returns:

a list of namespaces matching the regex

list_nodes(label_selector: str | None = None) list[str]

List nodes in the cluster

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

a list of node names

list_pods(namespace: str, label_selector: str | None = None) list[str]

List pods in the given namespace

Parameters:
  • namespace – namespace to search for pods

  • label_selector – filter by label selector (optional default None)

Returns:

a list of pod names

list_ready_nodes(label_selector: str | None = None) list[str]

Returns a list of ready nodes

Parameters:

label_selector – filter by label selector (optional default None)

Returns:

a list of node names

list_schedulable_nodes(label_selector: str | None = None) list[str]

Lists all the nodes that do not have NoSchedule or NoExecute taints and where pods can be scheduled :param label_selector: a label selector to filter the nodes :return: a list of node names

monitor_component(iteration: int, component_namespace: str) -> (<class 'bool'>, list[str])

Monitor component namespace

Parameters:
  • iteration – iteration number

  • component_namespace – namespace

Returns:

the status of the component namespace

monitor_namespace(namespace: str) -> (<class 'bool'>, list[str])

Monitor the status of the pods in the specified namespace and set the status to true or false

Parameters:

namespace – namespace

Returns:

the list of pods and the status (if one or more pods are not running False otherwise True)

monitor_nodes() -> (<class 'bool'>, list[str])

Monitor the status of the cluster nodes and set the status to true or false

Returns:

cluster status and a list of node names

monitor_pods_by_label(label_selector: str, pods_and_namespaces: list[str, str], max_timeout: int = 30, event: Event | None = None) PodsMonitorThread

Starts monitoring a list of pods identified as tuples (pod_name, namespace) filtered by label selector and collects infos about the pods recovery after a kill scenario. Returns a PodsMonitorThread that can be joined after the scenario to retrieve the PodsStatus object containing all the information collected in background during the chaos run.

Parameters:
  • label_selector – the label selector used to filter the pods to monitor (must be the same used in select_pods_by_label)

  • pods_and_namespaces – the list of pods collected by select_pods_by_label against which the changes in the pods state is monitored

  • max_timeout – the expected time the pods should take to recover. If the killed pods are replaced in this time frame, but they didn’t reach the Ready State, they will be marked as unrecovered. If during the time frame the pods are not replaced at all the error field of the PodsStatus structure will be valorized with an exception.

  • event – a threading event can be passed to interrupt the process before the timeout. Simply call set() method on the event passed to make the thread return immediately

Returns:

a PodsMonitorThread structure that can be joined in any place of the code, to collect the PodsStatus structure returned, in order to make the process run in background while a chaos scenario is performed.

monitor_pods_by_name_pattern_and_namespace_pattern(pod_name_pattern: str, namespace_pattern: str, pods_and_namespaces: list[str, str], max_timeout=30, event: Event | None = None) PodsMonitorThread

Starts monitoring a list of pods identified as tuples (pod_name, namespace) filtered by a pod name regex pattern and a namespace regex pattern, and collects infos about the pods recovery after a kill scenario. Returns a PodsMonitorThread that can be joined after the scenario to retrieve the PodsStatus object containing all the information collected in background during the chaos run.

Parameters:
  • pod_name_pattern – a regex representing the pod name pattern used to filter the pods to be monitored (must be the same used in select_pods_by_name_pattern_and_namespace_pattern)

  • namespace_pattern – a regex representing the namespace pattern used to filter the pods to be monitored (must be the same used in select_pods_by_name_pattern_and_namespace_pattern)

  • pods_and_namespaces – the list of pods collected by select_pods_by_name_pattern_and_namespace_pattern against which the changes in the pods state is monitored

  • max_timeout – the expected time the pods should take to recover. If the killed pods are replaced in this time frame, but they didn’t reach the Ready State, they will be marked as unrecovered. If during the time frame the pods are not replaced at all the error field of the PodsStatus structure will be valorized with an exception.

  • event – a threading event can be passed to interrupt the process before the timeout. Simply call set() method on the event passed to make the thread return immediately

Returns:

a PodsMonitorThread structure that can be joined in any place of the code, to collect the PodsStatus structure returned, in order to make the process run in background while a chaos scenario is performed.

monitor_pods_by_namespace_pattern_and_label(namespace_pattern: str, label_selector: str, pods_and_namespaces: list[str, str], max_timeout=30, event: Event | None = None) PodsMonitorThread

Starts monitoring a list of pods identified as tuples (pod_name, namespace) filtered by a namespace regex pattern and a pod label selector, and collects infos about the pods recovery after a kill scenario. Returns a PodsMonitorThread that can be joined after the scenario to retrieve the PodsStatus object containing all the information collected in background during the chaos run.

Parameters:
  • label_selector – the label selector used to filter the pods to monitor (must be the same used in select_pods_by_label)

  • namespace_pattern – a regex representing the namespace pattern used to filter the pods to be monitored (must be the same used in select_pods_by_name_pattern_and_namespace_pattern)

  • pods_and_namespaces – the list of pods collected by select_pods_by_name_pattern_and_namespace_pattern against which the changes in the pods state is monitored

  • max_timeout – the expected time the pods should take to recover. If the killed pods are replaced in this time frame, but they didn’t reach the Ready State, they will be marked as unrecovered. If during the time frame the pods are not replaced at all the error field of the PodsStatus structure will be valorized with an exception.

  • event – a threading event can be passed to interrupt the process before the timeout. Simply call set() method on the event passed to make the thread return immediately

Returns:

a PodsMonitorThread structure that can be joined in any place of the code, to collect the PodsStatus structure returned, in order to make the process run in background while a chaos scenario is performed.

property net_cli: NetworkingV1Api
parse_events_from_file(events_filename: str) list[ClusterEvent] | None
path_exists_in_pod(pod_name: str, container_name: str, namespace: str, path: str) bool
read_pod(name: str, namespace: str = 'default') V1Pod

Read a pod definition

Parameters:
  • name – pod name

  • namespace – namespace (optional default default)

Returns:

V1Pod definition of the pod

replace_service_selector(new_selectors: list[str], service_name: str, namespace: str) dict[Any] | None

Replaces a service selector with one or more new selectors Patching the target service

Parameters:
  • new_selectors – a list of selectors in the format “key=value”

  • service_name – the service name that needs to be patched

  • namespace – the namespace of the service

Returns:

the original service spec (useful to restore it after the scenario) returns None if self.api_client hasn’t been initialized

request_chunk_size: int = 250
select_pods_by_label(label_selector: str) list[str, str]

Selects the pods identified by a label_selector

Parameters:
  • label_selector – a label selector string in the format “key=value”

  • max_timeout – the maximum time in seconds to wait before considering the pod “not recovered” after the Chaos

Returns:

a list of pod_name and namespace tuples

select_pods_by_name_pattern_and_namespace_pattern(pod_name_pattern: str, namespace_pattern: str) list[str, str]

Selects the pods identified by a namespace_pattern and a pod_name pattern.

Parameters:
  • pod_name_pattern – a pod_name pattern to match

  • namespace_pattern – a namespace pattern to match

  • max_timeout – the maximum time in seconds to wait before considering the pod “not recovered” after the Chaos

Returns:

a list of pod_name and namespace tuples

select_pods_by_namespace_pattern_and_label(namespace_pattern: str, label_selector: str) list[str, str]

Selects the pods identified by a label_selector and a namespace pattern

Parameters:
  • namespace_pattern – a namespace pattern to match

  • label_selector – a label selector string in the format “key=value”

  • max_timeout – the maximum time in seconds to wait before considering the pod “not recovered” after the Chaos

Returns:

a list of pod_name and namespace tuples

select_service_by_label(namespace: str, label_selector: str) list[str]

Selects all the services marked by a label in the format key=value deployed on a namespace

Parameters:
  • namespace – namespace where the service are searched

  • label_selector – label selector in the format key=value

Returns:

the list of services matching the criteria

service_exists(service_name: str, namespace: str) bool

Checks wheter a kubernetes Service exist or not :param service_name: the name of the service to check :param namespace: the namespace where the service should exist :return: True if the service exists, False if not

undeploy_service_hijacking(service_infos: ServiceHijacking)

Undeploys the resource created for the ServiceHijacking Scenario

Parameters:

service_infos – the structure returned by the deploy_service_hijacking method

property version_client: VersionApi
watch_managedcluster_status(managedcluster: str, status: str, timeout: int) bool

Watch for a specific managedcluster status

Parameters:
  • managedcluster – managedcluster name

  • status – status of the resource

  • timeout – timeout

Returns:

boolean value indicating if the timeout occurred

watch_node_status(node: str, status: str, timeout: int, affected_node: AffectedNode)

Watch for a specific node status

Parameters:
  • node – node name

  • status – status of the resource

  • timeout – timeout

  • resource_version – version of the resource

watch_resource: Watch = None