Skip to content

Commit

Permalink
csi: CSIVolumeByID should not use prefix query
Browse files Browse the repository at this point in the history
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").
  • Loading branch information
tgross committed Mar 10, 2021
1 parent ded978c commit c327e47
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2126,20 +2126,20 @@ func (s *StateStore) CSIVolumes(ws memdb.WatchSet) (memdb.ResultIterator, error)
func (s *StateStore) CSIVolumeByID(ws memdb.WatchSet, namespace, id string) (*structs.CSIVolume, error) {
txn := s.db.ReadTxn()

watchCh, obj, err := txn.FirstWatch("csi_volumes", "id_prefix", namespace, id)
obj, err := txn.First("csi_volumes", "id", namespace, id)
if err != nil {
return nil, fmt.Errorf("volume lookup failed: %s %v", id, err)
return nil, fmt.Errorf("volume lookup failed for %s: %v", id, err)
}

ws.Add(watchCh)

if obj == nil {
return nil, nil
}
vol, ok := obj.(*structs.CSIVolume)
if !ok {
return nil, fmt.Errorf("volume row conversion error")
}

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

Expand Down

0 comments on commit c327e47

Please sign in to comment.