From 00439a51d2ab164c2b9420bbeb3dafce3e18bc68 Mon Sep 17 00:00:00 2001 From: Kobi Levi Date: Thu, 25 Jan 2024 16:45:59 +0200 Subject: [PATCH] address cr suggestions Signed-off-by: Kobi Levi --- .../translate/out/default-resources.all.yaml | 22 ++++++++++++++++++ .../out/echo-gateway-api.cluster.yaml | 22 ++++++++++++++++++ .../translate/out/echo-gateway-api.route.json | 23 +++++++++++++++++++ .../translate/out/invalid-envoyproxy.all.yaml | 22 ++++++++++++++++++ .../out/rejected-http-route.route.yaml | 22 ++++++++++++++++++ .../translate/out/valid-envoyproxy.all.yaml | 22 ++++++++++++++++++ internal/cmd/egctl/translate.go | 2 -- internal/cmd/egctl/translate_test.go | 8 +++++++ internal/status/gatewayclass.go | 21 ++++++----------- test/conformance/conformance_features.go | 17 ++++++++++++++ test/conformance/conformance_test.go | 8 +++---- .../experimental_conformance_test.go | 8 +++---- 12 files changed, 171 insertions(+), 26 deletions(-) create mode 100644 test/conformance/conformance_features.go diff --git a/internal/cmd/egctl/testdata/translate/out/default-resources.all.yaml b/internal/cmd/egctl/testdata/translate/out/default-resources.all.yaml index c11c272db86c..788eea8304f7 100644 --- a/internal/cmd/egctl/testdata/translate/out/default-resources.all.yaml +++ b/internal/cmd/egctl/testdata/translate/out/default-resources.all.yaml @@ -149,6 +149,28 @@ gatewayClass: reason: Accepted status: "True" type: Accepted + supportedFeatures: + - Gateway + - GatewayPort8080 + - GatewayStaticAddresses + - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout + - HTTPRouteDestinationPortMatching + - HTTPRouteHostRewrite + - HTTPRouteMethodMatching + - HTTPRoutePathRedirect + - HTTPRoutePathRewrite + - HTTPRoutePortRedirect + - HTTPRouteQueryParamMatching + - HTTPRouteRequestMirror + - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout + - HTTPRouteResponseHeaderModification + - HTTPRouteSchemeRedirect + - ReferenceGrant + - TLSRoute gateways: - metadata: creationTimestamp: null diff --git a/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.cluster.yaml b/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.cluster.yaml index c61a2fdf774a..f8e6fa6c6d89 100644 --- a/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.cluster.yaml +++ b/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.cluster.yaml @@ -12,6 +12,28 @@ gatewayClass: reason: Accepted status: "True" type: Accepted + supportedFeatures: + - Gateway + - GatewayPort8080 + - GatewayStaticAddresses + - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout + - HTTPRouteDestinationPortMatching + - HTTPRouteHostRewrite + - HTTPRouteMethodMatching + - HTTPRoutePathRedirect + - HTTPRoutePathRewrite + - HTTPRoutePortRedirect + - HTTPRouteQueryParamMatching + - HTTPRouteRequestMirror + - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout + - HTTPRouteResponseHeaderModification + - HTTPRouteSchemeRedirect + - ReferenceGrant + - TLSRoute gateways: - metadata: creationTimestamp: null diff --git a/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.route.json b/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.route.json index 41dfd6683e7f..dc6cd0b14e00 100644 --- a/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.route.json +++ b/internal/cmd/egctl/testdata/translate/out/echo-gateway-api.route.json @@ -17,6 +17,29 @@ "reason": "Accepted", "message": "Valid GatewayClass" } + ], + "supportedFeatures": [ + "Gateway", + "GatewayPort8080", + "GatewayStaticAddresses", + "HTTPRoute", + "HTTPRouteBackendProtocolH2C", + "HTTPRouteBackendProtocolWebSocket", + "HTTPRouteBackendTimeout", + "HTTPRouteDestinationPortMatching", + "HTTPRouteHostRewrite", + "HTTPRouteMethodMatching", + "HTTPRoutePathRedirect", + "HTTPRoutePathRewrite", + "HTTPRoutePortRedirect", + "HTTPRouteQueryParamMatching", + "HTTPRouteRequestMirror", + "HTTPRouteRequestMultipleMirrors", + "HTTPRouteRequestTimeout", + "HTTPRouteResponseHeaderModification", + "HTTPRouteSchemeRedirect", + "ReferenceGrant", + "TLSRoute" ] } }, diff --git a/internal/cmd/egctl/testdata/translate/out/invalid-envoyproxy.all.yaml b/internal/cmd/egctl/testdata/translate/out/invalid-envoyproxy.all.yaml index c7ad9cde1334..161e3cadfff7 100644 --- a/internal/cmd/egctl/testdata/translate/out/invalid-envoyproxy.all.yaml +++ b/internal/cmd/egctl/testdata/translate/out/invalid-envoyproxy.all.yaml @@ -38,6 +38,28 @@ gatewayClass: reason: InvalidParameters status: "False" type: Accepted + supportedFeatures: + - Gateway + - GatewayPort8080 + - GatewayStaticAddresses + - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout + - HTTPRouteDestinationPortMatching + - HTTPRouteHostRewrite + - HTTPRouteMethodMatching + - HTTPRoutePathRedirect + - HTTPRoutePathRewrite + - HTTPRoutePortRedirect + - HTTPRouteQueryParamMatching + - HTTPRouteRequestMirror + - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout + - HTTPRouteResponseHeaderModification + - HTTPRouteSchemeRedirect + - ReferenceGrant + - TLSRoute gateways: - metadata: creationTimestamp: null diff --git a/internal/cmd/egctl/testdata/translate/out/rejected-http-route.route.yaml b/internal/cmd/egctl/testdata/translate/out/rejected-http-route.route.yaml index c578d14aef50..a0216a115e00 100644 --- a/internal/cmd/egctl/testdata/translate/out/rejected-http-route.route.yaml +++ b/internal/cmd/egctl/testdata/translate/out/rejected-http-route.route.yaml @@ -12,6 +12,28 @@ gatewayClass: reason: Accepted status: "True" type: Accepted + supportedFeatures: + - Gateway + - GatewayPort8080 + - GatewayStaticAddresses + - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout + - HTTPRouteDestinationPortMatching + - HTTPRouteHostRewrite + - HTTPRouteMethodMatching + - HTTPRoutePathRedirect + - HTTPRoutePathRewrite + - HTTPRoutePortRedirect + - HTTPRouteQueryParamMatching + - HTTPRouteRequestMirror + - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout + - HTTPRouteResponseHeaderModification + - HTTPRouteSchemeRedirect + - ReferenceGrant + - TLSRoute gateways: - metadata: creationTimestamp: null diff --git a/internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml b/internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml index ef42d68c93e8..48c41840b299 100644 --- a/internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml +++ b/internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml @@ -31,6 +31,28 @@ gatewayClass: reason: Accepted status: "True" type: Accepted + supportedFeatures: + - Gateway + - GatewayPort8080 + - GatewayStaticAddresses + - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout + - HTTPRouteDestinationPortMatching + - HTTPRouteHostRewrite + - HTTPRouteMethodMatching + - HTTPRoutePathRedirect + - HTTPRoutePathRewrite + - HTTPRoutePortRedirect + - HTTPRouteQueryParamMatching + - HTTPRouteRequestMirror + - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout + - HTTPRouteResponseHeaderModification + - HTTPRouteSchemeRedirect + - ReferenceGrant + - TLSRoute gateways: - metadata: creationTimestamp: null diff --git a/internal/cmd/egctl/translate.go b/internal/cmd/egctl/translate.go index f7a0f3784a23..179fe2cac0da 100644 --- a/internal/cmd/egctl/translate.go +++ b/internal/cmd/egctl/translate.go @@ -275,13 +275,11 @@ func translateGatewayAPIToGatewayAPI(resources *gatewayapi.Resources) (gatewayap epInvalid = true msg := fmt.Sprintf("%s: %v", status.MsgGatewayClassInvalidParams, err) status.SetGatewayClassAccepted(resources.GatewayClass, false, string(gwapiv1.GatewayClassReasonInvalidParameters), msg) - status.SetGatewayClassSupportedFeatures(resources.GatewayClass) } gRes.EnvoyProxy = resources.EnvoyProxy } if !epInvalid { status.SetGatewayClassAccepted(resources.GatewayClass, true, string(gwapiv1.GatewayClassReasonAccepted), status.MsgValidGatewayClass) - status.SetGatewayClassSupportedFeatures(resources.GatewayClass) } gRes.GatewayClass = resources.GatewayClass diff --git a/internal/cmd/egctl/translate_test.go b/internal/cmd/egctl/translate_test.go index 02bd04c9f34a..ab04b122dee7 100644 --- a/internal/cmd/egctl/translate_test.go +++ b/internal/cmd/egctl/translate_test.go @@ -22,6 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" + "github.com/envoyproxy/gateway/internal/status" "github.com/envoyproxy/gateway/internal/utils/field" "github.com/envoyproxy/gateway/internal/utils/file" ) @@ -344,6 +345,13 @@ func TestTranslate(t *testing.T) { } want := &TranslationResult{} mustUnmarshal(t, requireTestDataOutFile(t, fn), want) + + // Supported features are dynamic, instead of hard-coding them in the output files + // we define them here. + if want.GatewayClass != nil { + want.GatewayClass.Status.SupportedFeatures = status.GetSupportedFeatures() + } + opts := cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime") require.Empty(t, cmp.Diff(want, got, opts)) diff --git a/internal/status/gatewayclass.go b/internal/status/gatewayclass.go index ebd16435e118..1ef85cb2121c 100644 --- a/internal/status/gatewayclass.go +++ b/internal/status/gatewayclass.go @@ -16,23 +16,15 @@ package status import ( "k8s.io/apimachinery/pkg/util/sets" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" - "sigs.k8s.io/gateway-api/conformance/utils/suite" -) -// SetGatewayClassAccepted inserts or updates the Accepted condition -// for the provided GatewayClass. -func SetGatewayClassAccepted(gc *gwapiv1.GatewayClass, accepted bool, reason, msg string) *gwapiv1.GatewayClass { - gc.Status.Conditions = MergeConditions(gc.Status.Conditions, computeGatewayClassAcceptedCondition(gc, accepted, reason, msg)) - return gc -} + "github.com/envoyproxy/gateway/test/conformance" +) // GetSupportedFeatures returns a list of supported Gateway-API features, // based on the running conformance tests suite. func GetSupportedFeatures() []gwapiv1.SupportedFeature { - - // TODO(levikobi): This must be in sync with the cSuite supported features. - supportedFeatures := suite.AllFeatures - supportedFeatures.Delete(suite.MeshCoreFeatures.UnsortedList()...) + supportedFeatures := conformance.EnvoyGatewaySuite.SupportedFeatures + supportedFeatures.Delete(conformance.EnvoyGatewaySuite.ExemptFeatures.UnsortedList()...) ret := sets.New[gwapiv1.SupportedFeature]() for _, feature := range supportedFeatures.UnsortedList() { @@ -41,9 +33,10 @@ func GetSupportedFeatures() []gwapiv1.SupportedFeature { return sets.List(ret) } -// SetGatewayClassSupportedFeatures insert or updates the SupportedFeatures field +// SetGatewayClassAccepted inserts or updates the Accepted condition // for the provided GatewayClass. -func SetGatewayClassSupportedFeatures(gc *gwapiv1.GatewayClass) *gwapiv1.GatewayClass { +func SetGatewayClassAccepted(gc *gwapiv1.GatewayClass, accepted bool, reason, msg string) *gwapiv1.GatewayClass { + gc.Status.Conditions = MergeConditions(gc.Status.Conditions, computeGatewayClassAcceptedCondition(gc, accepted, reason, msg)) gc.Status.SupportedFeatures = GetSupportedFeatures() return gc } diff --git a/test/conformance/conformance_features.go b/test/conformance/conformance_features.go new file mode 100644 index 000000000000..330a12d54ecd --- /dev/null +++ b/test/conformance/conformance_features.go @@ -0,0 +1,17 @@ +// Copyright Envoy Gateway Authors +// SPDX-License-Identifier: Apache-2.0 +// The full text of the Apache license is available in the LICENSE file at +// the root of the repo. + +package conformance + +import ( + "sigs.k8s.io/gateway-api/conformance/tests" + "sigs.k8s.io/gateway-api/conformance/utils/suite" +) + +var EnvoyGatewaySuite = suite.Options{ + SupportedFeatures: suite.AllFeatures, + ExemptFeatures: suite.MeshCoreFeatures, + SkipTests: []string{tests.GatewayStaticAddresses.ShortName}, +} diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index 149909e2ce45..1a3bc8542ff2 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -46,11 +46,9 @@ func TestGatewayAPIConformance(t *testing.T) { Debug: *flags.ShowDebug, Clientset: clientset, CleanupBaseResources: *flags.CleanupBaseResources, - SupportedFeatures: suite.AllFeatures, - SkipTests: []string{ - tests.GatewayStaticAddresses.ShortName, - }, - ExemptFeatures: suite.MeshCoreFeatures, + SupportedFeatures: EnvoyGatewaySuite.SupportedFeatures, + SkipTests: EnvoyGatewaySuite.SkipTests, + ExemptFeatures: EnvoyGatewaySuite.ExemptFeatures, }) cSuite.Setup(t) cSuite.Run(t, tests.ConformanceTests) diff --git a/test/conformance/experimental_conformance_test.go b/test/conformance/experimental_conformance_test.go index b6d6b19e953a..ecf0c4ad1410 100644 --- a/test/conformance/experimental_conformance_test.go +++ b/test/conformance/experimental_conformance_test.go @@ -95,11 +95,9 @@ func experimentalConformance(t *testing.T) { GatewayClassName: *flags.GatewayClassName, Debug: *flags.ShowDebug, CleanupBaseResources: *flags.CleanupBaseResources, - SupportedFeatures: suite.AllFeatures, - SkipTests: []string{ - tests.GatewayStaticAddresses.ShortName, - }, - ExemptFeatures: suite.MeshCoreFeatures, + SupportedFeatures: EnvoyGatewaySuite.SupportedFeatures, + SkipTests: EnvoyGatewaySuite.SkipTests, + ExemptFeatures: EnvoyGatewaySuite.ExemptFeatures, }, Implementation: *implementation, ConformanceProfiles: conformanceProfiles,