From 6e2e7f7c26d0c4908180180a85a53d2ca408f3b0 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Mon, 27 May 2024 21:29:48 -0400 Subject: [PATCH] Sample Controller: Use one variable for key throughout After changing it to use a typed workqueue, the differentiation between the key we get from the workqueue and they key we use down the line is no longer useful as they are the same, so use one variable for it throughout. --- staging/src/k8s.io/sample-controller/controller.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/staging/src/k8s.io/sample-controller/controller.go b/staging/src/k8s.io/sample-controller/controller.go index f2e66c301ab..efbd391e66c 100644 --- a/staging/src/k8s.io/sample-controller/controller.go +++ b/staging/src/k8s.io/sample-controller/controller.go @@ -204,27 +204,27 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool { } // We wrap this block in a func so we can defer c.workqueue.Done. - err := func(key string) error { + err := func() error { // We call Done here so the workqueue knows we have finished // processing this item. We also must remember to call Forget if we // do not want this work item being re-queued. For example, we do // not call Forget if a transient error occurs, instead the item is // put back on the workqueue and attempted again after a back-off // period. - defer c.workqueue.Done(key) + defer c.workqueue.Done(obj) // Run the syncHandler, passing it the namespace/name string of the // Foo resource to be synced. - if err := c.syncHandler(ctx, key); err != nil { + if err := c.syncHandler(ctx, obj); err != nil { // Put the item back on the workqueue to handle any transient errors. - c.workqueue.AddRateLimited(key) - return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error()) + c.workqueue.AddRateLimited(obj) + return fmt.Errorf("error syncing '%s': %s, requeuing", obj, err.Error()) } // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens. c.workqueue.Forget(obj) - logger.Info("Successfully synced", "resourceName", key) + logger.Info("Successfully synced", "resourceName", obj) return nil - }(obj) + }() if err != nil { utilruntime.HandleError(err)