Finish switching to utilruntime.HandleErrorWithContext

Signed-off-by: Mike Spreitzer <mspreitz@us.ibm.com>

Kubernetes-commit: fdbf0bbb2d85c3095fdc9625620648fb861fce6a
This commit is contained in:
Mike Spreitzer 2024-07-03 10:36:51 -04:00 committed by Kubernetes Publisher
parent 6e60f3495c
commit cd970a4c9d

View File

@ -225,7 +225,7 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool {
// there was a failure so be sure to report it. This method allows for // there was a failure so be sure to report it. This method allows for
// pluggable error handling which can be used for things like // pluggable error handling which can be used for things like
// cluster-monitoring. // cluster-monitoring.
utilruntime.HandleErrorWithContext(ctx, err, "error syncing; requeuing", "objectReference", objRef) utilruntime.HandleErrorWithContext(ctx, err, "Error syncing; requeuing for later retry", "objectReference", objRef)
// since we failed, we should requeue the item to work on later. This // since we failed, we should requeue the item to work on later. This
// method will add a backoff to avoid hotlooping on particular items // method will add a backoff to avoid hotlooping on particular items
// (they're probably still not going to work right away) and overall // (they're probably still not going to work right away) and overall
@ -247,7 +247,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
// The Foo resource may no longer exist, in which case we stop // The Foo resource may no longer exist, in which case we stop
// processing. // processing.
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
utilruntime.HandleError(fmt.Errorf("foo '%#v' in work queue no longer exists", objectRef)) utilruntime.HandleErrorWithContext(ctx, err, "Foo referenced by item in work queue no longer exists", "objectReference", objectRef)
return nil return nil
} }
@ -259,7 +259,7 @@ func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName
// We choose to absorb the error here as the worker would requeue the // We choose to absorb the error here as the worker would requeue the
// resource otherwise. Instead, the next time the resource is updated // resource otherwise. Instead, the next time the resource is updated
// the resource will be queued again. // the resource will be queued again.
utilruntime.HandleError(fmt.Errorf("%#v: deployment name must be specified", objectRef)) utilruntime.HandleErrorWithContext(ctx, nil, "Deployment name missing from object reference", "objectReference", objectRef)
return nil return nil
} }
@ -349,12 +349,16 @@ func (c *Controller) handleObject(obj interface{}) {
if object, ok = obj.(metav1.Object); !ok { if object, ok = obj.(metav1.Object); !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("error decoding object, invalid type")) // If the object value is not too big and does not contain sensitive information then
// it may be useful to include it.
utilruntime.HandleErrorWithContext(context.Background(), nil, "Error decoding object, invalid type", "type", fmt.Sprintf("%T", obj))
return return
} }
object, ok = tombstone.Obj.(metav1.Object) object, ok = tombstone.Obj.(metav1.Object)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) // If the object value is not too big and does not contain sensitive information then
// it may be useful to include it.
utilruntime.HandleErrorWithContext(context.Background(), nil, "Error decoding object tombstone, invalid type", "type", fmt.Sprintf("%T", tombstone.Obj))
return return
} }
logger.V(4).Info("Recovered deleted object", "resourceName", object.GetName()) logger.V(4).Info("Recovered deleted object", "resourceName", object.GetName())