Skip to content

Commit

Permalink
feat: Add promtail event filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik003 committed Sep 5, 2023
1 parent 795684d commit 92f6eee
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions backend/capellacollab/sessions/operators/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit 92f6eee

Please sign in to comment.