Skip to content

Commit

Permalink
test(conformance): pass GRPCRoute conformance test
Browse files Browse the repository at this point in the history
Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
  • Loading branch information
tao12345666333 committed May 18, 2024
1 parent 6081f65 commit 1c6a1cb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Adding a new version? You'll need three changes:
performance benefits, however, so labeling plugin configuration Secrets and
enabling the filter is recommended as soon as is convenient.
[#5856](https://github.com/Kong/kubernetes-ingress-controller/pull/5856)
- Dynamically set the proxy protocol of GRPCRoute to `grpc` or `grpcs` based on the port listened by Gateway.
If you don't set the protocol for Service via "konghq.com/protocol" annotation, Kong will use grpc instead of grpcs.
[#5776](https://github.com/Kong/kubernetes-ingress-controller/pull/5776)

### Added

Expand Down Expand Up @@ -158,6 +161,8 @@ Adding a new version? You'll need three changes:
[#5965](https://github.com/Kong/kubernetes-ingress-controller/pull/5965)
- Fallback configuration no longer omits licenses and vaults.
[#6048](https://github.com/Kong/kubernetes-ingress-controller/pull/6048)
- Add support for pass Kubernetes Gateway API GRPCRoute conformance test.
[#5776](https://github.com/Kong/kubernetes-ingress-controller/pull/5776)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/gateway/grpcroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func (r *GRPCRouteReconciler) ensureGatewayReferenceStatusAdded(ctx context.Cont

// if the reference already exists and doesn't require any changes
// then just leave it alone.
parentRefKey := gateway.gateway.Namespace + "/" + gateway.gateway.Name
parentRefKey := fmt.Sprintf("%s/%s/%s", gateway.gateway.Namespace, gateway.gateway.Name, gateway.listenerName)
if existingGatewayParentStatus, exists := parentStatuses[parentRefKey]; exists {
// check if the parentRef and controllerName are equal, and whether the new condition is present in existing conditions
if reflect.DeepEqual(existingGatewayParentStatus.ParentRef, gatewayParentStatus.ParentRef) &&
Expand Down
5 changes: 5 additions & 0 deletions internal/controllers/gateway/route_parent_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func routeParentStatusKey[routeT gatewayapi.RouteT](
namespace,
parentRef.GetName(),
parentRef.GetSectionName().OrEmpty())
case *gatewayapi.GRPCRoute:
return fmt.Sprintf("%s/%s/%s",
namespace,
parentRef.GetName(),
parentRef.GetSectionName().OrEmpty())
default:
return fmt.Sprintf("%s/%s", namespace, parentRef.GetName())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/translator/translate_grpcroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func grpcBackendRefsToBackendRefs(grpcBackendRef []gatewayapi.GRPCBackendRef) []
return backendRefs
}

// getProtocolForKongService returns the protocol for the Kong service based on the Gateway listening ports
// getProtocolForKongService returns the protocol for the Kong service based on the Gateway listening ports.
func (t *Translator) getProtocolForKongService(grpcRoute *gatewayapi.GRPCRoute) string {
// When Gateway listens on HTTP use "grpc" protocol for the service. Otherwise for HTTPS use "grpcs".
if len(t.getGatewayListeningPorts(grpcRoute.Namespace, gatewayapi.HTTPProtocolType, grpcRoute.Spec.ParentRefs)) > 0 {
Expand Down
11 changes: 11 additions & 0 deletions test/conformance/gateway_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ import (
var skippedTestsForTraditionalRoutes = []string{
// core conformance
tests.HTTPRouteHeaderMatching.ShortName,
// Kong gateway does not support this feature
tests.GRPCRouteListenerHostnameMatching.ShortName,
}

var skippedTestsForExpressionRoutes = []string{
// core conformance
tests.HTTPRouteHeaderMatching.ShortName,
// Kong gateway does not support this feature
tests.GRPCRouteListenerHostnameMatching.ShortName,
}

var traditionalRoutesSupportedFeatures = []features.SupportedFeature{
// core features
features.SupportGateway,
features.SupportHTTPRoute,
features.SupportGRPCRoute,
// extended features
features.SupportHTTPRouteResponseHeaderModification,
features.SupportHTTPRoutePathRewrite,
Expand Down Expand Up @@ -71,6 +81,7 @@ func TestGatewayConformance(t *testing.T) {
supportedFeatures = traditionalRoutesSupportedFeatures
mode = string(dpconf.RouterFlavorTraditionalCompatible)
case dpconf.RouterFlavorExpressions:
skippedTests = skippedTestsForExpressionRoutes
supportedFeatures = expressionRoutesSupportedFeatures
mode = string(dpconf.RouterFlavorExpressions)
default:
Expand Down
4 changes: 4 additions & 0 deletions test/conformance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func TestMain(m *testing.M) {
kongBuilder = kongBuilder.WithProxyEnvVar("router_flavor", string(dpconf.RouterFlavorExpressions))
}

// The test cases for GRPCRoute in the current GatewayAPI all use the h2c protocol.
// In order to pass conformance tests, the proxy must listen http2 and http on the same port.
kongBuilder.WithProxyEnvVar("PROXY_LISTEN", `0.0.0.0:8000 http2\, 0.0.0.0:8443 http2 ssl`)

// Pin the Helm chart version.
kongBuilder.WithHelmChartVersion(testenv.KongHelmChartVersion())

Expand Down

0 comments on commit 1c6a1cb

Please sign in to comment.