Skip to content

Commit 9c9f046

Browse files
committed
Check if ListSnapshots is supported during GetSnapshotStatus
1 parent c0658cb commit 9c9f046

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pkg/snapshotter/snapshotter.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,37 @@ func (s *snapshot) DeleteSnapshot(ctx context.Context, snapshotID string, snapsh
101101
return nil
102102
}
103103

104+
func (s *snapshot) isListSnapshotsSupported(ctx context.Context) (bool, error) {
105+
client := csi.NewControllerClient(s.conn)
106+
107+
capRsp, err := client.ControllerGetCapabilities(ctx, &csi.ControllerGetCapabilitiesRequest{})
108+
if err != nil {
109+
return false, err
110+
}
111+
112+
for _, cap := range capRsp.Capabilities {
113+
if cap.GetRpc().GetType() == csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS {
114+
return true, nil
115+
}
116+
}
117+
118+
return false, nil
119+
}
120+
104121
func (s *snapshot) GetSnapshotStatus(ctx context.Context, snapshotID string) (bool, time.Time, int64, error) {
105122
client := csi.NewControllerClient(s.conn)
106123

124+
// If the driver does not support ListSnapshots, assume the snapshot ID is valid.
125+
listSnapshotsSupported, err := s.isListSnapshotsSupported(ctx)
126+
if err != nil {
127+
return false, time.Time{}, 0, fmt.Errorf("failed to check if ListSnapshots is supported: %s", err.Error())
128+
}
129+
if !listSnapshotsSupported {
130+
return true, time.Time{}, 0, nil
131+
}
107132
req := csi.ListSnapshotsRequest{
108133
SnapshotId: snapshotID,
109134
}
110-
111135
rsp, err := client.ListSnapshots(ctx, &req)
112136
if err != nil {
113137
return false, time.Time{}, 0, err

0 commit comments

Comments
 (0)