From 7c510d5ebdc8669a2f4fa76e89a115243d961352 Mon Sep 17 00:00:00 2001 From: hejianpeng Date: Wed, 31 Aug 2022 10:28:59 +0800 Subject: [PATCH] translator: Gateway API Translator Should Support * Listener Hostnames Signed-off-by: hejianpeng --- ...lows-same-namespace-with-disallowed-httproute.out.yaml | 2 ++ internal/gatewayapi/translator.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/gatewayapi/testdata/gateway-allows-same-namespace-with-disallowed-httproute.out.yaml b/internal/gatewayapi/testdata/gateway-allows-same-namespace-with-disallowed-httproute.out.yaml index 3d0b7588b7..2926aea169 100644 --- a/internal/gatewayapi/testdata/gateway-allows-same-namespace-with-disallowed-httproute.out.yaml +++ b/internal/gatewayapi/testdata/gateway-allows-same-namespace-with-disallowed-httproute.out.yaml @@ -57,6 +57,8 @@ xdsIR: http: - name: envoy-gateway-gateway-1-http address: 0.0.0.0 + hostnames: + - "*" port: 80 infraIR: proxy: diff --git a/internal/gatewayapi/translator.go b/internal/gatewayapi/translator.go index 53c4bc6495..c0ee2e7a6a 100644 --- a/internal/gatewayapi/translator.go +++ b/internal/gatewayapi/translator.go @@ -428,6 +428,11 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR *ir.Xds, } if listener.Hostname != nil { irListener.Hostnames = append(irListener.Hostnames, string(*listener.Hostname)) + } else { + // Hostname specifies the virtual hostname to match for protocol types that define this concept. + // When unspecified, all hostnames are matched. This field is ignored for protocols that don’t require hostname based matching. + // see more https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.Listener. + irListener.Hostnames = append(irListener.Hostnames, "*") } xdsIR.HTTP = append(xdsIR.HTTP, irListener) @@ -692,9 +697,6 @@ func (t *Translator) ProcessHTTPRoutes(httpRoutes []*v1beta1.HTTPRoute, gateways } irListener := xdsIR.GetListener(irListenerName(listener)) - if len(irListener.Hostnames) == 0 { - irListener.Hostnames = hosts - } irListener.Routes = append(irListener.Routes, perHostRoutes...) // Theoretically there should only be one parent ref per