Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass context on in GroupSnapshot sync functions #1193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/common-controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package common_controller

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -1751,7 +1752,7 @@ func testSyncSnapshot(ctrl *csiSnapshotCommonController, reactor *snapshotReacto
}

func testSyncGroupSnapshot(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
return ctrl.syncGroupSnapshot(test.initialGroupSnapshots[0])
return ctrl.syncGroupSnapshot(context.TODO(), test.initialGroupSnapshots[0])
}

func testSyncSnapshotError(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
Expand Down
13 changes: 6 additions & 7 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (ctrl *csiSnapshotCommonController) getClaimsFromVolumeGroupSnapshot(groupS

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

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

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))
Expand Down Expand Up @@ -326,7 +326,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) {
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
return ctrl.syncUnreadyGroupSnapshot(ctx, groupSnapshot)
}
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func (ctrl *csiSnapshotCommonController) getGroupSnapshotContentFromStore(conten

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

// TODO(leonardoce): introduce a current context in this function
newGroupSnapshotContentObj, err := ctrl.createSnapshotsForGroupSnapshotContent(context.TODO(), contentObj, groupSnapshot)
newGroupSnapshotContentObj, err := ctrl.createSnapshotsForGroupSnapshotContent(ctx, contentObj, groupSnapshot)
if err != nil {
klog.V(4).Infof("createSnapshotsForGroupSnapshotContent[%s]: failed to create snapshots and snapshotcontents for group snapshot %v: %v",
contentObj.Name, groupSnapshot.Name, err.Error())
Expand Down
7 changes: 4 additions & 3 deletions pkg/common-controller/snapshot_controller_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package common_controller

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -671,7 +672,7 @@ func (ctrl *csiSnapshotCommonController) groupSnapshotWorker() {
}
defer ctrl.groupSnapshotQueue.Done(keyObj)

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

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

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