Skip to content

Commit

Permalink
Pass along container status message (robusta-dev#1166)
Browse files Browse the repository at this point in the history
Support more error diagnostics for containers and pods
  • Loading branch information
Robert Szefler authored and pavangudiwada committed May 30, 2024
1 parent 1aacf8e commit e2f9bb5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion playbooks/robusta_playbooks/k8s_resource_enrichments.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RelatedContainer(BaseModel):
status: Optional[str] = None
created: Optional[str] = None
ports: List[Any] = []
statusMessage: Optional[str] = None
statusReason: Optional[str] = None


class RelatedPod(BaseModel):
Expand All @@ -64,6 +66,7 @@ class RelatedPod(BaseModel):
addresses: str
containers: List[RelatedContainer]
status: Optional[str] = None
statusReason: Optional[str] = None


supported_resources = ["Deployment", "DaemonSet", "ReplicaSet", "Pod", "StatefulSet", "Job", "Node"]
Expand All @@ -87,6 +90,7 @@ def to_pod_row(pod: Pod, cluster_name: str) -> List:
addresses,
len(pod.spec.containers),
pod.status.phase,
pod.status.reason,
]


Expand All @@ -95,7 +99,6 @@ def get_related_pods(resource) -> list[Pod]:
if kind not in supported_resources:
raise ActionException(ErrorCodes.RESOURCE_NOT_SUPPORTED, f"Related pods is not supported for resource {kind}")

pods = []
if kind == "Job":
job_pods = get_job_all_pods(resource)
pods = job_pods if job_pods else []
Expand Down Expand Up @@ -128,6 +131,7 @@ def to_pod_obj(pod: Pod, cluster: str) -> RelatedPod:
addresses=addresses,
containers=get_pod_containers(pod),
status=pod.status.phase,
statusReason=pod.status.reason,
)


Expand Down Expand Up @@ -156,6 +160,8 @@ def get_pod_containers(pod: Pod) -> List[RelatedContainer]:
memoryRequest=requests.memory,
restarts=getattr(containerStatus, "restartCount", 0),
status=stateStr,
statusMessage=getattr(state, "messsage", None) if state else None,
statusReason=getattr(state, "reason", None) if state else None,
created=getattr(state, "startedAt", None),
ports=[port.to_dict() for port in container.ports] if container.ports else [],
)
Expand Down Expand Up @@ -197,6 +203,7 @@ def related_pods(event: KubernetesResourceEvent, params: RelatedPodParams):
"addresses",
"containers",
"status",
"status reason",
],
rows=rows,
)
Expand Down

0 comments on commit e2f9bb5

Please sign in to comment.