Merge pull request #125190 from pohly/record-event-panic

client-go record: avoid panic when watch creation failed
This commit is contained in:
Kubernetes Prow Robot 2024-05-29 06:20:33 -07:00 committed by GitHub
commit ea0ab06b69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -395,7 +395,11 @@ func (e *eventBroadcasterImpl) StartStructuredLogging(verbosity klog.Level) watc
func (e *eventBroadcasterImpl) StartEventWatcher(eventHandler func(*v1.Event)) watch.Interface {
watcher, err := e.Watch()
if err != nil {
// This function traditionally returns no error even though it can fail.
// Instead, it logs the error and returns an empty watch. The empty
// watch ensures that callers don't crash when calling Stop.
klog.FromContext(e.cancelationCtx).Error(err, "Unable start event watcher (will not retry!)")
return watch.NewEmptyWatch()
}
go func() {
defer utilruntime.HandleCrash()