Skip to content

Commit e4730bc

Browse files
committed
Pass context on in GroupSnapshot sync functions
1 parent 2965ff7 commit e4730bc

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

pkg/common-controller/framework_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package common_controller
1818

1919
import (
20+
"context"
2021
"encoding/json"
2122
"errors"
2223
"fmt"
@@ -1751,7 +1752,7 @@ func testSyncSnapshot(ctrl *csiSnapshotCommonController, reactor *snapshotReacto
17511752
}
17521753

17531754
func testSyncGroupSnapshot(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
1754-
return ctrl.syncGroupSnapshot(test.initialGroupSnapshots[0])
1755+
return ctrl.syncGroupSnapshot(context.TODO(), test.initialGroupSnapshots[0])
17551756
}
17561757

17571758
func testSyncSnapshotError(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (ctrl *csiSnapshotCommonController) getClaimsFromVolumeGroupSnapshot(groupS
234234

235235
// updateGroupSnapshot runs in worker thread and handles "groupsnapshot added",
236236
// "groupsnapshot updated" and "periodic sync" events.
237-
func (ctrl *csiSnapshotCommonController) updateGroupSnapshot(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
237+
func (ctrl *csiSnapshotCommonController) updateGroupSnapshot(ctx context.Context, groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
238238
// Store the new group snapshot version in the cache and do not process it
239239
// if this is an old version.
240240
klog.V(5).Infof("updateGroupSnapshot %q", utils.GroupSnapshotKey(groupSnapshot))
@@ -246,7 +246,7 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshot(groupSnapshot *crdv
246246
return nil
247247
}
248248

249-
err = ctrl.syncGroupSnapshot(groupSnapshot)
249+
err = ctrl.syncGroupSnapshot(ctx, groupSnapshot)
250250
if err != nil {
251251
if errors.IsConflict(err) {
252252
// Version conflict error happens quite often and the controller
@@ -294,7 +294,7 @@ func (ctrl *csiSnapshotCommonController) deleteGroupSnapshot(groupSnapshot *crdv
294294
// a group snapshot is created, updated or periodically synced. We do not
295295
// differentiate between these events.
296296
// For easier readability, it is split into syncUnreadyGroupSnapshot and syncReadyGroupSnapshot
297-
func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
297+
func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(ctx context.Context, groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
298298
klog.V(5).Infof("synchronizing VolumeGroupSnapshot[%s]", utils.GroupSnapshotKey(groupSnapshot))
299299

300300
klog.V(5).Infof("syncGroupSnapshot [%s]: check if we should remove finalizer on group snapshot PVC source and remove it if we can", utils.GroupSnapshotKey(groupSnapshot))
@@ -326,7 +326,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
326326
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
327327
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
328328
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) {
329-
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
329+
return ctrl.syncUnreadyGroupSnapshot(ctx, groupSnapshot)
330330
}
331331
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
332332
}
@@ -383,7 +383,7 @@ func (ctrl *csiSnapshotCommonController) getGroupSnapshotContentFromStore(conten
383383

384384
// syncUnreadyGroupSnapshot is the main controller method to decide what to do
385385
// with a group snapshot which is not set to ready.
386-
func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
386+
func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(ctx context.Context, groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) error {
387387
uniqueGroupSnapshotName := utils.GroupSnapshotKey(groupSnapshot)
388388
klog.V(5).Infof("syncUnreadyGroupSnapshot %s", uniqueGroupSnapshotName)
389389
driverName, err := ctrl.getGroupSnapshotDriverName(groupSnapshot)
@@ -460,8 +460,7 @@ func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot
460460
return fmt.Errorf("VolumeGroupSnapshotHandle should not be set in the group snapshot content for dynamic provisioning for group snapshot %s", uniqueGroupSnapshotName)
461461
}
462462

463-
// TODO(leonardoce): introduce a current context in this function
464-
newGroupSnapshotContentObj, err := ctrl.createSnapshotsForGroupSnapshotContent(context.TODO(), contentObj, groupSnapshot)
463+
newGroupSnapshotContentObj, err := ctrl.createSnapshotsForGroupSnapshotContent(ctx, contentObj, groupSnapshot)
465464
if err != nil {
466465
klog.V(4).Infof("createSnapshotsForGroupSnapshotContent[%s]: failed to create snapshots and snapshotcontents for group snapshot %v: %v",
467466
contentObj.Name, groupSnapshot.Name, err.Error())

pkg/common-controller/snapshot_controller_base.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package common_controller
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"time"
2223

@@ -671,7 +672,7 @@ func (ctrl *csiSnapshotCommonController) groupSnapshotWorker() {
671672
}
672673
defer ctrl.groupSnapshotQueue.Done(keyObj)
673674

674-
if err := ctrl.syncGroupSnapshotByKey(keyObj.(string)); err != nil {
675+
if err := ctrl.syncGroupSnapshotByKey(context.Background(), keyObj.(string)); err != nil {
675676
// Rather than wait for a full resync, re-add the key to the
676677
// queue to be processed.
677678
ctrl.groupSnapshotQueue.AddRateLimited(keyObj)
@@ -704,7 +705,7 @@ func (ctrl *csiSnapshotCommonController) groupSnapshotContentWorker() {
704705
}
705706

706707
// syncGroupSnapshotByKey processes a VolumeGroupSnapshot request.
707-
func (ctrl *csiSnapshotCommonController) syncGroupSnapshotByKey(key string) error {
708+
func (ctrl *csiSnapshotCommonController) syncGroupSnapshotByKey(ctx context.Context, key string) error {
708709
klog.V(5).Infof("syncGroupSnapshotByKey[%s]", key)
709710

710711
namespace, name, err := cache.SplitMetaNamespaceKey(key)
@@ -726,7 +727,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshotByKey(key string) erro
726727
klog.V(5).Infof("GroupSnapshot %q is being deleted. GroupSnapshotClass has already been removed", key)
727728
}
728729
klog.V(5).Infof("Updating group snapshot %q", key)
729-
return ctrl.updateGroupSnapshot(newGroupSnapshot)
730+
return ctrl.updateGroupSnapshot(ctx, newGroupSnapshot)
730731
}
731732
return err
732733
}

0 commit comments

Comments
 (0)