Skip to content

Commit a080057

Browse files
authored
Merge pull request kubernetes#125154 from alvaroaleman/rename
Sample Controller: Use one variable for key throughout
2 parents 7e88a33 + 6e2e7f7 commit a080057

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

staging/src/k8s.io/sample-controller/controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,27 +204,27 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool {
204204
}
205205

206206
// We wrap this block in a func so we can defer c.workqueue.Done.
207-
err := func(key string) error {
207+
err := func() error {
208208
// We call Done here so the workqueue knows we have finished
209209
// processing this item. We also must remember to call Forget if we
210210
// do not want this work item being re-queued. For example, we do
211211
// not call Forget if a transient error occurs, instead the item is
212212
// put back on the workqueue and attempted again after a back-off
213213
// period.
214-
defer c.workqueue.Done(key)
214+
defer c.workqueue.Done(obj)
215215
// Run the syncHandler, passing it the namespace/name string of the
216216
// Foo resource to be synced.
217-
if err := c.syncHandler(ctx, key); err != nil {
217+
if err := c.syncHandler(ctx, obj); err != nil {
218218
// Put the item back on the workqueue to handle any transient errors.
219-
c.workqueue.AddRateLimited(key)
220-
return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error())
219+
c.workqueue.AddRateLimited(obj)
220+
return fmt.Errorf("error syncing '%s': %s, requeuing", obj, err.Error())
221221
}
222222
// Finally, if no error occurs we Forget this item so it does not
223223
// get queued again until another change happens.
224224
c.workqueue.Forget(obj)
225-
logger.Info("Successfully synced", "resourceName", key)
225+
logger.Info("Successfully synced", "resourceName", obj)
226226
return nil
227-
}(obj)
227+
}()
228228

229229
if err != nil {
230230
utilruntime.HandleError(err)

0 commit comments

Comments
 (0)