Check if ListSnapshots is supported during GetSnapshotStatus

This commit is contained in:
Grant Griffiths
2019-07-10 16:36:31 -07:00
parent c0658cb68d
commit ea5d2d6089
2 changed files with 86 additions and 31 deletions

View File

@@ -101,13 +101,36 @@ func (s *snapshot) DeleteSnapshot(ctx context.Context, snapshotID string, snapsh
return nil
}
func (s *snapshot) isListSnapshotsSupported(ctx context.Context) (bool, error) {
client := csi.NewControllerClient(s.conn)
capRsp, err := client.ControllerGetCapabilities(ctx, &csi.ControllerGetCapabilitiesRequest{})
if err != nil {
return false, err
}
for _, cap := range capRsp.Capabilities {
if cap.GetRpc().GetType() == csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS {
return true, nil
}
}
return false, nil
}
func (s *snapshot) GetSnapshotStatus(ctx context.Context, snapshotID string) (bool, time.Time, int64, error) {
client := csi.NewControllerClient(s.conn)
// If the driver does not support ListSnapshots, assume the snapshot ID is valid.
listSnapshotsSupported, err := s.isListSnapshotsSupported(ctx)
if err != nil {
return false, time.Time{}, 0, fmt.Errorf("failed to check if ListSnapshots is supported: %s", err.Error())
}
if !listSnapshotsSupported {
return true, time.Time{}, 0, nil
}
req := csi.ListSnapshotsRequest{
SnapshotId: snapshotID,
}
rsp, err := client.ListSnapshots(ctx, &req)
if err != nil {
return false, time.Time{}, 0, err