Skip to content

Commit

Permalink
fixed taints serialization issue
Browse files Browse the repository at this point in the history
check one taints

fixed test
  • Loading branch information
tsebastiani authored and chaitanyaenr committed Dec 13, 2023
1 parent b2735e4 commit eebdb53
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/krkn_lib/k8s/krkn_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions src/krkn_lib/models/telemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
"""
Expand Down
14 changes: 10 additions & 4 deletions src/krkn_lib/tests/test_krkn_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion src/krkn_lib/tests/test_krkn_telemetry_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eebdb53

Please sign in to comment.