Skip to content

Commit

Permalink
Set VolumeHandle for dynamic provisioned VolumeGroupSnapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoce committed Nov 19, 2024
1 parent a7443c7 commit a1be62e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
44 changes: 37 additions & 7 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
DeletionPolicy: groupSnapshotContent.Spec.DeletionPolicy,
Driver: groupSnapshotContent.Spec.Driver,
Source: crdv1.VolumeSnapshotContentSource{
SnapshotHandle: &snapshotHandle,
VolumeHandle: &volumeHandle,
},
},
// The status will be set by VolumeSnapshotContent reconciler
Expand Down Expand Up @@ -599,15 +599,19 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
Labels: label,
Finalizers: []string{utils.VolumeSnapshotInGroupFinalizer},
},
Spec: crdv1.VolumeSnapshotSpec{
Source: crdv1.VolumeSnapshotSource{
PersistentVolumeClaimName: &pv.Spec.ClaimRef.Name,
},
},
// The spec stanza is set immediately
// The status will be set by VolumeSnapshot reconciler
}

_, err = ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Create(ctx, volumeSnapshotContent, metav1.CreateOptions{})
if pv != nil {
volumeSnapshot.Spec.Source.PersistentVolumeClaimName = &pv.Spec.ClaimRef.Name
} else {
// If no persistent volume was wound, set the PVC name to empty
var emptyString string
volumeSnapshot.Spec.Source.PersistentVolumeClaimName = &emptyString
}

createdVolumeSnapshotContent, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Create(ctx, volumeSnapshotContent, metav1.CreateOptions{})
if err != nil && !apierrs.IsAlreadyExists(err) {
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w", err)
Expand Down Expand Up @@ -663,6 +667,32 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: binding volumesnapshot to volumesnapshotcontent %w", err)
}

// set the snapshot handle and the group snapshot handle
// inside the volume snapshot content to allow
// the CSI Snapshotter sidecar to reconcile its status
_, err = utils.PatchVolumeSnapshotContent(createdVolumeSnapshotContent, []utils.PatchOp{
{
Op: "replace",
Path: "/status",
Value: &crdv1.VolumeSnapshotContentStatus{},
},
{
Op: "replace",
Path: "/status/snapshotHandle",
Value: snapshotHandle,
},
{
Op: "replace",
Path: "/status/volumeGroupSnapshotHandle",
Value: groupSnapshotContent.Status.VolumeGroupSnapshotHandle,
},
}, ctrl.clientset, "status")
if err != nil {
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: setting snapshotHandle in volumesnapshotcontent %w", err)
}

}

// Phase 2: set the backlinks
Expand Down
14 changes: 11 additions & 3 deletions pkg/sidecar-controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
var size int64
readyToUse := false
var driverName string
var snapshotID, groupSnapshotID string
var groupSnapshotID string
var snapshotterListCredentials map[string]string

if content.Spec.Source.SnapshotHandle != nil {
volumeGroupSnapshotMember := content.Status != nil && content.Status.VolumeGroupSnapshotHandle != nil

if content.Spec.Source.SnapshotHandle != nil || (volumeGroupSnapshotMember && content.Status.SnapshotHandle != nil) {
klog.V(5).Infof("checkandUpdateContentStatusOperation: call GetSnapshotStatus for snapshot which is pre-bound to content [%s]", content.Name)

if content.Spec.VolumeSnapshotClassName != nil {
Expand Down Expand Up @@ -286,7 +288,13 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
return content, err
}
driverName = content.Spec.Driver
snapshotID = *content.Spec.Source.SnapshotHandle

var snapshotID string
if content.Spec.Source.SnapshotHandle != nil {
snapshotID = *content.Spec.Source.SnapshotHandle
} else {
snapshotID = *content.Status.SnapshotHandle
}

klog.V(5).Infof("checkandUpdateContentStatusOperation: driver %s, snapshotId %s, creationTime %v, size %d, readyToUse %t, groupSnapshotID %s", driverName, snapshotID, creationTime, size, readyToUse, groupSnapshotID)

Expand Down

0 comments on commit a1be62e

Please sign in to comment.