Skip to content
Merged
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
16 changes: 11 additions & 5 deletions playbooks/robusta_playbooks/k8s_resource_enrichments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
)
)

Expand Down
Loading