From c833464daf95b7a3e965c497afa0e766038d0ec5 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Tue, 28 Mar 2023 11:23:49 -0400 Subject: [PATCH] Update normalization of route refs (#16789) * Use merge of enterprise meta's rather than new custom method * Add merge logic for tcp routes * Add changelog * Normalize certificate refs on gateways * Fix infinite call loop * Explicitly call enterprise meta --- .changelog/16789.txt | 3 +++ agent/structs/config_entry_gateways.go | 3 +++ agent/structs/config_entry_routes.go | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changelog/16789.txt diff --git a/.changelog/16789.txt b/.changelog/16789.txt new file mode 100644 index 0000000000..ed25e11bbb --- /dev/null +++ b/.changelog/16789.txt @@ -0,0 +1,3 @@ +```release-note:bug +gateway: **(Enterprise only)** Fix bug where parent refs and service refs for a route in the same namespace as the route would fallback to the default namespace if the namespace was not specified in the configuration rather than falling back to the routes namespace. +``` diff --git a/agent/structs/config_entry_gateways.go b/agent/structs/config_entry_gateways.go index 5309af35ad..32fd966f60 100644 --- a/agent/structs/config_entry_gateways.go +++ b/agent/structs/config_entry_gateways.go @@ -755,6 +755,7 @@ func (e *APIGatewayConfigEntry) Normalize() error { if cert.Kind == "" { cert.Kind = InlineCertificate } + cert.EnterpriseMeta.Merge(e.GetEnterpriseMeta()) cert.EnterpriseMeta.Normalize() listener.TLS.Certificates[i] = cert @@ -985,11 +986,13 @@ func (e *BoundAPIGatewayConfigEntry) GetMeta() map[string]string { return e.Meta func (e *BoundAPIGatewayConfigEntry) Normalize() error { for i, listener := range e.Listeners { for j, route := range listener.Routes { + route.EnterpriseMeta.Merge(&e.EnterpriseMeta) route.EnterpriseMeta.Normalize() listener.Routes[j] = route } for j, cert := range listener.Certificates { + cert.EnterpriseMeta.Merge(&e.EnterpriseMeta) cert.EnterpriseMeta.Normalize() listener.Certificates[j] = cert diff --git a/agent/structs/config_entry_routes.go b/agent/structs/config_entry_routes.go index 70a3065598..ca092c07d1 100644 --- a/agent/structs/config_entry_routes.go +++ b/agent/structs/config_entry_routes.go @@ -81,6 +81,7 @@ func (e *HTTPRouteConfigEntry) Normalize() error { if parent.Kind == "" { parent.Kind = APIGateway } + parent.EnterpriseMeta.Merge(e.GetEnterpriseMeta()) parent.EnterpriseMeta.Normalize() e.Parents[i] = parent } @@ -91,7 +92,7 @@ func (e *HTTPRouteConfigEntry) Normalize() error { } for j, service := range rule.Services { - rule.Services[j] = normalizeHTTPService(service) + rule.Services[j] = e.normalizeHTTPService(service) } e.Rules[i] = rule } @@ -99,7 +100,8 @@ func (e *HTTPRouteConfigEntry) Normalize() error { return nil } -func normalizeHTTPService(service HTTPService) HTTPService { +func (e *HTTPRouteConfigEntry) normalizeHTTPService(service HTTPService) HTTPService { + service.EnterpriseMeta.Merge(e.GetEnterpriseMeta()) service.EnterpriseMeta.Normalize() if service.Weight <= 0 { service.Weight = 1 @@ -507,11 +509,13 @@ func (e *TCPRouteConfigEntry) Normalize() error { if parent.Kind == "" { parent.Kind = APIGateway } + parent.EnterpriseMeta.Merge(e.GetEnterpriseMeta()) parent.EnterpriseMeta.Normalize() e.Parents[i] = parent } for i, service := range e.Services { + service.EnterpriseMeta.Merge(e.GetEnterpriseMeta()) service.EnterpriseMeta.Normalize() e.Services[i] = service }