@@ -287,7 +287,7 @@ func (m *FakeNodeHandler) Watch(_ context.Context, opts metav1.ListOptions) (wat
287
287
}
288
288
289
289
// Patch patches a Node in the fake store.
290
- func (m * FakeNodeHandler ) Patch (_ context.Context , name string , pt types.PatchType , data []byte , _ metav1.PatchOptions , subresources ... string ) (* v1.Node , error ) {
290
+ func (m * FakeNodeHandler ) Patch (ctx context.Context , name string , pt types.PatchType , data []byte , _ metav1.PatchOptions , subresources ... string ) (* v1.Node , error ) {
291
291
m .lock .Lock ()
292
292
defer func () {
293
293
m .RequestCount ++
@@ -312,12 +312,12 @@ func (m *FakeNodeHandler) Patch(_ context.Context, name string, pt types.PatchTy
312
312
313
313
originalObjJS , err := json .Marshal (nodeCopy )
314
314
if err != nil {
315
- klog .Errorf ( "Failed to marshal %v" , nodeCopy )
315
+ klog .FromContext ( ctx ). Error ( nil , "Failed to marshal" , "node" , klog . KObj ( & nodeCopy ) )
316
316
return nil , nil
317
317
}
318
318
var originalNode v1.Node
319
319
if err = json .Unmarshal (originalObjJS , & originalNode ); err != nil {
320
- klog .Errorf ( "Failed to unmarshal original object: %v" , err )
320
+ klog .FromContext ( ctx ). Error ( err , "Failed to unmarshal original object" )
321
321
return nil , nil
322
322
}
323
323
@@ -326,31 +326,31 @@ func (m *FakeNodeHandler) Patch(_ context.Context, name string, pt types.PatchTy
326
326
case types .JSONPatchType :
327
327
patchObj , err := jsonpatch .DecodePatch (data )
328
328
if err != nil {
329
- klog .Error ( err .Error () )
329
+ klog .FromContext ( ctx ) .Error (err , "" )
330
330
return nil , nil
331
331
}
332
332
if patchedObjJS , err = patchObj .Apply (originalObjJS ); err != nil {
333
- klog .Error ( err .Error () )
333
+ klog .FromContext ( ctx ) .Error (err , "" )
334
334
return nil , nil
335
335
}
336
336
case types .MergePatchType :
337
337
if patchedObjJS , err = jsonpatch .MergePatch (originalObjJS , data ); err != nil {
338
- klog .Error ( err .Error () )
338
+ klog .FromContext ( ctx ) .Error (err , "" )
339
339
return nil , nil
340
340
}
341
341
case types .StrategicMergePatchType :
342
342
if patchedObjJS , err = strategicpatch .StrategicMergePatch (originalObjJS , data , originalNode ); err != nil {
343
- klog .Error ( err .Error () )
343
+ klog .FromContext ( ctx ) .Error (err , "" )
344
344
return nil , nil
345
345
}
346
346
default :
347
- klog .Errorf ( "unknown Content-Type header for patch: %v " , pt )
347
+ klog .FromContext ( ctx ). Error ( nil , "Unknown Content-Type header" , " patch" , pt )
348
348
return nil , nil
349
349
}
350
350
351
351
var updatedNode v1.Node
352
352
if err = json .Unmarshal (patchedObjJS , & updatedNode ); err != nil {
353
- klog .Errorf ( "Failed to unmarshal patched object: %v" , err )
353
+ klog .FromContext ( ctx ). Error ( err , "Failed to unmarshal patched object" )
354
354
return nil , nil
355
355
}
356
356
@@ -422,9 +422,10 @@ func (f *FakeRecorder) AnnotatedEventf(obj runtime.Object, annotations map[strin
422
422
func (f * FakeRecorder ) generateEvent (obj runtime.Object , timestamp metav1.Time , eventtype , reason , message string ) {
423
423
f .Lock ()
424
424
defer f .Unlock ()
425
+ ctx := context .TODO ()
425
426
ref , err := ref .GetReference (legacyscheme .Scheme , obj )
426
427
if err != nil {
427
- klog .Errorf ( "Encountered error while getting reference: %v" , err )
428
+ klog .FromContext ( ctx ). Error ( err , "Encountered error while getting reference" )
428
429
return
429
430
}
430
431
event := f .makeEvent (ref , eventtype , reason , message )
0 commit comments