Skip to content

Commit d0f443f

Browse files
committed
implement GroupSnapshotter.GetGroupSnapshotStatus()
1 parent 3124b8c commit d0f443f

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

pkg/group_snapshotter/group_snapshotter.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type GroupSnapshotter interface {
3535
DeleteGroupSnapshot(ctx context.Context, groupSnapshotID string, snapshotIDs []string, snapshotterCredentials map[string]string) (err error)
3636

3737
// GetGroupSnapshotStatus returns if a group snapshot is ready to use, its creation time, etc
38-
GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotterListCredentials map[string]string) (bool, time.Time, error)
38+
GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error)
3939
}
4040

4141
type groupSnapshot struct {
@@ -92,7 +92,21 @@ func (gs *groupSnapshot) DeleteGroupSnapshot(ctx context.Context, groupSnapshotI
9292
return nil
9393
}
9494

95-
func (gs *groupSnapshot) GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotterListCredentials map[string]string) (bool, time.Time, error) {
96-
// TODO: Implement GetGroupSnapshotStatus
97-
return true, time.Now(), nil
95+
func (gs *groupSnapshot) GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotIds []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) {
96+
klog.V(5).Infof("CSI GetGroupSnapshotStatus: %s", groupSnapshotID)
97+
client := csi.NewGroupControllerClient(gs.conn)
98+
99+
req := csi.GetVolumeGroupSnapshotRequest{
100+
Secrets: snapshotterListCredentials,
101+
GroupSnapshotId: groupSnapshotID,
102+
SnapshotIds: snapshotIds,
103+
}
104+
105+
rsp, err := client.GetVolumeGroupSnapshot(ctx, &req)
106+
if err != nil {
107+
return false, time.Time{}, err
108+
}
109+
110+
klog.V(5).Infof("CSI GetGroupSnapshot: group snapshot ID [%s] time stamp [%v] snapshots [%v] readyToUse [%v]", rsp.GroupSnapshot.GroupSnapshotId, rsp.GroupSnapshot.CreationTime, rsp.GroupSnapshot.Snapshots, rsp.GroupSnapshot.ReadyToUse)
111+
return rsp.GroupSnapshot.ReadyToUse, rsp.GroupSnapshot.CreationTime.AsTime(), nil
98112
}

pkg/sidecar-controller/csi_handler.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Handler interface {
3636
DeleteSnapshot(content *crdv1.VolumeSnapshotContent, snapshotterCredentials map[string]string) error
3737
GetSnapshotStatus(content *crdv1.VolumeSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, int64, string, error)
3838
CreateGroupSnapshot(content *crdv1alpha1.VolumeGroupSnapshotContent, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, []*csi.Snapshot, time.Time, bool, error)
39-
GetGroupSnapshotStatus(content *crdv1alpha1.VolumeGroupSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, error)
39+
GetGroupSnapshotStatus(groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error)
4040
DeleteGroupSnapshot(content *crdv1alpha1.VolumeGroupSnapshotContent, SnapshotID []string, snapshotterCredentials map[string]string) error
4141
}
4242

@@ -188,23 +188,27 @@ func (handler *csiHandler) DeleteGroupSnapshot(content *crdv1alpha1.VolumeGroupS
188188
return handler.groupSnapshotter.DeleteGroupSnapshot(ctx, groupSnapshotHandle, snapshotIDs, snapshotterCredentials)
189189
}
190190

191-
func (handler *csiHandler) GetGroupSnapshotStatus(groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, error) {
191+
func (handler *csiHandler) GetGroupSnapshotStatus(content *crdv1alpha1.VolumeGroupSnapshotContent, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) {
192192
ctx, cancel := context.WithTimeout(context.Background(), handler.timeout)
193193
defer cancel()
194194

195+
// NOTE: snapshotIDs are required for GetGroupSnapshotStatus
196+
if len(snapshotIDs) == 0 {
197+
return false, time.Time{}, fmt.Errorf("cannot list group snapshot %s. No snapshots found in the group snapshot content", content.Name)
198+
}
195199
var groupSnapshotHandle string
196200
var err error
197-
if groupSnapshotContent.Status != nil && groupSnapshotContent.Status.VolumeGroupSnapshotHandle != nil {
198-
groupSnapshotHandle = *groupSnapshotContent.Status.VolumeGroupSnapshotHandle
199-
} else if groupSnapshotContent.Spec.Source.GroupSnapshotHandles != nil {
200-
groupSnapshotHandle = groupSnapshotContent.Spec.Source.GroupSnapshotHandles.VolumeGroupSnapshotHandle
201+
if content.Status != nil && content.Status.VolumeGroupSnapshotHandle != nil {
202+
groupSnapshotHandle = *content.Status.VolumeGroupSnapshotHandle
203+
} else if content.Spec.Source.GroupSnapshotHandles != nil {
204+
groupSnapshotHandle = content.Spec.Source.GroupSnapshotHandles.VolumeGroupSnapshotHandle
201205
} else {
202-
return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: groupSnapshotHandle is missing", groupSnapshotContent.Name)
206+
return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: groupSnapshotHandle is missing", content.Name)
203207
}
204208

205-
csiSnapshotStatus, timestamp, err := handler.groupSnapshotter.GetGroupSnapshotStatus(ctx, groupSnapshotHandle, snapshotterListCredentials)
209+
csiSnapshotStatus, timestamp, err := handler.groupSnapshotter.GetGroupSnapshotStatus(ctx, groupSnapshotHandle, snapshotIDs, snapshotterListCredentials)
206210
if err != nil {
207-
return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: %q", groupSnapshotContent.Name, err)
211+
return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: %q", content.Name, err)
208212
}
209213

210214
return csiSnapshotStatus, timestamp, nil

pkg/sidecar-controller/groupsnapshot_helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat
802802
}
803803
}
804804

805-
readyToUse, creationTime, err = ctrl.handler.GetGroupSnapshotStatus(groupSnapshotContent, snapshotterListCredentials)
805+
snapshotIDs := groupSnapshotContent.Spec.Source.GroupSnapshotHandles.VolumeSnapshotHandles
806+
readyToUse, creationTime, err = ctrl.handler.GetGroupSnapshotStatus(groupSnapshotContent, snapshotIDs, snapshotterListCredentials)
806807
if err != nil {
807808
klog.Errorf("checkandUpdateGroupSnapshotContentStatusOperation: failed to call get group snapshot status to check whether group snapshot is ready to use %q", err)
808809
return groupSnapshotContent, err

0 commit comments

Comments
 (0)