diff --git a/agent/agent.go b/agent/agent.go index 610aeb64f7..4d0246b997 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -295,8 +295,9 @@ func (a *Agent) Start() error { // regular and on-demand state synchronizations (anti-entropy). a.sync = ae.NewStateSyncer(a.State, c.AEInterval, a.shutdownCh, a.logger) - // create the cache + // create the cache and register types a.cache = cache.New(nil) + a.registerCache() // create the config for the rpc server/client consulCfg, err := a.consulConfig() @@ -334,9 +335,6 @@ func (a *Agent) Start() error { a.State.Delegate = a.delegate a.State.TriggerSyncChanges = a.sync.SyncChanges.Trigger - // Register the cache - a.registerCache() - // Load checks/services/metadata. if err := a.loadServices(c); err != nil { return err diff --git a/agent/cache-types/connect_ca_leaf.go b/agent/cache-types/connect_ca_leaf.go index 70d5e3c24e..c6a2eee735 100644 --- a/agent/cache-types/connect_ca_leaf.go +++ b/agent/cache-types/connect_ca_leaf.go @@ -98,7 +98,9 @@ func (c *ConnectCALeaf) Fetch(opts cache.FetchOptions, req cache.Request) (cache } // Create a CSR. - // TODO(mitchellh): This is obviously not production ready! + // TODO(mitchellh): This is obviously not production ready! The host + // needs a correct host ID, and we probably don't want to use TestCSR + // and want a non-test-specific way to create a CSR. csr, pk := connect.TestCSR(&testing.RuntimeT{}, &connect.SpiffeIDService{ Host: "1234.consul", Namespace: "default", diff --git a/agent/cache-types/intention_match_test.go b/agent/cache-types/intention_match_test.go index 97b2951b36..d94d7d9351 100644 --- a/agent/cache-types/intention_match_test.go +++ b/agent/cache-types/intention_match_test.go @@ -35,7 +35,7 @@ func TestIntentionMatch(t *testing.T) { MinIndex: 24, Timeout: 1 * time.Second, }, &structs.IntentionQueryRequest{Datacenter: "dc1"}) - require.Nil(err) + require.NoError(err) require.Equal(cache.FetchResult{ Value: resp, Index: 48, @@ -51,7 +51,7 @@ func TestIntentionMatch_badReqType(t *testing.T) { // Fetch _, err := typ.Fetch(cache.FetchOptions{}, cache.TestRequest( t, cache.RequestInfo{Key: "foo", MinIndex: 64})) - require.NotNil(err) + require.Error(err) require.Contains(err.Error(), "wrong type") } diff --git a/agent/cache/cache.go b/agent/cache/cache.go index a5aa575d83..cdcaffc58c 100644 --- a/agent/cache/cache.go +++ b/agent/cache/cache.go @@ -187,7 +187,7 @@ func (c *Cache) Get(t string, r Request) (interface{}, error) { // First time through first := true - // timeoutCh for watching our tmeout + // timeoutCh for watching our timeout var timeoutCh <-chan time.Time RETRY_GET: diff --git a/agent/cache/request.go b/agent/cache/request.go index 7cd53df256..6a20a9c1f3 100644 --- a/agent/cache/request.go +++ b/agent/cache/request.go @@ -18,7 +18,7 @@ type Request interface { // cacheability. type RequestInfo struct { // Key is a unique cache key for this request. This key should - // absolutely uniquely identify this request, since any conflicting + // be globally unique to identify this request, since any conflicting // cache keys could result in invalid data being returned from the cache. // The Key does not need to include ACL or DC information, since the // cache already partitions by these values prior to using this key. diff --git a/agent/cache/type.go b/agent/cache/type.go index cccb10b94f..b4f630d2bf 100644 --- a/agent/cache/type.go +++ b/agent/cache/type.go @@ -4,12 +4,12 @@ import ( "time" ) -// Type implement the logic to fetch certain types of data. +// Type implements the logic to fetch certain types of data. type Type interface { // Fetch fetches a single unique item. // // The FetchOptions contain the index and timeouts for blocking queries. - // The CacheMinIndex value on the Request itself should NOT be used + // The MinIndex value on the Request itself should NOT be used // as the blocking index since a request may be reused multiple times // as part of Refresh behavior. // diff --git a/agent/structs/intention.go b/agent/structs/intention.go index 6ad1a98359..5c6b1e991e 100644 --- a/agent/structs/intention.go +++ b/agent/structs/intention.go @@ -270,7 +270,7 @@ func (q *IntentionQueryRequest) RequestDatacenter() string { return q.Datacenter } -// cache.Request impl. +// CacheInfo implements cache.Request func (q *IntentionQueryRequest) CacheInfo() cache.RequestInfo { // We only support caching Match queries, so if Match isn't set, // then return an empty info object which will cause a pass-through @@ -294,7 +294,7 @@ func (q *IntentionQueryRequest) CacheInfo() cache.RequestInfo { // If there is an error, we don't set the key. A blank key forces // no cache for this request so the request is forwarded directly // to the server. - info.Key = strconv.FormatUint(v, 10) + info.Key = strconv.FormatUint(v, 16) } return info