Skip to content

Commit ab40e9d

Browse files
authored
Merge pull request #1177 from leonardoce/set-pvc-name
Set PVC name on VolumeGroupSnapshot members
2 parents 8b17d9f + 811740c commit ab40e9d

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
609609
},
610610
Spec: crdv1.VolumeSnapshotSpec{
611611
Source: crdv1.VolumeSnapshotSource{
612-
VolumeSnapshotContentName: &volumeSnapshotContentName,
612+
PersistentVolumeClaimName: &pv.Spec.ClaimRef.Name,
613613
},
614614
},
615615
// The status will be set by VolumeSnapshot reconciler
@@ -621,7 +621,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
621621
"createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w", err)
622622
}
623623

624-
_, err = ctrl.clientset.SnapshotV1().VolumeSnapshots(volumeSnapshotNamespace).Create(ctx, volumeSnapshot, metav1.CreateOptions{})
624+
createdVolumeSnapshot, err := ctrl.clientset.SnapshotV1().VolumeSnapshots(volumeSnapshotNamespace).Create(ctx, volumeSnapshot, metav1.CreateOptions{})
625625
if err != nil && !apierrs.IsAlreadyExists(err) {
626626
return groupSnapshotContent, fmt.Errorf(
627627
"createSnapshotsForGroupSnapshotContent: creating volumesnapshot %w", err)
@@ -637,6 +637,40 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
637637
Name: pv.Name,
638638
}
639639
}
640+
641+
// bind the volume snapshot content to the volume snapshot
642+
// like a dynamically provisioned snapshot would do
643+
volumeSnapshotContent.Spec.VolumeSnapshotRef.UID = createdVolumeSnapshot.UID
644+
_, err = utils.PatchVolumeSnapshotContent(volumeSnapshotContent, []utils.PatchOp{
645+
{
646+
Op: "replace",
647+
Path: "/spec/volumeSnapshotRef/uid",
648+
Value: volumeSnapshotContent.Spec.VolumeSnapshotRef.UID,
649+
},
650+
}, ctrl.clientset)
651+
if err != nil {
652+
return groupSnapshotContent, fmt.Errorf(
653+
"createSnapshotsForGroupSnapshotContent: binding volumesnapshotcontent to volumesnapshot %w", err)
654+
}
655+
656+
// bind the volume snapshot to the volume snapshot content
657+
// like a dynamically provisioned snapshot would do
658+
_, err = utils.PatchVolumeSnapshot(createdVolumeSnapshot, []utils.PatchOp{
659+
{
660+
Op: "replace",
661+
Path: "/status",
662+
Value: &crdv1.VolumeSnapshotStatus{},
663+
},
664+
{
665+
Op: "replace",
666+
Path: "/status/boundVolumeSnapshotContentName",
667+
Value: volumeSnapshotContentName,
668+
},
669+
}, ctrl.clientset, "status")
670+
if err != nil {
671+
return groupSnapshotContent, fmt.Errorf(
672+
"createSnapshotsForGroupSnapshotContent: binding volumesnapshot to volumesnapshotcontent %w", err)
673+
}
640674
}
641675

642676
// Phase 2: set the backlinks

pkg/common-controller/snapshot_controller.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,40 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
484484
return nil
485485
}
486486

487+
// member of a dynamically provisioned volume group snapshot
488+
if _, ok := snapshot.Labels[utils.VolumeGroupSnapshotNameLabel]; ok {
489+
if snapshot.Status == nil || snapshot.Status.BoundVolumeSnapshotContentName == nil {
490+
klog.V(5).Infof(
491+
"syncUnreadySnapshot [%s]: detected group snapshot member with no content, retrying",
492+
utils.SnapshotKey(snapshot))
493+
return fmt.Errorf("detected group snapshot member %s with no content, retrying",
494+
utils.SnapshotKey(snapshot))
495+
}
496+
497+
volumeSnapshotContentName := *snapshot.Status.BoundVolumeSnapshotContentName
498+
499+
content, err := ctrl.getContentFromStore(volumeSnapshotContentName)
500+
if err != nil {
501+
return err
502+
}
503+
if content == nil {
504+
// can not find the desired VolumeSnapshotContent from cache store
505+
// we'll retry
506+
return fmt.Errorf("group snapshot member %s requests an non-existing content %s", utils.SnapshotKey(snapshot), volumeSnapshotContentName)
507+
}
508+
509+
// update snapshot status
510+
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update group snapshot member status", utils.SnapshotKey(snapshot))
511+
if _, err = ctrl.updateSnapshotStatus(snapshot, content); err != nil {
512+
// update snapshot status failed
513+
klog.V(4).Infof("failed to update group snapshot member %s status: %v", utils.SnapshotKey(snapshot), err)
514+
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, false, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
515+
return err
516+
}
517+
518+
return nil
519+
}
520+
487521
// snapshot.Spec.Source.VolumeSnapshotContentName == nil - dynamically creating snapshot
488522
klog.V(5).Infof("getDynamicallyProvisionedContentFromStore for snapshot %s", uniqueSnapshotName)
489523
contentObj, err := ctrl.getDynamicallyProvisionedContentFromStore(snapshot)
@@ -1390,6 +1424,12 @@ func (ctrl *csiSnapshotCommonController) SetDefaultSnapshotClass(snapshot *crdv1
13901424
return nil, snapshot, nil
13911425
}
13921426

1427+
if _, ok := snapshot.Labels[utils.VolumeGroupSnapshotNameLabel]; ok {
1428+
// don't return error for volume group snapshot members
1429+
klog.V(5).Infof("Don't need to find SnapshotClass for volume group snapshot member [%s]", snapshot.Name)
1430+
return nil, snapshot, nil
1431+
}
1432+
13931433
// Find default snapshot class if available
13941434
list, err := ctrl.classLister.List(labels.Everything())
13951435
if err != nil {

0 commit comments

Comments
 (0)