From 3827919572ee3806f4ca6180b02e79eb4305340a Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Thu, 12 Oct 2023 18:38:27 -0700 Subject: [PATCH] fix: Remove ErrHTTPRouteMatchEmpty check for Xds IR (#1959) --- internal/ir/xds.go | 4 ---- internal/ir/xds_test.go | 26 ++------------------------ 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/internal/ir/xds.go b/internal/ir/xds.go index b2884c04fbe..e80a09769fe 100644 --- a/internal/ir/xds.go +++ b/internal/ir/xds.go @@ -31,7 +31,6 @@ var ( ErrTLSPrivateKey = errors.New("field PrivateKey must be specified") ErrHTTPRouteNameEmpty = errors.New("field Name must be specified") ErrHTTPRouteHostnameEmpty = errors.New("field Hostname must be specified") - ErrHTTPRouteMatchEmpty = errors.New("either PathMatch, HeaderMatches or QueryParamMatches fields must be specified") ErrDestinationNameEmpty = errors.New("field Name must be specified") ErrDestEndpointHostInvalid = errors.New("field Address must be a valid IP address") ErrDestEndpointPortInvalid = errors.New("field Port specified is invalid") @@ -317,9 +316,6 @@ func (h HTTPRoute) Validate() error { if h.Hostname == "" { errs = multierror.Append(errs, ErrHTTPRouteHostnameEmpty) } - if h.PathMatch == nil && (len(h.HeaderMatches) == 0) && (len(h.QueryParamMatches) == 0) { - errs = multierror.Append(errs, ErrHTTPRouteMatchEmpty) - } if h.PathMatch != nil { if err := h.PathMatch.Validate(); err != nil { errs = multierror.Append(errs, err) diff --git a/internal/ir/xds_test.go b/internal/ir/xds_test.go index 3eb36f36b39..1e91aaecfa2 100644 --- a/internal/ir/xds_test.go +++ b/internal/ir/xds_test.go @@ -43,13 +43,6 @@ var ( Hostnames: []string{"example.com"}, Routes: []*HTTPRoute{&happyHTTPRoute}, } - invalidRouteMatchHTTPListener = HTTPListener{ - Name: "invalid-route-match", - Address: "0.0.0.0", - Port: 80, - Hostnames: []string{"example.com"}, - Routes: []*HTTPRoute{&emptyMatchHTTPRoute}, - } invalidBackendHTTPListener = HTTPListener{ Name: "invalid-backend-match", Address: "0.0.0.0", @@ -146,11 +139,6 @@ var ( }, Destination: &happyRouteDestination, } - emptyMatchHTTPRoute = HTTPRoute{ - Name: "empty-match", - Hostname: "*", - Destination: &happyRouteDestination, - } invalidBackendHTTPRoute = HTTPRoute{ Name: "invalid-backend", Hostname: "*", @@ -510,9 +498,9 @@ func TestValidateXds(t *testing.T) { { name: "invalid listener", input: Xds{ - HTTP: []*HTTPListener{&happyHTTPListener, &invalidAddrHTTPListener, &invalidRouteMatchHTTPListener}, + HTTP: []*HTTPListener{&happyHTTPListener, &invalidAddrHTTPListener}, }, - want: []error{ErrListenerAddressInvalid, ErrHTTPRouteMatchEmpty}, + want: []error{ErrListenerAddressInvalid}, }, { name: "invalid backend", @@ -579,11 +567,6 @@ func TestValidateHTTPListener(t *testing.T) { }, want: []error{ErrListenerPortInvalid, ErrHTTPListenerHostnamesEmpty}, }, - { - name: "invalid route match", - input: invalidRouteMatchHTTPListener, - want: []error{ErrHTTPRouteMatchEmpty}, - }, } for _, test := range tests { test := test @@ -837,11 +820,6 @@ func TestValidateHTTPRoute(t *testing.T) { }, want: []error{ErrHTTPRouteHostnameEmpty}, }, - { - name: "empty match", - input: emptyMatchHTTPRoute, - want: []error{ErrHTTPRouteMatchEmpty}, - }, { name: "invalid backend", input: invalidBackendHTTPRoute,