diff --git a/src/krkn_lib/k8s/krkn_kubernetes.py b/src/krkn_lib/k8s/krkn_kubernetes.py index 920d481f..4295c814 100644 --- a/src/krkn_lib/k8s/krkn_kubernetes.py +++ b/src/krkn_lib/k8s/krkn_kubernetes.py @@ -29,7 +29,7 @@ Volume, VolumeMount, ) -from krkn_lib.models.telemetry import NodeInfo +from krkn_lib.models.telemetry import NodeInfo, Taint from krkn_lib.utils import filter_dictionary from krkn_lib.utils.safe_logger import SafeLogger @@ -1814,7 +1814,15 @@ def get_nodes_infos(self) -> list[NodeInfo]: ) for node_resp in resp: for node in node_resp.items: - node_info = NodeInfo(taint=node.spec.taints) + node_info = NodeInfo() + if node.spec.taints is not None: + for taint in node.spec.taints: + taint = Taint( + effect=taint.effect, + key=taint.key, + value=taint.value, + ) + node_info.taints.append(taint) if instance_type_label in node.metadata.labels.keys(): node_info.instance_type = node.metadata.labels[ instance_type_label diff --git a/src/krkn_lib/models/telemetry/models.py b/src/krkn_lib/models/telemetry/models.py index 64413a99..5793f739 100644 --- a/src/krkn_lib/models/telemetry/models.py +++ b/src/krkn_lib/models/telemetry/models.py @@ -71,14 +71,40 @@ def __init__(self, json_object: any = None): self.parameters = {} +@dataclass(order=False) +class Taint: + """ + Cluster Node Taint details + """ + + effect: str = "" + """ + effect of the taint in the node + """ + key: str = "" + """ + Taint key + """ + value: str = "" + """ + Taint Value + """ + + @dataclass(order=False) class NodeInfo: """ Cluster node telemetry informations """ - taint: dict + + def __init__(self): + self.taints = list[Taint]() + + taints: list[Taint] + + """ + Taints on the node """ - Taint on the node""" name: str = "" """ diff --git a/src/krkn_lib/tests/test_krkn_kubernetes.py b/src/krkn_lib/tests/test_krkn_kubernetes.py index e9cf5cdd..2c1d6237 100644 --- a/src/krkn_lib/tests/test_krkn_kubernetes.py +++ b/src/krkn_lib/tests/test_krkn_kubernetes.py @@ -13,6 +13,7 @@ from kubernetes.client import ApiException from jinja2 import Environment, FileSystemLoader from krkn_lib.k8s import ApiRequestException, KrknKubernetes +from krkn_lib.models.telemetry import ChaosRunTelemetry from krkn_lib.tests import BaseTest from tzlocal import get_localzone @@ -72,21 +73,20 @@ def test_get_kubeconfig_path(self): test_kubeconfig = test.read() self.assertEqual(test_kubeconfig, kubeconfig_str) - def test_list_all_namespaces(self): # test list all namespaces result = self.lib_k8s.list_all_namespaces() result_count = 0 for r in result: for item in r.items: - result_count+=1 - print('result type' + str((result_count))) + result_count += 1 + print("result type" + str((result_count))) self.assertTrue(result_count > 1) # test filter by label result = self.lib_k8s.list_all_namespaces( "kubernetes.io/metadata.name=default" ) - + self.assertTrue(len(result) == 1) namespace_names = [] for r in result: @@ -672,6 +672,7 @@ def test_get_kubernetes_custom_objects_count(self): self.assertTrue("Ingress" in objs.keys()) def test_get_nodes_infos(self): + telemetry = ChaosRunTelemetry() nodes = self.lib_k8s.get_nodes_infos() for node in nodes: self.assertTrue(node.node_type) @@ -680,6 +681,11 @@ def test_get_nodes_infos(self): self.assertTrue(node.os_version) self.assertTrue(node.kernel_version) self.assertTrue(node.kubelet_version) + telemetry.node_infos.append(node) + try: + _ = telemetry.to_json() + except Exception: + self.fail("failed to deserialize NodeInfo") def test_download_folder_from_pod_as_archive(self): workdir_basepath = os.getenv("TEST_WORKDIR") diff --git a/src/krkn_lib/tests/test_krkn_telemetry_models.py b/src/krkn_lib/tests/test_krkn_telemetry_models.py index 1f264aef..dc93acc4 100644 --- a/src/krkn_lib/tests/test_krkn_telemetry_models.py +++ b/src/krkn_lib/tests/test_krkn_telemetry_models.py @@ -86,7 +86,15 @@ def test_chaos_run_telemetry(self): "scenario": "test", "exitStatus": 0, "parametersBase64": "cHJvcGVydHk6CiAgICB1bml0OiB1bml0CiAgICB0ZXN0OiB0ZXN0" - }] + }], + "node_infos": [{ + "name": "test_node", + "taints": [{ + "key": "key", + "value": "value", + "effect": "NoSchedule" + }] + }] } """ # NOQA