From 0ffca221e82ba63180869a27e34e1cd6a43a1355 Mon Sep 17 00:00:00 2001 From: "avi@robusta.dev" Date: Sun, 1 Dec 2024 14:52:17 +0200 Subject: [PATCH] fixed missing fields in the related pods due to using hikaru in the past and moving to kubernetes python api --- .../k8s_resource_enrichments.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/playbooks/robusta_playbooks/k8s_resource_enrichments.py b/playbooks/robusta_playbooks/k8s_resource_enrichments.py index 27387ea34..37e3f9d1e 100644 --- a/playbooks/robusta_playbooks/k8s_resource_enrichments.py +++ b/playbooks/robusta_playbooks/k8s_resource_enrichments.py @@ -197,6 +197,12 @@ def to_pod_obj(pod: V1Pod, cluster: str, include_raw_data: bool = False) -> Rela ) +def get_attr_str(obj, attr) -> Optional[str]: + ret_attr = getattr(obj, attr, None) + # str(None) = "None" + return str(ret_attr) if ret_attr else None + + def get_pod_containers(pod: V1Pod) -> List[RelatedContainer]: containers: List[RelatedContainer] = [] spec: V1PodSpec = pod.spec @@ -224,16 +230,16 @@ def get_pod_containers(pod: V1Pod) -> List[RelatedContainer]: cpuRequest=requests.cpu, memoryLimit=limits.memory, memoryRequest=requests.memory, - restarts=getattr(containerStatus, "restartCount", 0), + restarts=getattr(containerStatus, "restart_count", 0), status=stateStr, statusMessage=getattr(state, "message", None) if state else None, statusReason=getattr(state, "reason", None) if state else None, - created=getattr(state, "startedAt", None), + created=get_attr_str(state, "started_at"), ports=[port.to_dict() for port in container.ports] if container.ports else [], terminatedReason=getattr(terminated_state, "reason", None), - terminatedExitCode=getattr(terminated_state, "exitCode", None), - terminatedStarted=getattr(terminated_state, "startedAt", None), - terminatedFinished=getattr(terminated_state, "finishedAt", None), + terminatedExitCode=getattr(terminated_state, "exit_code", None), + terminatedStarted=get_attr_str(terminated_state, "started_at"), + terminatedFinished=get_attr_str(terminated_state, "finished_at"), ) )