diff --git a/agent/consul/state/intention.go b/agent/consul/state/intention.go index 80a150cfa..a29b9f63f 100644 --- a/agent/consul/state/intention.go +++ b/agent/consul/state/intention.go @@ -106,11 +106,6 @@ func (s *Snapshot) Intentions() (structs.Intentions, error) { var ret structs.Intentions for wrapped := ixns.Next(); wrapped != nil; wrapped = ixns.Next() { - // Update precedence values for consistency (i.e. the object returned should - // be usable/comparable to the ones returned from Intentions() and Match() - // etc.) - ixn := wrapped.(*structs.Intention) - ixn.UpdatePrecedence() ret = append(ret, wrapped.(*structs.Intention)) } @@ -147,9 +142,7 @@ func (s *Store) Intentions(ws memdb.WatchSet) (uint64, structs.Intentions, error var results structs.Intentions for ixn := iter.Next(); ixn != nil; ixn = iter.Next() { - ixnReal := ixn.(*structs.Intention) - ixnReal.UpdatePrecedence() - results = append(results, ixnReal) + results = append(results, ixn.(*structs.Intention)) } // Sort by precedence just because that's nicer and probably what most clients @@ -180,6 +173,9 @@ func (s *Store) intentionSetTxn(tx *memdb.Txn, idx uint64, ixn *structs.Intentio return ErrMissingIntentionID } + // Ensure Precedence is populated correctly on "write" + ixn.UpdatePrecedence() + // Check for an existing intention existing, err := tx.First(intentionsTableName, "id", ixn.ID) if err != nil { @@ -324,9 +320,7 @@ func (s *Store) IntentionMatch(ws memdb.WatchSet, args *structs.IntentionQueryMa ws.Add(iter.WatchCh()) for ixn := iter.Next(); ixn != nil; ixn = iter.Next() { - ixnReal := ixn.(*structs.Intention) - ixnReal.UpdatePrecedence() - ixns = append(ixns, ixnReal) + ixns = append(ixns, ixn.(*structs.Intention)) } } diff --git a/agent/consul/state/intention_test.go b/agent/consul/state/intention_test.go index fc161cddb..3e7df561c 100644 --- a/agent/consul/state/intention_test.go +++ b/agent/consul/state/intention_test.go @@ -61,6 +61,7 @@ func TestStore_IntentionSetGet_basic(t *testing.T) { ModifyIndex: 1, }, } + expected.UpdatePrecedence() ws = memdb.NewWatchSet() idx, actual, err := s.IntentionGet(ws, ixn.ID)