Skip to content

Commit

Permalink
Minimal changes to get the controller working with the updated API
Browse files Browse the repository at this point in the history
This commit won't set any value in the new fields, but only change the
logic to reproduce the behavior we already had.
  • Loading branch information
leonardoce committed Apr 18, 2024
1 parent 282443f commit 248171c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
34 changes: 18 additions & 16 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
// 2) groupSnapshot.Status.ReadyToUse is false
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsVolumeSnapshotRefListSet(groupSnapshot) {
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsPVCVolumeSnapshotRefListSet(groupSnapshot) {
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
}
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
Expand Down Expand Up @@ -564,14 +564,16 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
volumeSnapshotErr = groupSnapshotContent.Status.Error.DeepCopy()
}

var volumeSnapshotRefList []v1.ObjectReference
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 {
for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList {
groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.Name)
var pvcVolumeSnapshotRefList []crdv1alpha1.PVCVolumeSnapshotPair
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 {
for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList {
groupSnapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName)
if err != nil {
return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.Name, err)
return nil, fmt.Errorf("failed to get group snapshot content %s from group snapshot content store: %v", contentRef.VolumeSnapshotContentName, err)
}
volumeSnapshotRefList = append(volumeSnapshotRefList, groupSnapshotContent.Spec.VolumeSnapshotRef)
pvcVolumeSnapshotRefList = append(pvcVolumeSnapshotRefList, crdv1alpha1.PVCVolumeSnapshotPair{
VolumeSnapshotRef: groupSnapshotContent.Spec.VolumeSnapshotRef,
})
}
}

Expand All @@ -595,8 +597,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
if volumeSnapshotErr != nil {
newStatus.Error = volumeSnapshotErr
}
if len(volumeSnapshotRefList) == 0 {
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
if len(pvcVolumeSnapshotRefList) == 0 {
newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList
}

updated = true
Expand All @@ -621,8 +623,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
newStatus.Error = volumeSnapshotErr
updated = true
}
if len(newStatus.VolumeSnapshotRefList) == 0 {
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
if len(newStatus.PVCVolumeSnapshotRefList) == 0 {
newStatus.PVCVolumeSnapshotRefList = pvcVolumeSnapshotRefList
updated = true
}
}
Expand Down Expand Up @@ -1137,8 +1139,8 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
// check if an individual snapshot belonging to the group snapshot is being
// used for restore a PVC
// If yes, do nothing and wait until PVC restoration finishes
for _, snapshotRef := range groupSnapshot.Status.VolumeSnapshotRefList {
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.Namespace).Get(snapshotRef.Name)
for _, snapshotRef := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
snapshot, err := ctrl.snapshotLister.VolumeSnapshots(snapshotRef.VolumeSnapshotRef.Namespace).Get(snapshotRef.VolumeSnapshotRef.Name)
if err != nil {
if apierrs.IsNotFound(err) {
continue
Expand Down Expand Up @@ -1185,10 +1187,10 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
klog.V(5).Infof("processGroupSnapshotWithDeletionTimestamp[%s]: Delete individual snapshots that are part of the group snapshot", utils.GroupSnapshotKey(groupSnapshot))

// Delete the individual snapshots part of the group snapshot
for _, snapshot := range groupSnapshot.Status.VolumeSnapshotRefList {
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.Namespace).Delete(context.TODO(), snapshot.Name, metav1.DeleteOptions{})
for _, snapshot := range groupSnapshot.Status.PVCVolumeSnapshotRefList {
err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.VolumeSnapshotRef.Namespace).Delete(context.TODO(), snapshot.VolumeSnapshotRef.Name, metav1.DeleteOptions{})
if err != nil && !apierrs.IsNotFound(err) {
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)
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)
klog.Error(msg)
ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "SnapshotDeleteError", msg)
return fmt.Errorf(msg)
Expand Down
22 changes: 10 additions & 12 deletions pkg/sidecar-controller/groupsnapshot_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ func (ctrl *csiSnapshotSideCarController) deleteCSIGroupSnapshotOperation(groupS
}

var snapshotIDs []string
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 {
for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList {
snapshotContent, err := ctrl.contentLister.Get(contentRef.Name)
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.PVVolumeSnapshotContentRefList) != 0 {
for _, contentRef := range groupSnapshotContent.Status.PVVolumeSnapshotContentRefList {
snapshotContent, err := ctrl.contentLister.Get(contentRef.VolumeSnapshotContentName)
if err != nil {
return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.Name, err)
return fmt.Errorf("failed to get snapshot content %s from snapshot content store: %v", contentRef.VolumeSnapshotContentName, err)
}
snapshotIDs = append(snapshotIDs, *snapshotContent.Status.SnapshotHandle)
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (ctrl *csiSnapshotSideCarController) clearGroupSnapshotContentStatus(
groupSnapshotContent.Status.ReadyToUse = nil
groupSnapshotContent.Status.CreationTime = nil
groupSnapshotContent.Status.Error = nil
groupSnapshotContent.Status.VolumeSnapshotContentRefList = nil
groupSnapshotContent.Status.PVVolumeSnapshotContentRefList = nil
}
newContent, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().UpdateStatus(context.TODO(), groupSnapshotContent, metav1.UpdateOptions{})
if err != nil {
Expand Down Expand Up @@ -650,9 +650,8 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
CreationTime: &createdAt,
}
for _, name := range snapshotContentNames {
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
Kind: "VolumeSnapshotContent",
Name: name,
newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{
VolumeSnapshotContentName: name,
})
}
updated = true
Expand All @@ -673,11 +672,10 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
newStatus.CreationTime = &createdAt
updated = true
}
if len(newStatus.VolumeSnapshotContentRefList) == 0 {
if len(newStatus.PVVolumeSnapshotContentRefList) == 0 {
for _, name := range snapshotContentNames {
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
Kind: "VolumeSnapshotContent",
Name: name,
newStatus.PVVolumeSnapshotContentRefList = append(newStatus.PVVolumeSnapshotContentRefList, crdv1alpha1.PVVolumeSnapshotContentPair{
VolumeSnapshotContentName: name,
})
}
updated = true
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeG
return true
}

func IsVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
if groupSnapshot.Status == nil || len(groupSnapshot.Status.VolumeSnapshotRefList) == 0 {
func IsPVCVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
if groupSnapshot.Status == nil || len(groupSnapshot.Status.PVCVolumeSnapshotRefList) == 0 {
return false
}
return true
Expand Down

0 comments on commit 248171c

Please sign in to comment.