Skip to content
Open
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
30 changes: 23 additions & 7 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,25 +619,41 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
}

createdVolumeSnapshotContent, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Create(ctx, volumeSnapshotContent, metav1.CreateOptions{})
if err != nil && !apierrs.IsAlreadyExists(err) {
if apierrs.IsAlreadyExists(err) {
createdVolumeSnapshotContent, err = ctrl.clientset.SnapshotV1().
VolumeSnapshotContents().
Get(ctx, volumeSnapshotContent.Name, metav1.GetOptions{})
}
if err != nil {
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w", err)
"createSnapshotsForGroupSnapshotContent: error creating or fetching volumesnapshotcontent %w", err)
}

createdVolumeSnapshot, err := ctrl.clientset.SnapshotV1().VolumeSnapshots(volumeSnapshotNamespace).Create(ctx, volumeSnapshot, metav1.CreateOptions{})
if err != nil && !apierrs.IsAlreadyExists(err) {
if apierrs.IsAlreadyExists(err) {
createdVolumeSnapshot, err = ctrl.clientset.SnapshotV1().
VolumeSnapshots(volumeSnapshotNamespace).
Get(ctx, volumeSnapshot.Name, metav1.GetOptions{})
}
if err != nil {
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: creating volumesnapshot %w", err)
"createSnapshotsForGroupSnapshotContent: error creating or fetching volumesnapshot %w", err)
}

// FIX for cases where the UID might be empty
if createdVolumeSnapshot.GetUID() == "" {
return groupSnapshotContent, fmt.Errorf(
"createSnapshotsForGroupSnapshotContent: created snapshot %s has an empty UID", createdVolumeSnapshot.Name)
}

// bind the volume snapshot content to the volume snapshot
// like a dynamically provisioned snapshot would do
volumeSnapshotContent.Spec.VolumeSnapshotRef.UID = createdVolumeSnapshot.UID
_, err = utils.PatchVolumeSnapshotContent(volumeSnapshotContent, []utils.PatchOp{
createdVolumeSnapshotContent.Spec.VolumeSnapshotRef.UID = createdVolumeSnapshot.UID
_, err = utils.PatchVolumeSnapshotContent(createdVolumeSnapshotContent, []utils.PatchOp{
{
Op: "replace",
Path: "/spec/volumeSnapshotRef/uid",
Value: volumeSnapshotContent.Spec.VolumeSnapshotRef.UID,
Value: createdVolumeSnapshotContent.Spec.VolumeSnapshotRef.UID,
},
}, ctrl.clientset)
if err != nil {
Expand Down