Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Jul 12, 2023
1 parent 5e7dacf commit ab4e96b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/service/k8s/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (s *svc) ListEvents(ctx context.Context, clientset, cluster, namespace, obj
}

// For ease of use, we can sort the events in reverse chronological order
func sortEventsByTime(events []*k8sapiv1.Event) {
func sortEventsByLastTime(events []*k8sapiv1.Event) {
sort.Slice(events, func(i, j int) bool {
return events[i].CreationTimeMillis > events[j].CreationTimeMillis
return events[i].LastTimestampMillis > events[j].LastTimestampMillis
})
}

Expand Down Expand Up @@ -123,7 +123,8 @@ func (s *svc) ListNamespaceEvents(ctx context.Context, clientset, cluster, names
for _, f := range fs {
eventList, err := cs.CoreV1().Events(cs.Namespace()).List(ctx, metav1.ListOptions{FieldSelector: f})
if err != nil {
return nil, err
// swallow any errors since we don't support partial errors right now, and if there are no events a 404 is returned
continue
}
totalEventList = append(totalEventList, eventList.Items...)
}
Expand All @@ -132,12 +133,13 @@ func (s *svc) ListNamespaceEvents(ctx context.Context, clientset, cluster, names
// ProtoForEvent()
var events []*k8sapiv1.Event
for _, ev := range totalEventList {
// scopelint
ev := ev
events = append(events, ProtoForEvent(cs.Cluster(), &ev))
}
// Sort in reverse chronological order (by CreationTimeMillis),
// Sort in reverse chronological order (by LastTimestampMillis),
// this is needed because we might have multiple types of events
sortEventsByTime(events)
sortEventsByLastTime(events)

return events, nil
}
Expand Down

0 comments on commit ab4e96b

Please sign in to comment.