Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#837 from nixpanic/GetVolumeGroupSna…
Browse files Browse the repository at this point in the history
…pshot

implement GroupSnapshotter.GetGroupSnapshotStatus()
  • Loading branch information
k8s-ci-robot authored Jan 30, 2024
2 parents 3124b8c + d0f443f commit 025f824
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
22 changes: 18 additions & 4 deletions pkg/group_snapshotter/group_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
22 changes: 13 additions & 9 deletions pkg/sidecar-controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/sidecar-controller/groupsnapshot_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 025f824

Please sign in to comment.