Skip to content

Commit

Permalink
csi: fix watches on volumes
Browse files Browse the repository at this point in the history
Add missing nil checks and missing watch `Add` calls on some state store
methods for CSI volumes
  • Loading branch information
tgross committed Nov 24, 2020
1 parent 61c462e commit 879acb6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,9 @@ func (s *StateStore) CSIVolumeByID(ws memdb.WatchSet, namespace, id string) (*st
if err != nil {
return nil, fmt.Errorf("volume lookup failed: %s %v", id, err)
}
ws.Add(watchCh)
if ws != nil {
ws.Add(watchCh)
}

if obj == nil {
return nil, nil
Expand Down Expand Up @@ -2208,6 +2210,7 @@ func (s *StateStore) CSIVolumesByNodeID(ws memdb.WatchSet, nodeID string) (memdb
}
iter.Add(raw)
}
ws.Add(iter.WatchCh())

return iter, nil
}
Expand All @@ -2229,7 +2232,6 @@ func (s *StateStore) CSIVolumesByNamespace(ws memdb.WatchSet, namespace string)
func (s *StateStore) CSIVolumeClaim(index uint64, namespace, id string, claim *structs.CSIVolumeClaim) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
ws := memdb.NewWatchSet()

row, err := txn.First("csi_volumes", "id", namespace, id)
if err != nil {
Expand All @@ -2246,7 +2248,7 @@ func (s *StateStore) CSIVolumeClaim(index uint64, namespace, id string, claim *s

var alloc *structs.Allocation
if claim.State == structs.CSIVolumeClaimStateTaken {
alloc, err = s.AllocByID(ws, claim.AllocationID)
alloc, err = s.allocByIDImpl(txn, nil, claim.AllocationID)
if err != nil {
s.logger.Error("AllocByID failed", "error", err)
return fmt.Errorf(structs.ErrUnknownAllocationPrefix)
Expand Down

0 comments on commit 879acb6

Please sign in to comment.