From 42e1f2c9b14a31afb92c0b6b04bff0b0c0b0b0a9 Mon Sep 17 00:00:00 2001 From: Romain Date: Tue, 17 Sep 2024 16:40:04 +0200 Subject: [PATCH] Add supported features to the Gateway API GatewayClass status --- integration/k8s_conformance_test.go | 20 ++-------------- pkg/provider/kubernetes/gateway/features.go | 23 +++++++++++++++++++ pkg/provider/kubernetes/gateway/kubernetes.go | 7 ++++++ 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 pkg/provider/kubernetes/gateway/features.go diff --git a/integration/k8s_conformance_test.go b/integration/k8s_conformance_test.go index 56c1e07f8..b42112ba4 100644 --- a/integration/k8s_conformance_test.go +++ b/integration/k8s_conformance_test.go @@ -18,6 +18,7 @@ import ( "github.com/testcontainers/testcontainers-go/modules/k3s" "github.com/testcontainers/testcontainers-go/network" "github.com/traefik/traefik/v3/integration/try" + "github.com/traefik/traefik/v3/pkg/provider/kubernetes/gateway" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/util/sets" kclientset "k8s.io/client-go/kubernetes" @@ -33,7 +34,6 @@ import ( "sigs.k8s.io/gateway-api/conformance/tests" "sigs.k8s.io/gateway-api/conformance/utils/config" ksuite "sigs.k8s.io/gateway-api/conformance/utils/suite" - "sigs.k8s.io/gateway-api/pkg/features" "sigs.k8s.io/yaml" ) @@ -199,23 +199,7 @@ func (s *K8sConformanceSuite) TestK8sGatewayAPIConformance() { ksuite.GatewayGRPCConformanceProfileName, ksuite.GatewayTLSConformanceProfileName, ), - SupportedFeatures: sets.New( - features.SupportGateway, - features.SupportGatewayPort8080, - features.SupportGRPCRoute, - features.SupportHTTPRoute, - features.SupportHTTPRouteQueryParamMatching, - features.SupportHTTPRouteMethodMatching, - features.SupportHTTPRoutePortRedirect, - features.SupportHTTPRouteSchemeRedirect, - features.SupportHTTPRouteHostRewrite, - features.SupportHTTPRoutePathRewrite, - features.SupportHTTPRoutePathRedirect, - features.SupportHTTPRouteResponseHeaderModification, - features.SupportTLSRoute, - features.SupportHTTPRouteBackendProtocolH2C, - features.SupportHTTPRouteBackendProtocolWebSocket, - ), + SupportedFeatures: sets.New(gateway.SupportedFeatures()...), }) require.NoError(s.T(), err) diff --git a/pkg/provider/kubernetes/gateway/features.go b/pkg/provider/kubernetes/gateway/features.go new file mode 100644 index 000000000..6d95c54d7 --- /dev/null +++ b/pkg/provider/kubernetes/gateway/features.go @@ -0,0 +1,23 @@ +package gateway + +import "sigs.k8s.io/gateway-api/pkg/features" + +func SupportedFeatures() []features.SupportedFeature { + return []features.SupportedFeature{ + features.SupportGateway, + features.SupportGatewayPort8080, + features.SupportGRPCRoute, + features.SupportHTTPRoute, + features.SupportHTTPRouteQueryParamMatching, + features.SupportHTTPRouteMethodMatching, + features.SupportHTTPRoutePortRedirect, + features.SupportHTTPRouteSchemeRedirect, + features.SupportHTTPRouteHostRewrite, + features.SupportHTTPRoutePathRewrite, + features.SupportHTTPRoutePathRedirect, + features.SupportHTTPRouteResponseHeaderModification, + features.SupportTLSRoute, + features.SupportHTTPRouteBackendProtocolH2C, + features.SupportHTTPRouteBackendProtocolWebSocket, + } +} diff --git a/pkg/provider/kubernetes/gateway/kubernetes.go b/pkg/provider/kubernetes/gateway/kubernetes.go index f3e50e274..144bdf31a 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes.go +++ b/pkg/provider/kubernetes/gateway/kubernetes.go @@ -316,6 +316,12 @@ func (p *Provider) loadConfigurationFromGateways(ctx context.Context) *dynamic.C return nil } + var supportedFeatures []gatev1.SupportedFeature + for _, feature := range SupportedFeatures() { + supportedFeatures = append(supportedFeatures, gatev1.SupportedFeature(feature)) + } + slices.Sort(supportedFeatures) + gatewayClassNames := map[string]struct{}{} for _, gatewayClass := range gatewayClasses { if gatewayClass.Spec.ControllerName != controllerName { @@ -333,6 +339,7 @@ func (p *Provider) loadConfigurationFromGateways(ctx context.Context) *dynamic.C Message: "Handled by Traefik controller", LastTransitionTime: metav1.Now(), }), + SupportedFeatures: supportedFeatures, } if err := p.client.UpdateGatewayClassStatus(ctx, gatewayClass.Name, status); err != nil {