Skip to content

Commit 7c8516f

Browse files
committed
Minimal changes to get the controller working with the updated API
This commit won't set any value in the new fields, but only change the logic to reproduce the behavior we already had.
1 parent 76c098a commit 7c8516f

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
315315
// 2) groupSnapshot.Status.ReadyToUse is false
316316
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
317317
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
318-
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsVolumeSnapshotRefListSet(groupSnapshot) {
318+
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) {
319319
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
320320
}
321321
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
@@ -564,14 +564,16 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
564564
volumeSnapshotErr = groupSnapshotContent.Status.Error.DeepCopy()
565565
}
566566

567-
var volumeSnapshotRefList []v1.ObjectReference
568-
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 {
569-
for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList {
570-
groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.Name)
567+
var pvcVolumeSnapshotRefList []crdv1alpha1.PVCVolumeSnapshotPair
568+
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 {
569+
for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList {
570+
groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName)
571571
if err != nil {
572-
return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.Name, err)
572+
return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err)
573573
}
574-
volumeSnapshotRefList = append(volumeSnapshotRefList, groupSnapshotContent.Spec.VolumeSnapshotRef)
574+
pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{
575+
VolumeSnapshotRef: groupSnapshotContent.Spec.VolumeSnapshotRef,
576+
})
575577
}
576578
}
577579

@@ -595,8 +597,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
595597
if volumeSnapshotErr != nil {
596598
newStatus.Error = volumeSnapshotErr
597599
}
598-
if len(volumeSnapshotRefList) == 0 {
599-
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
600+
if len(pvcVolumeSnapshotRefList) == 0 {
601+
newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList
600602
}
601603

602604
updated = true
@@ -621,8 +623,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
621623
newStatus.Error = volumeSnapshotErr
622624
updated = true
623625
}
624-
if len(newStatus.VolumeSnapshotRefList) == 0 {
625-
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
626+
if len(newStatus.PVCVolumeSnapshotRefList) == 0 {
627+
newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList
626628
updated = true
627629
}
628630
}
@@ -1137,8 +1139,8 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
11371139
// check if an individual snapshot belonging to the group snapshot is being
11381140
// used for restore a PVC
11391141
// If yes, do nothing and wait until PVC restoration finishes
1140-
for _, snapshotRef := range groupSnapshot.Status.VolumeSnapshotRefList {
1141-
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.Namespace).Get(snapshotRef.Name)
1142+
for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
1143+
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.VolumeSnapshotRef.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name)
11421144
if err != nil {
11431145
if apierrs.IsNotFound(err) {
11441146
continue
@@ -1185,10 +1187,10 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
11851187
klog.V(5).Infof("processGroupSnapshotWithDeletionTimestamp[%s]: Delete individual snapshots that are part of the group snapshot", utils.GroupSnapshotKey(groupSnapshot))
11861188

11871189
// Delete the individual snapshots part of the group snapshot
1188-
for _, snapshot := range groupSnapshot.Status.VolumeSnapshotRefList {
1189-
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.Namespace).Delete(context.TODO(), snapshot.Name, metav1.DeleteOptions{})
1190+
for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
1191+
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.VolumeSnapshotRef.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{})
11901192
if err != nil && !apierrs.IsNotFound(err) {
1191-
msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", snapshot.Namespace, snapshot.Name, utils.GroupSnapshotKey(groupSnapshot), err)
1193+
msg := fmt.Sprintf("failed to delete snapshot API object %s/%s part of group snapshot %s: %v", snapshot.VolumeSnapshotRef.Namespace, snapshot.VolumeSnapshotRef.Name, utils.GroupSnapshotKey(groupSnapshot), err)
11921194
klog.Error(msg)
11931195
ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg)
11941196
return fmt.Errorf(msg)

pkg/sidecar-controller/groupsnapshot_helper.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ func (ctrl *csiSnapshotSideCarController) deleteCSIGroupSnapshotOperation(groupS
240240
}
241241

242242
var snapshotIDs []string
243-
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 {
244-
for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList {
245-
snapshotContent, err := ctrl.contentLister.Get(contentRef.Name)
243+
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 {
244+
for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList {
245+
snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName)
246246
if err != nil {
247-
return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.Name, err)
247+
return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentName, err)
248248
}
249249
snapshotIDs = append(snapshotIDs, *snapshotContent.Status.SnapshotHandle)
250250
}
@@ -283,7 +283,7 @@ func (ctrl *csiSnapshotSideCarController) clearGroupSnapshotContentStatus(
283283
groupSnapshotContent.Status.ReadyToUse = nil
284284
groupSnapshotContent.Status.CreationTime = nil
285285
groupSnapshotContent.Status.Error = nil
286-
groupSnapshotContent.Status.VolumeSnapshotContentRefList = nil
286+
groupSnapshotContent.Status.PVVolumeSnapshotContentRefList = nil
287287
}
288288
newContent, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().UpdateStatus(context.TODO(), groupSnapshotContent, metav1.UpdateOptions{})
289289
if err != nil {
@@ -650,9 +650,8 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
650650
CreationTime: &createdAt,
651651
}
652652
for _, name := range snapshotContentNames {
653-
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
654-
Kind: "VolumeSnapshotContent",
655-
Name: name,
653+
newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{
654+
VolumeSnapshotContentName: name,
656655
})
657656
}
658657
updated = true
@@ -673,11 +672,10 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
673672
newStatus.CreationTime = &createdAt
674673
updated = true
675674
}
676-
if len(newStatus.VolumeSnapshotContentRefList) == 0 {
675+
if len(newStatus.PVVolumeSnapshotContentRefList) == 0 {
677676
for _, name := range snapshotContentNames {
678-
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
679-
Kind: "VolumeSnapshotContent",
680-
Name: name,
677+
newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{
678+
VolumeSnapshotContentName: name,
681679
})
682680
}
683681
updated = true

pkg/utils/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeG
638638
return true
639639
}
640640

641-
func IsVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
642-
if groupSnapshot.Status == nil || len(groupSnapshot.Status.VolumeSnapshotRefList) == 0 {
641+
func IsPVCVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
642+
if groupSnapshot.Status == nil || len(groupSnapshot.Status.PVCVolumeSnapshotRefList) == 0 {
643643
return false
644644
}
645645
return true

0 commit comments

Comments
 (0)