Skip to content

Commit

Permalink
Clarify naming
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoce committed May 14, 2024
1 parent 71ea1e2 commit 81474e7
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/sidecar-controller/groupsnapshot_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"github.com/kubernetes-csi/external-snapshotter/v7/pkg/utils"
)

// snapshotInfo contains the basic information
// about a snapshotted volume
type snapshotInfo struct {
// snapshotContentNameVolumeHandlePair represent the link between a VolumeSnapshotContent and
// the handle of the volume that was snapshotted
type snapshotContentNameVolumeHandlePair struct {
snapshotContentName string
volumeHandle string
}
Expand Down Expand Up @@ -437,7 +437,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
return groupSnapshotContent, fmt.Errorf("failed to get secret reference for group snapshot content %s: %v", groupSnapshotContent.Name, err)
}
// Create individual snapshots and snapshot contents
var snapshotsInfo []snapshotInfo
var snapshotContentLinks []snapshotContentNameVolumeHandlePair
for _, snapshot := range snapshots {
volumeSnapshotContentName := GetSnapshotContentNameForVolumeGroupSnapshotContent(string(groupSnapshotContent.UID), snapshot.SourceVolumeId)
volumeSnapshotName := GetSnapshotNameForVolumeGroupSnapshotContent(string(groupSnapshotContent.UID), snapshot.SourceVolumeId)
Expand Down Expand Up @@ -491,7 +491,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
if err != nil {
return groupSnapshotContent, err
}
snapshotsInfo = append(snapshotsInfo, snapshotInfo{
snapshotContentLinks = append(snapshotContentLinks, snapshotContentNameVolumeHandlePair{
snapshotContentName: vsc.Name,
volumeHandle: snapshot.SourceVolumeId,
})
Expand All @@ -507,7 +507,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
}
}

newGroupSnapshotContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), snapshotsInfo)
newGroupSnapshotContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), snapshotContentLinks)
if err != nil {
klog.Errorf("error updating status for volume group snapshot content %s: %v.", groupSnapshotContent.Name, err)
return groupSnapshotContent, fmt.Errorf("error updating status for volume group snapshot content %s: %v", groupSnapshotContent.Name, err)
Expand Down Expand Up @@ -643,7 +643,7 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
groupSnapshotHandle string,
readyToUse bool,
createdAt int64,
snapshots []snapshotInfo,
snapshotContentLinks []snapshotContentNameVolumeHandlePair,
) (*crdv1alpha1.VolumeGroupSnapshotContent, error) {
klog.V(5).Infof("updateGroupSnapshotContentStatus: updating VolumeGroupSnapshotContent [%s], groupSnapshotHandle %s, readyToUse %v, createdAt %v", groupSnapshotContent.Name, groupSnapshotHandle, readyToUse, createdAt)

Expand Down Expand Up @@ -679,13 +679,13 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
ReadyToUse: &readyToUse,
CreationTime: &createdAt,
}
for _, snapshot := range snapshots {
for _, snapshotContentLink := range snapshotContentLinks {
newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{
VolumeSnapshotContentRef: v1.LocalObjectReference{
Name: snapshot.snapshotContentName,
Name: snapshotContentLink.snapshotContentName,
},
PersistentVolumeRef: v1.LocalObjectReference{
Name: snapshotInfoList.GetFromVolumeHandle(snapshot.volumeHandle).PVName,
Name: snapshotInfoList.GetFromVolumeHandle(snapshotContentLink.volumeHandle).PVName,
},
})
}
Expand All @@ -708,13 +708,13 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
updated = true
}
if len(newStatus.PVVolumeSnapshotContentList) == 0 {
for _, snapshot := range snapshots {
for _, snapshotContentLink := range snapshotContentLinks {
newStatus.PVVolumeSnapshotContentList = append(newStatus.PVVolumeSnapshotContentList, crdv1alpha1.PVVolumeSnapshotContentPair{
VolumeSnapshotContentRef: v1.LocalObjectReference{
Name: snapshot.snapshotContentName,
Name: snapshotContentLink.snapshotContentName,
},
PersistentVolumeRef: v1.LocalObjectReference{
Name: snapshotInfoList.GetFromVolumeHandle(snapshot.volumeHandle).PVName,
Name: snapshotInfoList.GetFromVolumeHandle(snapshotContentLink.volumeHandle).PVName,
},
})
}
Expand Down Expand Up @@ -878,7 +878,7 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat
}

// TODO: Get a reference to snapshot contents for this volume group snapshot
updatedContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), []snapshotInfo{})
updatedContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), []snapshotContentNameVolumeHandlePair{})
if err != nil {
return groupSnapshotContent, err
}
Expand Down

0 comments on commit 81474e7

Please sign in to comment.