Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conformance: Enable HTTPRouteBackendProtocolH2C conformance test #2136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
}

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 @@
}
}

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

Check warning on line 1045 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L1044-L1045

Added lines #L1044 - L1045 were not covered by tests

// 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

Check warning on line 1052 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L1052

Added line #L1052 was not covered by tests
ep := ir.NewDestEndpoint(
service.Spec.ClusterIP,
uint32(*backendRef.Port))
Expand All @@ -1052,11 +1059,28 @@

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

Check warning on line 1081 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L1081

Added line #L1081 was not covered by tests
}

// 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 @@
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