diff --git a/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.in.yaml b/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.in.yaml index e1ed619de393..4eb7e6f739c6 100644 --- a/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.in.yaml +++ b/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.in.yaml @@ -30,7 +30,7 @@ httpRoutes: backendRefs: - name: service-1 port: 8080 - weight: 1 + weight: 8 filters: - type: RequestHeaderModifier requestHeaderModifier: @@ -39,16 +39,19 @@ httpRoutes: value: "some-value" - name: "add-header-2" value: "some-value" - - type: RequestHeaderModifier - requestHeaderModifier: - add: - - name: "add-header-1" - value: "some-value" - - name: "add-header-3" - value: "some-value" - name: service-2 port: 8080 weight: 2 + - matches: + - path: + value: "/foo" + backendRefs: - name: service-3 port: 8080 - weight: 3 + weight: 1 + filters: + - type: RequestHeaderModifier + requestHeaderModifier: + set: + - name: "add-header-3" + value: "some-value" diff --git a/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.out.yaml b/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.out.yaml index 7976ef4c8c48..5971006c8503 100755 --- a/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.out.yaml +++ b/internal/gatewayapi/testdata/httproute-with-backendref-add-multiple-filters.out.yaml @@ -60,26 +60,30 @@ httpRoutes: - name: add-header-2 value: some-value type: RequestHeaderModifier - - requestHeaderModifier: - add: - - name: add-header-1 - value: some-value - - name: add-header-3 - value: some-value - type: RequestHeaderModifier name: service-1 port: 8080 - weight: 1 + weight: 8 - name: service-2 port: 8080 weight: 2 - - name: service-3 - port: 8080 - weight: 3 matches: - path: value: / sessionPersistence: null + - backendRefs: + - filters: + - requestHeaderModifier: + set: + - name: add-header-3 + value: some-value + type: RequestHeaderModifier + name: service-3 + port: 8080 + weight: 1 + matches: + - path: + value: /foo + sessionPersistence: null status: parents: - conditions: @@ -131,9 +135,9 @@ xdsIR: routes: - backendWeights: invalid: 0 - valid: 6 + valid: 1 destination: - name: httproute/default/httproute-1/rule/0 + name: httproute/default/httproute-1/rule/1 settings: - addressType: IP endpoints: @@ -141,31 +145,45 @@ xdsIR: port: 8080 filters: addRequestHeaders: - - append: true - name: add-header-1 - value: some-value - - append: true - name: add-header-2 - value: some-value - - append: true + - append: false name: add-header-3 value: some-value protocol: HTTP weight: 1 + hostname: '*' + isHTTP2: false + name: httproute/default/httproute-1/rule/1/match/0/* + pathMatch: + distinct: false + name: "" + prefix: /foo + - backendWeights: + invalid: 0 + valid: 10 + destination: + name: httproute/default/httproute-1/rule/0 + settings: - addressType: IP endpoints: - host: 7.7.7.7 port: 8080 - filters: {} + filters: + addRequestHeaders: + - append: true + name: add-header-1 + value: some-value + - append: true + name: add-header-2 + value: some-value protocol: HTTP - weight: 2 + weight: 8 - addressType: IP endpoints: - host: 7.7.7.7 port: 8080 filters: {} protocol: HTTP - weight: 3 + weight: 2 hostname: '*' isHTTP2: false name: httproute/default/httproute-1/rule/0/match/0/* diff --git a/internal/xds/translator/route.go b/internal/xds/translator/route.go index 3837f0f5a822..bbdbf6b4f74d 100644 --- a/internal/xds/translator/route.go +++ b/internal/xds/translator/route.go @@ -72,7 +72,7 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) (*routev3.Route, error) { router.Action = &routev3.Route_Route{Route: routeAction} default: var routeAction *routev3.RouteAction - if httpRoute.BackendWeights.Invalid != 0 || httpRoute.BackendWeights.Valid > 1 { + if hasFiltersInSettings(httpRoute.Destination.Settings) || httpRoute.BackendWeights.Invalid != 0 { // If there are backend weights stored then a weighted cluster is required for the route routeAction = buildXdsWeightedRouteAction(httpRoute) } else { @@ -272,8 +272,8 @@ func buildXdsWeightedRouteAction(httpRoute *ir.HTTPRoute) *routev3.RouteAction { validCluster.ResponseHeadersToRemove = append(validCluster.ResponseHeadersToRemove, destinationSetting.Filters.RemoveResponseHeaders...) } } + weightedClusters = append(weightedClusters, validCluster) } - weightedClusters = append(weightedClusters, validCluster) return &routev3.RouteAction{ // Intentionally route to a non-existent cluster and return a 500 error when it is not found @@ -597,3 +597,13 @@ func buildRetryOn(triggers []ir.TriggerEnum) (string, error) { return b.String(), nil } + +func hasFiltersInSettings(settings []*ir.DestinationSetting) bool { + for _, setting := range settings { + filters := setting.Filters + if filters != nil { + return true + } + } + return false +} diff --git a/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend-with-filters.yaml b/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend-with-filters.yaml index 940ba1eb0bc4..4dcc8aae5ce1 100644 --- a/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend-with-filters.yaml +++ b/internal/xds/translator/testdata/in/xds-ir/http-route-weighted-backend-with-filters.yaml @@ -1,45 +1,62 @@ http: -- name: "first-listener" - address: "0.0.0.0" - port: 10080 - hostnames: - - "*" - path: - mergeSlashes: true - escapedSlashesAction: UnescapeAndRedirect - routes: - - name: "first-route" - backendWeights: - invalid: 0 - valid: 20 - hostname: "*" - destination: - name: "first-route-dest" - settings: - - endpoints: - - host: "1.1.1.1" - port: 50001 - weight: 20 - filters: - addRequestHeaders: - - append: true - name: add-header-1 - value: some-value - - append: true - name: add-header-2 - value: some-value - - append: true - name: add-header-3 - value: some-value - - endpoints: - - host: "2.2.2.2" - port: 50002 - weight: 40 - - endpoints: - - host: "3.3.3.3" - port: 50003 - weight: 20 - - endpoints: - - host: "4.4.4.4" - port: 50004 - weight: 20 + - name: "first-listener" + address: "0.0.0.0" + hostnames: + - '*' + path: + escapedSlashesAction: UnescapeAndRedirect + mergeSlashes: true + port: 10080 + routes: + - backendWeights: + invalid: 0 + valid: 1 + destination: + name: "first-route-dest" + settings: + - addressType: IP + endpoints: + - host: 1.1.1.1 + port: 8080 + filters: + addRequestHeaders: + - append: false + name: add-header-3 + value: some-value + protocol: HTTP + weight: 1 + hostname: '*' + name: "first-route" + pathMatch: + prefix: /foo + - backendWeights: + invalid: 0 + valid: 10 + destination: + name: "second-route-dest" + settings: + - addressType: IP + endpoints: + - host: 2.2.2.2 + port: 8080 + filters: + addRequestHeaders: + - append: true + name: add-header-1 + value: some-value + - append: true + name: add-header-2 + value: some-value + protocol: HTTP + weight: 8 + - addressType: IP + endpoints: + - host: 3.3.3.3 + port: 8080 + filters: {} + protocol: HTTP + weight: 2 + hostname: '*' + name: "second-route" + pathMatch: + prefix: / diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.clusters.yaml index d53a7a1b2ce5..d65e267ad7de 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.clusters.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.clusters.yaml @@ -15,3 +15,20 @@ outlierDetection: {} perConnectionBufferLimitBytes: 32768 type: EDS +- circuitBreakers: + thresholds: + - maxRetries: 1024 + commonLbConfig: + localityWeightedLbConfig: {} + connectTimeout: 10s + dnsLookupFamily: V4_ONLY + edsClusterConfig: + edsConfig: + ads: {} + resourceApiVersion: V3 + serviceName: second-route-dest + lbPolicy: LEAST_REQUEST + name: second-route-dest + outlierDetection: {} + perConnectionBufferLimitBytes: 32768 + type: EDS diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.endpoints.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.endpoints.yaml index f5633bd158e3..261bcf04f941 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.endpoints.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.endpoints.yaml @@ -5,38 +5,30 @@ address: socketAddress: address: 1.1.1.1 - portValue: 50001 + portValue: 8080 loadBalancingWeight: 1 - loadBalancingWeight: 20 + loadBalancingWeight: 1 locality: region: first-route-dest/backend/0 +- clusterName: second-route-dest + endpoints: - lbEndpoints: - endpoint: address: socketAddress: address: 2.2.2.2 - portValue: 50002 + portValue: 8080 loadBalancingWeight: 1 - loadBalancingWeight: 40 + loadBalancingWeight: 8 locality: - region: first-route-dest/backend/1 + region: second-route-dest/backend/0 - lbEndpoints: - endpoint: address: socketAddress: address: 3.3.3.3 - portValue: 50003 - loadBalancingWeight: 1 - loadBalancingWeight: 20 - locality: - region: first-route-dest/backend/2 - - lbEndpoints: - - endpoint: - address: - socketAddress: - address: 4.4.4.4 - portValue: 50004 + portValue: 8080 loadBalancingWeight: 1 - loadBalancingWeight: 20 + loadBalancingWeight: 2 locality: - region: first-route-dest/backend/3 + region: second-route-dest/backend/1 diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.routes.yaml index 7e08c106f81f..10bba14aedbf 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-weighted-backend-with-filters.routes.yaml @@ -6,7 +6,7 @@ name: first-listener/* routes: - match: - prefix: / + pathSeparatedPrefix: /foo name: first-route route: clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR @@ -15,6 +15,22 @@ weightedClusters: clusters: - name: first-route-dest + requestHeadersToAdd: + - appendAction: OVERWRITE_IF_EXISTS_OR_ADD + header: + key: add-header-3 + value: some-value + weight: 1 + - match: + prefix: / + name: second-route + route: + clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR + upgradeConfigs: + - upgradeType: websocket + weightedClusters: + clusters: + - name: second-route-dest requestHeadersToAdd: - header: key: add-header-1 @@ -22,7 +38,13 @@ - header: key: add-header-2 value: some-value + weight: 10 + - name: second-route-dest + requestHeadersToAdd: - header: - key: add-header-3 + key: add-header-1 + value: some-value + - header: + key: add-header-2 value: some-value - weight: 20 + weight: 10