Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add promtail event filter #972

Merged
merged 1 commit into from
Sep 6, 2023
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
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