MCPcopy
hub / github.com/kubernetes/client-go / recordEvent

Function recordEvent

tools/record/event.go:211–251  ·  view source on GitHub ↗

recordEvent attempts to write event to a sink. It returns true if the event was successfully recorded or discarded, false if it should be retried. If updateExistingEvent is false, it creates a new event, otherwise it updates existing event.

(sink EventSink, event *v1.Event, patch []byte, updateExistingEvent bool, eventCorrelator *EventCorrelator)

Source from the content-addressed store, hash-verified

209// If updateExistingEvent is false, it creates a new event, otherwise it updates
210// existing event.
211func recordEvent(sink EventSink, event *v1.Event, patch []byte, updateExistingEvent bool, eventCorrelator *EventCorrelator) bool {
212 var newEvent *v1.Event
213 var err error
214 if updateExistingEvent {
215 newEvent, err = sink.Patch(event, patch)
216 }
217 // Update can fail because the event may have been removed and it no longer exists.
218 if !updateExistingEvent || (updateExistingEvent && util.IsKeyNotFoundError(err)) {
219 // Making sure that ResourceVersion is empty on creation
220 event.ResourceVersion = ""
221 newEvent, err = sink.Create(event)
222 }
223 if err == nil {
224 // we need to update our event correlator with the server returned state to handle name/resourceversion
225 eventCorrelator.UpdateState(newEvent)
226 return true
227 }
228
229 // If we can't contact the server, then hold everything while we keep trying.
230 // Otherwise, something about the event is malformed and we should abandon it.
231 switch err.(type) {
232 case *restclient.RequestConstructionError:
233 // We will construct the request the same next time, so don't keep trying.
234 klog.Errorf("Unable to construct event '%#v': '%v' (will not retry!)", event, err)
235 return true
236 case *errors.StatusError:
237 if errors.IsAlreadyExists(err) {
238 klog.V(5).Infof("Server rejected event '%#v': '%v' (will not retry!)", event, err)
239 } else {
240 klog.Errorf("Server rejected event '%#v': '%v' (will not retry!)", event, err)
241 }
242 return true
243 case *errors.UnexpectedObjectError:
244 // We don't expect this; it implies the server's response didn't match a
245 // known pattern. Go ahead and retry.
246 default:
247 // This case includes actual http transport errors. Go ahead and retry.
248 }
249 klog.Errorf("Unable to write event: '%v' (may retry after sleeping)", err)
250 return false
251}
252
253// StartLogging starts sending events received from this EventBroadcaster to the given logging function.
254// The return value can be ignored or used to stop recording, if desired.

Callers 1

recordToSinkFunction · 0.70

Calls 5

IsKeyNotFoundErrorFunction · 0.92
UpdateStateMethod · 0.80
PatchMethod · 0.65
CreateMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected