Skip to content

Commit

Permalink
conformance: Enable HTTPRouteBackendProtocolH2C conformance test (#2136)
Browse files Browse the repository at this point in the history
* nit

Signed-off-by: zirain <zirain2009@gmail.com>

* build Cluster depends on route type and service appProtocol

Signed-off-by: zirain <zirain2009@gmail.com>

* enable HTTPRouteBackendProtocolH2C conformance test

Signed-off-by: zirain <zirain2009@gmail.com>

* lint

Signed-off-by: zirain <zirain2009@gmail.com>

* fix

Signed-off-by: zirain <zirain2009@gmail.com>

* address comment

Signed-off-by: zirain <zirain2009@gmail.com>

* move to package internal/ir

Signed-off-by: zirain <zirain2009@gmail.com>

---------

Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain authored Nov 1, 2023
1 parent 6e81fb3 commit 6d532c1
Show file tree
Hide file tree
Showing 99 changed files with 212 additions and 35 deletions.
30 changes: 27 additions & 3 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/discovery/v1"
discoveryv1 "k8s.io/api/discovery/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a1 "sigs.k8s.io/gateway-api/apis/v1alpha2"
Expand Down Expand Up @@ -1005,6 +1005,7 @@ func (t *Translator) processDestination(backendRef gwapiv1.BackendRef,
}

var endpoints []*ir.DestinationEndpoint
protocol := inspectAppProtocolByRouteKind(routeType)
switch KindDerefOr(backendRef.Kind, KindService) {
case KindServiceImport:
serviceImport := resources.GetServiceImport(backendNamespace, string(backendRef.Name))
Expand Down Expand Up @@ -1037,12 +1038,18 @@ func (t *Translator) processDestination(backendRef gwapiv1.BackendRef,
}
}

// support HTTPRouteBackendProtocolH2C
if servicePort.AppProtocol != nil &&
*servicePort.AppProtocol == "kubernetes.io/h2c" {
protocol = ir.HTTP2
}

// Route to endpoints by default
if !t.EndpointRoutingDisabled {
endpointSlices := resources.GetEndpointSlicesForBackend(backendNamespace, string(backendRef.Name), KindDerefOr(backendRef.Kind, KindService))
endpoints = getIREndpointsFromEndpointSlice(endpointSlices, servicePort.Name, servicePort.Protocol)
} else {
// Fall back to Service CluserIP routing
// Fall back to Service ClusterIP routing
ep := ir.NewDestEndpoint(
service.Spec.ClusterIP,
uint32(*backendRef.Port))
Expand All @@ -1052,11 +1059,28 @@ func (t *Translator) processDestination(backendRef gwapiv1.BackendRef,

ds = &ir.DestinationSetting{
Weight: &weight,
Protocol: protocol,
Endpoints: endpoints,
}
return ds, weight
}

func inspectAppProtocolByRouteKind(kind gwapiv1.Kind) ir.AppProtocol {
switch kind {
case KindUDPRoute:
return ir.UDP
case KindHTTPRoute:
return ir.HTTP
case KindTCPRoute:
return ir.TCP
case KindGRPCRoute:
return ir.GRPC
case KindTLSRoute:
return ir.HTTPS
}
return ir.TCP
}

// processAllowedListenersForParentRefs finds out if the route attaches to one of our
// Gateways' listeners, and if so, gets the list of listeners that allow it to
// attach for each parentRef.
Expand Down Expand Up @@ -1127,7 +1151,7 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont
return relevantRoute
}

func getIREndpointsFromEndpointSlice(endpointSlices []*v1.EndpointSlice, portName string, portProtocol corev1.Protocol) []*ir.DestinationEndpoint {
func getIREndpointsFromEndpointSlice(endpointSlices []*discoveryv1.EndpointSlice, portName string, portProtocol corev1.Protocol) []*ir.DestinationEndpoint {
endpoints := []*ir.DestinationEndpoint{}
for _, endpointSlice := range endpointSlices {
for _, endpoint := range endpointSlice.Endpoints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
loadBalancer:
Expand All @@ -274,6 +275,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: gateway.envoyproxy.io
loadBalancer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
name: grpcroute/default/grpcroute-1/rule/0/match/-1/*
Expand Down Expand Up @@ -302,6 +303,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: gateway.envoyproxy.io
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
extensionRefs:
- object:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/envoy-gateway/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: foo.bar.com
name: httproute/default/httproute-1/rule/0/match/0/foo_bar_com
Expand All @@ -203,6 +204,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTPS
weight: 1
name: envoy-gateway/gateway-1/tls-passthrough/tlsroute-1
port: 10090
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp/tcproute-1
port: 10162
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp/udproute-1
port: 10162
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp1/tcproute-1
port: 10162
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp1/udproute-1
port: 10162
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: foo.com
name: httproute/default/httproute-2/rule/0/match/0/foo_com
Expand All @@ -196,6 +197,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: foo.com
name: httproute/default/httproute-1/rule/0/match/0/foo_com
Expand All @@ -219,6 +221,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: bar.com
name: httproute/default/httproute-2/rule/0/match/0/bar_com
Expand All @@ -235,6 +238,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: bar.com
name: httproute/default/httproute-1/rule/0/match/0/bar_com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand All @@ -190,6 +191,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp/tcproute-1
port: 10080
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: '*'
name: httproute/default/httproute-1/rule/0/match/0/*
Expand All @@ -190,6 +191,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp/udproute-1
port: 10080
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp1/tcproute-1
port: 10162
Expand All @@ -174,6 +175,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp2/tcproute-2
port: 10163
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp1/tcproute-1
port: 10161
Expand All @@ -170,6 +171,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8163
protocol: TCP
weight: 1
name: envoy-gateway/gateway-1/tcp2/tcproute-1
port: 10162
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp1/udproute-1
port: 10162
Expand All @@ -173,6 +174,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp2/udproute-2
port: 10163
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp1/udproute-1
port: 10161
Expand All @@ -169,6 +170,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp2/udproute-1
port: 10162
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
headerMatches:
- distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
Expand All @@ -135,6 +136,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
name: grpcroute/default/grpcroute-1/rule/0/match/1/*
Expand All @@ -133,6 +134,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
headerMatches:
- distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ xdsIR:
- endpoints:
- host: 7.7.7.7
port: 8080
protocol: GRPC
weight: 1
hostname: '*'
name: grpcroute/default/grpcroute-1/rule/0/match/-1/*
Loading

0 comments on commit 6d532c1

Please sign in to comment.