Skip to content

Commit

Permalink
fix: move websocket config under config.route.v3.RouteAction
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Haka <haka.jesse@gmail.com>
  • Loading branch information
zetaab committed Feb 23, 2024
1 parent c5cd964 commit cd8aa99
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
StatusCode: 500,
}
}
ruleRoute.IsHTTP2 = false
}

// TODO handle:
Expand Down Expand Up @@ -495,6 +496,7 @@ func (t *Translator) processGRPCRouteRules(grpcRoute *GRPCRouteContext, parentRe
StatusCode: 500,
}
}
ruleRoute.IsHTTP2 = true
}

// TODO handle:
Expand Down Expand Up @@ -658,6 +660,7 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
ExtensionRefs: routeRoute.ExtensionRefs,
Timeout: routeRoute.Timeout,
Retry: routeRoute.Retry,
IsHTTP2: routeRoute.IsHTTP2,
}
// Don't bother copying over the weights unless the route has invalid backends.
if routeRoute.BackendWeights.Invalid > 0 {
Expand Down
2 changes: 2 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ type HTTPRoute struct {
Name string `json:"name" yaml:"name"`
// Hostname that the route matches against
Hostname string `json:"hostname" yaml:"hostname,omitempty"`
// IsHTTP2 is set if the route is configured to serve HTTP2 traffic
IsHTTP2 bool `json:"isHTTP2" yaml:"isHTTP2"`
// PathMatch defines the match conditions on the path.
PathMatch *StringMatch `json:"pathMatch,omitempty" yaml:"pathMatch,omitempty"`
// HeaderMatches define the match conditions on the request headers for this route.
Expand Down
8 changes: 0 additions & 8 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,6 @@ func (t *Translator) addXdsHTTPFilterChain(xdsListener *listenerv3.Listener, irL
mgr.HttpFilters = append(mgr.HttpFilters, xdsfilters.GRPCWeb)
// always enable grpc stats filter
mgr.HttpFilters = append(mgr.HttpFilters, xdsfilters.GRPCStats)
} else {
// Allow websocket upgrades for HTTP 1.1
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
mgr.UpgradeConfigs = []*hcmv3.HttpConnectionManager_UpgradeConfig{
{
UpgradeType: "websocket",
},
}
}

if http3Listener {
Expand Down
21 changes: 14 additions & 7 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) (*routev3.Route, error) {

router.Action = &routev3.Route_Route{Route: routeAction}
default:
routeAction := buildXdsRouteAction(httpRoute.Destination.Name)
if httpRoute.Mirrors != nil {
routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors)
}
if httpRoute.BackendWeights.Invalid != 0 {
// If there are invalid backends then a weighted cluster is required for the route
routeAction := buildXdsWeightedRouteAction(httpRoute)
routeAction = buildXdsWeightedRouteAction(httpRoute)
if httpRoute.Mirrors != nil {
routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors)
}
router.Action = &routev3.Route_Route{Route: routeAction}
} else {
routeAction := buildXdsRouteAction(httpRoute.Destination.Name)
if httpRoute.Mirrors != nil {
routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors)
}
if !httpRoute.IsHTTP2 {
// Allow websocket upgrades for HTTP 1.1
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
routeAction.UpgradeConfigs = []*routev3.RouteAction_UpgradeConfig{
{
UpgradeType: "websocket",
},
}
router.Action = &routev3.Route_Route{Route: routeAction}
}
router.Action = &routev3.Route_Route{Route: routeAction}
}

// Hash Policy
Expand Down

0 comments on commit cd8aa99

Please sign in to comment.