Skip to content

Commit f889cab

Browse files
kvapsclaude
andcommitted
feat(rest): honour ?resources= and ?snapshots= filters on /v1/view/snapshots
Symmetric to the resources/storage-pools view filters. linstor-csi's "is there a snapshot for this volume?" lookup arrives as GET /v1/view/snapshots?resources=pvc-X&snapshots=snap-Y and Java LINSTOR honours both as case-insensitive set membership; we now match. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent b02d23d commit f889cab

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

pkg/rest/snapshots.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,29 @@ func (s *Server) handleSnapshotsView(w http.ResponseWriter, r *http.Request) {
4646
return
4747
}
4848

49-
writeJSON(w, http.StatusOK, snaps)
49+
// Optional filters golinstor sends: ?resources=rd1,rd2 &
50+
// snapshots=name1,name2 — case-insensitive set membership against
51+
// Java LINSTOR's behaviour. Without filtering linstor-csi's "do
52+
// any snapshots exist for this volume?" poll has to scan the
53+
// whole cluster every cycle.
54+
rdFilter := splitCSV(r.URL.Query().Get("resources"))
55+
nameFilter := splitCSV(r.URL.Query().Get("snapshots"))
56+
57+
out := make([]apiv1.Snapshot, 0, len(snaps))
58+
59+
for i := range snaps {
60+
if !matchAnyFold(rdFilter, snaps[i].ResourceName) {
61+
continue
62+
}
63+
64+
if !matchAnyFold(nameFilter, snaps[i].Name) {
65+
continue
66+
}
67+
68+
out = append(out, snaps[i])
69+
}
70+
71+
writeJSON(w, http.StatusOK, out)
5072
}
5173

5274
func (s *Server) handleSnapshotList(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)