Skip to content

Commit df101f7

Browse files
committed
Refactor updateContentInInformerCache
The name suggests it only updates the cache, but it also resyncs the object. There is just only one caller, so remove the function completely.
1 parent 9cf863f commit df101f7

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

pkg/sidecar-controller/snapshot_controller_base.go

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,27 @@ func (ctrl *csiSnapshotSideCarController) syncContentByKey(key string) (requeue
260260
// been add/update/sync
261261
if err == nil {
262262
if ctrl.isDriverMatch(content) {
263-
requeue, err = ctrl.updateContentInInformerCache(content)
264-
}
265-
if err != nil {
266-
// If error occurs we add this item back to the queue
267-
return true, err
263+
// Store the new content version in the cache and do not process it if this is
264+
// an old version.
265+
new, err := ctrl.storeContentUpdate(content)
266+
if err != nil {
267+
klog.Errorf("%v", err)
268+
}
269+
if !new {
270+
return false, nil
271+
}
272+
requeue, err = ctrl.syncContent(content)
273+
if err != nil {
274+
if errors.IsConflict(err) {
275+
// Version conflict error happens quite often and the controller
276+
// recovers from it easily.
277+
klog.V(3).Infof("could not sync content %q: %+v", content.Name, err)
278+
} else {
279+
klog.Errorf("could not sync content %q: %+v", content.Name, err)
280+
}
281+
// If error occurs we add this item back to the queue
282+
return true, err
283+
}
268284
}
269285
return requeue, nil
270286
}
@@ -339,32 +355,6 @@ func (ctrl *csiSnapshotSideCarController) isDriverMatch(object interface{}) bool
339355
return false
340356
}
341357

342-
// updateContentInInformerCache runs in worker thread and handles "content added",
343-
// "content updated" and "periodic sync" events.
344-
func (ctrl *csiSnapshotSideCarController) updateContentInInformerCache(content *crdv1.VolumeSnapshotContent) (requeue bool, err error) {
345-
// Store the new content version in the cache and do not process it if this is
346-
// an old version.
347-
new, err := ctrl.storeContentUpdate(content)
348-
if err != nil {
349-
klog.Errorf("%v", err)
350-
}
351-
if !new {
352-
return false, nil
353-
}
354-
requeue, err = ctrl.syncContent(content)
355-
if err != nil {
356-
if errors.IsConflict(err) {
357-
// Version conflict error happens quite often and the controller
358-
// recovers from it easily.
359-
klog.V(3).Infof("could not sync content %q: %+v", content.Name, err)
360-
} else {
361-
klog.Errorf("could not sync content %q: %+v", content.Name, err)
362-
}
363-
return requeue, err
364-
}
365-
return requeue, nil
366-
}
367-
368358
// deleteContent runs in worker thread and handles "content deleted" event.
369359
func (ctrl *csiSnapshotSideCarController) deleteContentInCacheStore(content *crdv1.VolumeSnapshotContent) {
370360
_ = ctrl.contentStore.Delete(content)

0 commit comments

Comments
 (0)