diff --git a/backend/capellacollab/sessions/operators/k8s.py b/backend/capellacollab/sessions/operators/k8s.py index 4bd3ad1d8..3703351f1 100644 --- a/backend/capellacollab/sessions/operators/k8s.py +++ b/backend/capellacollab/sessions/operators/k8s.py @@ -231,13 +231,16 @@ def _get_pod_state(self, label_selector: str): log.debug("Received k8s pod: %s", pod_name) log.debug("Fetching k8s events for pod: %s", pod_name) - events = self.v1_core.list_namespaced_event( + events: list[ + client.CoreV1Event + ] = self.v1_core.list_namespaced_event( namespace=namespace, field_selector=f"involvedObject.name={pod_name}", - ) + ).items - if events.items: - return events.items[-1].reason + events = list(filter(self._is_non_promtail_event, events)) + if events: + return events[-1].reason # Fallback if no event is available return pod.status.phase @@ -250,6 +253,12 @@ def _get_pod_state(self, label_selector: str): return "unknown" + def _is_non_promtail_event(self, event: client.CoreV1Event) -> bool: + if not (event.involved_object and event.involved_object.field_path): + return True + + return "spec.containers{promtail}" != event.involved_object.field_path + def get_session_logs(self, _id: str) -> str: return self.v1_core.read_namespaced_pod_log( name=self._get_pod_name(_id),