Prevent requests without UpstreamIDs from being flagged as legacy.

New clients in transparent proxy mode can send requests for service
config resolution without any upstream args because they do not have
explicitly defined upstreams.

Old clients on the other hand will never send requests without the
Upstreams args unless they don't have upstreams, in which case we do not
send back upstream config.
This commit is contained in:
freddygv 2021-03-19 19:59:00 -06:00
parent 2b49cc39ed
commit 24ee8a0488
1 changed files with 4 additions and 3 deletions

View File

@ -410,13 +410,14 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
upstreamIDs := args.UpstreamIDs upstreamIDs := args.UpstreamIDs
legacyUpstreams := false legacyUpstreams := false
// Before Consul namespaces were released, the Upstreams provided to the endpoint did not contain the namespace. // The request is considered legacy if the deprecated args.Upstream was used
// Because of this we attach the enterprise meta of the request, which will just be the default namespace. if len(upstreamIDs) == 0 && len(args.Upstreams) > 0 {
if len(upstreamIDs) == 0 {
legacyUpstreams = true legacyUpstreams = true
upstreamIDs = make([]structs.ServiceID, 0) upstreamIDs = make([]structs.ServiceID, 0)
for _, upstream := range args.Upstreams { for _, upstream := range args.Upstreams {
// Before Consul namespaces were released, the Upstreams provided to the endpoint did not contain the namespace.
// Because of this we attach the enterprise meta of the request, which will just be the default namespace.
sid := structs.NewServiceID(upstream, &args.EnterpriseMeta) sid := structs.NewServiceID(upstream, &args.EnterpriseMeta)
upstreamIDs = append(upstreamIDs, sid) upstreamIDs = append(upstreamIDs, sid)
} }