diff --git a/pkg/group_snapshotter/group_snapshotter.go b/pkg/group_snapshotter/group_snapshotter.go index 8a08507a..1149e613 100644 --- a/pkg/group_snapshotter/group_snapshotter.go +++ b/pkg/group_snapshotter/group_snapshotter.go @@ -35,7 +35,7 @@ type GroupSnapshotter interface { DeleteGroupSnapshot(ctx context.Context, groupSnapshotID string, snapshotIDs []string, snapshotterCredentials map[string]string) (err error) // GetGroupSnapshotStatus returns if a group snapshot is ready to use, its creation time, etc - GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotterListCredentials map[string]string) (bool, time.Time, error) + GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) } type groupSnapshot struct { @@ -92,7 +92,21 @@ func (gs *groupSnapshot) DeleteGroupSnapshot(ctx context.Context, groupSnapshotI return nil } -func (gs *groupSnapshot) GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotterListCredentials map[string]string) (bool, time.Time, error) { - // TODO: Implement GetGroupSnapshotStatus - return true, time.Now(), nil +func (gs *groupSnapshot) GetGroupSnapshotStatus(ctx context.Context, groupSnapshotID string, snapshotIds []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) { + klog.V(5).Infof("CSI GetGroupSnapshotStatus: %s", groupSnapshotID) + client := csi.NewGroupControllerClient(gs.conn) + + req := csi.GetVolumeGroupSnapshotRequest{ + Secrets: snapshotterListCredentials, + GroupSnapshotId: groupSnapshotID, + SnapshotIds: snapshotIds, + } + + rsp, err := client.GetVolumeGroupSnapshot(ctx, &req) + if err != nil { + return false, time.Time{}, err + } + + 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) + return rsp.GroupSnapshot.ReadyToUse, rsp.GroupSnapshot.CreationTime.AsTime(), nil } diff --git a/pkg/sidecar-controller/csi_handler.go b/pkg/sidecar-controller/csi_handler.go index c17261d0..edfa4ac7 100644 --- a/pkg/sidecar-controller/csi_handler.go +++ b/pkg/sidecar-controller/csi_handler.go @@ -36,7 +36,7 @@ type Handler interface { DeleteSnapshot(content *crdv1.VolumeSnapshotContent, snapshotterCredentials map[string]string) error GetSnapshotStatus(content *crdv1.VolumeSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, int64, string, error) CreateGroupSnapshot(content *crdv1alpha1.VolumeGroupSnapshotContent, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, []*csi.Snapshot, time.Time, bool, error) - GetGroupSnapshotStatus(content *crdv1alpha1.VolumeGroupSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, error) + GetGroupSnapshotStatus(groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) DeleteGroupSnapshot(content *crdv1alpha1.VolumeGroupSnapshotContent, SnapshotID []string, snapshotterCredentials map[string]string) error } @@ -188,23 +188,27 @@ func (handler *csiHandler) DeleteGroupSnapshot(content *crdv1alpha1.VolumeGroupS return handler.groupSnapshotter.DeleteGroupSnapshot(ctx, groupSnapshotHandle, snapshotIDs, snapshotterCredentials) } -func (handler *csiHandler) GetGroupSnapshotStatus(groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent, snapshotterListCredentials map[string]string) (bool, time.Time, error) { +func (handler *csiHandler) GetGroupSnapshotStatus(content *crdv1alpha1.VolumeGroupSnapshotContent, snapshotIDs []string, snapshotterListCredentials map[string]string) (bool, time.Time, error) { ctx, cancel := context.WithTimeout(context.Background(), handler.timeout) defer cancel() + // NOTE: snapshotIDs are required for GetGroupSnapshotStatus + if len(snapshotIDs) == 0 { + return false, time.Time{}, fmt.Errorf("cannot list group snapshot %s. No snapshots found in the group snapshot content", content.Name) + } var groupSnapshotHandle string var err error - if groupSnapshotContent.Status != nil && groupSnapshotContent.Status.VolumeGroupSnapshotHandle != nil { - groupSnapshotHandle = *groupSnapshotContent.Status.VolumeGroupSnapshotHandle - } else if groupSnapshotContent.Spec.Source.GroupSnapshotHandles != nil { - groupSnapshotHandle = groupSnapshotContent.Spec.Source.GroupSnapshotHandles.VolumeGroupSnapshotHandle + if content.Status != nil && content.Status.VolumeGroupSnapshotHandle != nil { + groupSnapshotHandle = *content.Status.VolumeGroupSnapshotHandle + } else if content.Spec.Source.GroupSnapshotHandles != nil { + groupSnapshotHandle = content.Spec.Source.GroupSnapshotHandles.VolumeGroupSnapshotHandle } else { - return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: groupSnapshotHandle is missing", groupSnapshotContent.Name) + return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: groupSnapshotHandle is missing", content.Name) } - csiSnapshotStatus, timestamp, err := handler.groupSnapshotter.GetGroupSnapshotStatus(ctx, groupSnapshotHandle, snapshotterListCredentials) + csiSnapshotStatus, timestamp, err := handler.groupSnapshotter.GetGroupSnapshotStatus(ctx, groupSnapshotHandle, snapshotIDs, snapshotterListCredentials) if err != nil { - return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: %q", groupSnapshotContent.Name, err) + return false, time.Time{}, fmt.Errorf("failed to list group snapshot for group snapshot content %s: %q", content.Name, err) } return csiSnapshotStatus, timestamp, nil diff --git a/pkg/sidecar-controller/groupsnapshot_helper.go b/pkg/sidecar-controller/groupsnapshot_helper.go index ecf6db7b..f3807199 100644 --- a/pkg/sidecar-controller/groupsnapshot_helper.go +++ b/pkg/sidecar-controller/groupsnapshot_helper.go @@ -802,7 +802,8 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat } } - readyToUse, creationTime, err = ctrl.handler.GetGroupSnapshotStatus(groupSnapshotContent, snapshotterListCredentials) + snapshotIDs := groupSnapshotContent.Spec.Source.GroupSnapshotHandles.VolumeSnapshotHandles + readyToUse, creationTime, err = ctrl.handler.GetGroupSnapshotStatus(groupSnapshotContent, snapshotIDs, snapshotterListCredentials) if err != nil { klog.Errorf("checkandUpdateGroupSnapshotContentStatusOperation: failed to call get group snapshot status to check whether group snapshot is ready to use %q", err) return groupSnapshotContent, err