Harden logstream against non-object events (#1984)

This commit is contained in:
Markus Thömmes 2021-01-12 15:39:30 +01:00 committed by GitHub
parent 93874f0ea7
commit acbf2af596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -102,7 +102,13 @@ func (s *namespaceSource) watchPods() error {
if ev.Object == nil || reflect.ValueOf(ev.Object).IsNil() {
continue
}
p := ev.Object.(*corev1.Pod)
p, ok := ev.Object.(*corev1.Pod)
if !ok {
// The Watch interface can return errors via the channel as *metav1.Status.
// Log those to get notified that loglines might be missing but don't crash.
s.handleGenericLine([]byte(fmt.Sprintf("unexpected event: %v", p)), "no-pod", "no-container")
continue
}
switch ev.Type {
case watch.Deleted:
watchedPods.Delete(p.Name)