Skip to content

Commit 97bb912

Browse files
committed
csi: CSIVolumeByID should not use prefix query
Callers of `CSIVolumeByID` are generally assuming they should receive a single volume. This potentially results in feasibility checking being performed against the wrong volume if a volume's ID is a prefix substring of other volume (for example: "test" and "testing").
1 parent b66a341 commit 97bb912

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nomad/state/state_store.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -2126,20 +2126,20 @@ func (s *StateStore) CSIVolumes(ws memdb.WatchSet) (memdb.ResultIterator, error)
21262126
func (s *StateStore) CSIVolumeByID(ws memdb.WatchSet, namespace, id string) (*structs.CSIVolume, error) {
21272127
txn := s.db.ReadTxn()
21282128

2129-
watchCh, obj, err := txn.FirstWatch("csi_volumes", "id_prefix", namespace, id)
2129+
obj, err := txn.First("csi_volumes", "id", namespace, id)
21302130
if err != nil {
2131-
return nil, fmt.Errorf("volume lookup failed: %s %v", id, err)
2131+
return nil, fmt.Errorf("volume lookup failed for %s: %v", id, err)
21322132
}
2133-
2134-
ws.Add(watchCh)
2135-
21362133
if obj == nil {
21372134
return nil, nil
21382135
}
2136+
vol, ok := obj.(*structs.CSIVolume)
2137+
if !ok {
2138+
return nil, fmt.Errorf("volume row conversion error")
2139+
}
21392140

21402141
// we return the volume with the plugins denormalized by default,
21412142
// because the scheduler needs them for feasibility checking
2142-
vol := obj.(*structs.CSIVolume)
21432143
return s.CSIVolumeDenormalizePluginsTxn(txn, vol.Copy())
21442144
}
21452145

0 commit comments

Comments
 (0)