Skip to content

Commit ced70e3

Browse files
committed
Add --poll-snapshot-period for periodic readiness requeue check when creating a VolumeSnapshotContent
1 parent 59d7297 commit ced70e3

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

Diff for: cmd/csi-snapshotter/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var (
9393
metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
9494
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080`). The default is empty string, which means the server is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
9595
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
96+
pollSnapshotPeriod = flag.Duration("poll-snapshot-period", 10*time.Second, "Poll interval to check if a snapshot is ready. Default is 10 seconds.")
9697
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed volume snapshot creation or deletion. It doubles with each failure, up to retry-interval-max. Default is 1 second.")
9798
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
9899
enableNodeDeployment = flag.Bool("node-deployment", false, "Enables deploying the sidecar controller together with a CSI driver on nodes to manage snapshots for node-local volumes.")
@@ -297,6 +298,7 @@ func main() {
297298
snapshotContentfactory.Groupsnapshot().V1beta1().VolumeGroupSnapshotContents(),
298299
snapshotContentfactory.Groupsnapshot().V1beta1().VolumeGroupSnapshotClasses(),
299300
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax),
301+
*pollSnapshotPeriod,
300302
)
301303

302304
run := func(context.Context) {

Diff for: pkg/sidecar-controller/framework_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
580580
informerFactory.Groupsnapshot().V1beta1().VolumeGroupSnapshotContents(),
581581
informerFactory.Groupsnapshot().V1beta1().VolumeGroupSnapshotClasses(),
582582
workqueue.NewTypedItemExponentialFailureRateLimiter[string](1*time.Millisecond, 1*time.Minute),
583+
10*time.Second, /* pollSnapshotPeriod */
583584
)
584585

585586
ctrl.eventRecorder = record.NewFakeRecorder(1000)

Diff for: pkg/sidecar-controller/snapshot_controller_base.go

+19-14
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type csiSnapshotSideCarController struct {
6464

6565
resyncPeriod time.Duration
6666

67+
pollSnapshotPeriod time.Duration
68+
6769
enableVolumeGroupSnapshots bool
6870
groupSnapshotContentQueue workqueue.TypedRateLimitingInterface[string]
6971
groupSnapshotContentLister groupsnapshotlisters.VolumeGroupSnapshotContentLister
@@ -94,6 +96,7 @@ func NewCSISnapshotSideCarController(
9496
volumeGroupSnapshotContentInformer groupsnapshotinformers.VolumeGroupSnapshotContentInformer,
9597
volumeGroupSnapshotClassInformer groupsnapshotinformers.VolumeGroupSnapshotClassInformer,
9698
groupSnapshotContentRateLimiter workqueue.TypedRateLimiter[string],
99+
pollSnapshotPeriod time.Duration,
97100
) *csiSnapshotSideCarController {
98101
broadcaster := record.NewBroadcaster()
99102
broadcaster.StartLogging(klog.Infof)
@@ -102,13 +105,14 @@ func NewCSISnapshotSideCarController(
102105
eventRecorder = broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: fmt.Sprintf("csi-snapshotter %s", driverName)})
103106

104107
ctrl := &csiSnapshotSideCarController{
105-
clientset: clientset,
106-
client: client,
107-
driverName: driverName,
108-
eventRecorder: eventRecorder,
109-
handler: NewCSIHandler(snapshotter, groupSnapshotter, timeout, snapshotNamePrefix, snapshotNameUUIDLength, groupSnapshotNamePrefix, groupSnapshotNameUUIDLength),
110-
resyncPeriod: resyncPeriod,
111-
contentStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
108+
clientset: clientset,
109+
client: client,
110+
driverName: driverName,
111+
eventRecorder: eventRecorder,
112+
handler: NewCSIHandler(snapshotter, groupSnapshotter, timeout, snapshotNamePrefix, snapshotNameUUIDLength, groupSnapshotNamePrefix, groupSnapshotNameUUIDLength),
113+
resyncPeriod: resyncPeriod,
114+
pollSnapshotPeriod: pollSnapshotPeriod,
115+
contentStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
112116
contentQueue: workqueue.NewTypedRateLimitingQueueWithConfig(
113117
contentRateLimiter, workqueue.TypedRateLimitingQueueConfig[string]{
114118
Name: "csi-snapshotter-content"}),
@@ -232,16 +236,17 @@ func (ctrl *csiSnapshotSideCarController) processNextItem() bool {
232236
klog.V(4).Infof("Failed to sync content %q, will retry again: %v", key, err)
233237
// Always requeue on error to be able to call functions like "return false, doSomething()" where doSomething
234238
// does not need to worry about re-queueing.
235-
requeue = true
236-
}
237-
if requeue {
238239
ctrl.contentQueue.AddRateLimited(key)
239-
return true
240+
} else {
241+
// if no error occurs we Forget this item so it does not
242+
// get queued again until another change happens.
243+
ctrl.contentQueue.Forget(key)
244+
245+
if requeue {
246+
ctrl.contentQueue.AddAfter(key, ctrl.pollSnapshotPeriod)
247+
}
240248
}
241249

242-
// Finally, if no error occurs we Forget this item so it does not
243-
// get queued again until another change happens.
244-
ctrl.contentQueue.Forget(key)
245250
return true
246251
}
247252

0 commit comments

Comments
 (0)