From ef9d44fdfea254aa2819bb10cc317c73fffe44f6 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 18 Dec 2020 12:43:16 -0500 Subject: [PATCH] structs: fix caching of ServiceSpecificRequest when ingress=true The field was not being included in the cache info key. This would result in a DNS request for web.service.consul returning the same result as web.ingress.consul, when those results should not be the same. --- .changelog/9436.txt | 4 ++++ agent/structs/structs.go | 1 + agent/structs/structs_test.go | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changelog/9436.txt diff --git a/.changelog/9436.txt b/.changelog/9436.txt new file mode 100644 index 000000000..da0c22b8b --- /dev/null +++ b/.changelog/9436.txt @@ -0,0 +1,4 @@ +```release-note:bug +cache: Fixed a bug where a DNS or API request for an ingress gateway would incorrectly +return a cached result for a service request with the same name, and vice versa. +`` diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 389ee8153..9b9740c00 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -617,6 +617,7 @@ func (r *ServiceSpecificRequest) CacheInfo() cache.RequestInfo { r.Connect, r.Filter, r.EnterpriseMeta, + r.Ingress, }, nil) if err == nil { // If there is an error, we don't set the key. A blank key forces diff --git a/agent/structs/structs_test.go b/agent/structs/structs_test.go index 60abb12fb..f6a6f5ddd 100644 --- a/agent/structs/structs_test.go +++ b/agent/structs/structs_test.go @@ -1542,8 +1542,6 @@ func TestServiceSpecificRequestCacheInfoKey(t *testing.T) { ignoredFields := map[string]bool{ // TODO: should this filed be included? "ServiceKind": true, - // TODO: this filed should be included: github.com/hashicorp/consul/pull/9436 - "Ingress": true, } assertCacheInfoKeyIsComplete(t, &ServiceSpecificRequest{}, ignoredFields) @@ -1715,6 +1713,16 @@ func TestSpecificServiceRequest_CacheInfo(t *testing.T) { }, wantSame: false, }, + { + name: "with integress=true", + req: ServiceSpecificRequest{ + Datacenter: "dc1", + ServiceName: "my-service", + }, + mutate: func(req *ServiceSpecificRequest) { + req.Ingress = true + }, + }, } for _, tc := range tests {