Skip to content

Commit

Permalink
feat: add supported features to gateway class (envoyproxy#2491)
Browse files Browse the repository at this point in the history
* feat: add supported features to gateway class

Signed-off-by: Kobi Levi <kobilevi503@gmail.com>

* remove skipped test features from supported features list

Signed-off-by: Kobi Levi <kobilevi503@gmail.com>

---------

Signed-off-by: Kobi Levi <kobilevi503@gmail.com>
  • Loading branch information
levikobi authored May 15, 2024
1 parent a2fbbad commit 02e9367
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,27 @@ gatewayClass:
reason: Accepted
status: "True"
type: Accepted
supportedFeatures:
- GRPCRoute
- GatewayPort8080
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteBackendTimeout
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestTimeout
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
- ReferenceGrant
- TLSRoute
gateways:
- metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ gatewayClass:
reason: Accepted
status: "True"
type: Accepted
supportedFeatures:
- GRPCRoute
- GatewayPort8080
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteBackendTimeout
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestTimeout
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
- ReferenceGrant
- TLSRoute
gateways:
- metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@
"reason": "Accepted",
"message": "Valid GatewayClass"
}
],
"supportedFeatures": [
"GRPCRoute",
"GatewayPort8080",
"HTTPRouteBackendProtocolH2C",
"HTTPRouteBackendProtocolWebSocket",
"HTTPRouteBackendTimeout",
"HTTPRouteDestinationPortMatching",
"HTTPRouteHostRewrite",
"HTTPRouteMethodMatching",
"HTTPRouteParentRefPort",
"HTTPRoutePathRedirect",
"HTTPRoutePathRewrite",
"HTTPRoutePortRedirect",
"HTTPRouteQueryParamMatching",
"HTTPRouteRequestMirror",
"HTTPRouteRequestMultipleMirrors",
"HTTPRouteRequestTimeout",
"HTTPRouteResponseHeaderModification",
"HTTPRouteSchemeRedirect",
"ReferenceGrant",
"TLSRoute"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ gatewayClass:
reason: InvalidParameters
status: "False"
type: Accepted
supportedFeatures:
- GRPCRoute
- GatewayPort8080
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteBackendTimeout
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestTimeout
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
- ReferenceGrant
- TLSRoute
gateways:
- metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ gatewayClass:
reason: Accepted
status: "True"
type: Accepted
supportedFeatures:
- GRPCRoute
- GatewayPort8080
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteBackendTimeout
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestTimeout
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
- ReferenceGrant
- TLSRoute
gateways:
- metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ gatewayClass:
reason: Accepted
status: "True"
type: Accepted
supportedFeatures:
- GRPCRoute
- GatewayPort8080
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteBackendTimeout
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestTimeout
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
- ReferenceGrant
- TLSRoute
gateways:
- metadata:
creationTimestamp: null
Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/egctl/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/utils/field"
"github.com/envoyproxy/gateway/internal/utils/file"
)
Expand Down Expand Up @@ -349,6 +350,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.GatewaySupportedFeatures
}

opts := cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")
require.Empty(t, cmp.Diff(want, got, opts))
})
Expand Down
37 changes: 37 additions & 0 deletions internal/gatewayapi/conformance/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/gateway-api/conformance/tests"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

// SkipTests is a list of tests that are skipped in the conformance suite.
var SkipTests = []suite.ConformanceTest{
tests.GatewayStaticAddresses,
tests.GatewayHTTPListenerIsolation, // https://github.com/kubernetes-sigs/gateway-api/issues/3049
tests.HTTPRouteBackendRequestHeaderModifier, // https://github.com/envoyproxy/gateway/issues/3338
}

func skipTestsShortNames(skipTests []suite.ConformanceTest) []string {
shortNames := make([]string, len(skipTests))
for i, test := range skipTests {
shortNames[i] = test.ShortName
}
return shortNames
}

// EnvoyGatewaySuite is the conformance suite configuration for the Gateway API.
var EnvoyGatewaySuite = suite.ConformanceOptions{
SupportedFeatures: features.AllFeatures,
ExemptFeatures: sets.New[features.SupportedFeature]().
Insert(features.MeshCoreFeatures.UnsortedList()...).
Insert(features.MeshExtendedFeatures.UnsortedList()...),
SkipTests: skipTestsShortNames(SkipTests),
}
26 changes: 26 additions & 0 deletions internal/gatewayapi/status/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance/utils/suite"

"github.com/envoyproxy/gateway/internal/gatewayapi/conformance"
)

const (
Expand All @@ -32,6 +36,7 @@ const (
// 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))
gc.Status.SupportedFeatures = GatewaySupportedFeatures
return gc
}

Expand Down Expand Up @@ -61,3 +66,24 @@ func computeGatewayClassAcceptedCondition(gatewayClass *gwapiv1.GatewayClass,
}
}
}

// GatewaySupportedFeatures is a list of supported Gateway-API features,
// based on the running conformance tests suite.
var GatewaySupportedFeatures = getSupportedFeatures(conformance.EnvoyGatewaySuite, conformance.SkipTests)

func getSupportedFeatures(gatewaySuite suite.ConformanceOptions, skippedTests []suite.ConformanceTest) []gwapiv1.SupportedFeature {
supportedFeatures := gatewaySuite.SupportedFeatures.Clone()
supportedFeatures.Delete(gatewaySuite.ExemptFeatures.UnsortedList()...)

for _, skippedTest := range skippedTests {
for _, feature := range skippedTest.Features {
supportedFeatures.Delete(feature)
}
}

ret := sets.New[gwapiv1.SupportedFeature]()
for _, feature := range supportedFeatures.UnsortedList() {
ret.Insert(gwapiv1.SupportedFeature(feature))
}
return sets.List(ret)
}
59 changes: 59 additions & 0 deletions internal/gatewayapi/status/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"

gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func TestComputeGatewayClassAcceptedCondition(t *testing.T) {
Expand Down Expand Up @@ -66,3 +70,58 @@ func TestComputeGatewayClassAcceptedCondition(t *testing.T) {
assert.Equal(t, gc.Generation, got.ObservedGeneration)
}
}

func TestGetSupportedFeatures(t *testing.T) {
testCases := []struct {
name string
gatewaySuite suite.ConformanceOptions
skippedTests []suite.ConformanceTest
expectedResult []gwapiv1.SupportedFeature
}{
{
name: "No exempt features",
gatewaySuite: suite.ConformanceOptions{
SupportedFeatures: sets.New[features.SupportedFeature]("Gateway", "HTTPRoute"),
ExemptFeatures: sets.New[features.SupportedFeature](),
},
expectedResult: []gwapiv1.SupportedFeature{"Gateway", "HTTPRoute"},
},
{
name: "All features exempt",
gatewaySuite: suite.ConformanceOptions{
SupportedFeatures: sets.New[features.SupportedFeature]("Gateway", "HTTPRoute"),
ExemptFeatures: sets.New[features.SupportedFeature]("Gateway", "HTTPRoute"),
},
expectedResult: []gwapiv1.SupportedFeature{},
},
{
name: "Some features exempt",
gatewaySuite: suite.ConformanceOptions{
SupportedFeatures: sets.New[features.SupportedFeature]("Gateway", "HTTPRoute", "GRPCRoute"),
ExemptFeatures: sets.New[features.SupportedFeature]("GRPCRoute"),
},
expectedResult: []gwapiv1.SupportedFeature{"Gateway", "HTTPRoute"},
},
{
name: "Some features exempt with skipped tests",
gatewaySuite: suite.ConformanceOptions{
SupportedFeatures: sets.New[features.SupportedFeature]("Gateway", "HTTPRoute", "GRPCRoute"),
ExemptFeatures: sets.New[features.SupportedFeature]("GRPCRoute"),
},
skippedTests: []suite.ConformanceTest{
{
Features: []features.SupportedFeature{"HTTPRoute"},
},
},
expectedResult: []gwapiv1.SupportedFeature{"Gateway"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := getSupportedFeatures(tc.gatewaySuite, tc.skippedTests)

assert.ElementsMatch(t, tc.expectedResult, result, "The result should match the expected output for the test case.")
})
}
}
5 changes: 5 additions & 0 deletions internal/provider/kubernetes/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
"github.com/envoyproxy/gateway/internal/logging"
)

Expand Down Expand Up @@ -189,6 +190,7 @@ func TestHasManagedClass(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
SupportedFeatures: status.GatewaySupportedFeatures,
},
},
},
Expand Down Expand Up @@ -223,6 +225,7 @@ func TestHasManagedClass(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
SupportedFeatures: status.GatewaySupportedFeatures,
},
},
},
Expand Down Expand Up @@ -275,6 +278,7 @@ func TestHasManagedClass(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
SupportedFeatures: status.GatewaySupportedFeatures,
},
},
{
Expand All @@ -297,6 +301,7 @@ func TestHasManagedClass(t *testing.T) {
Status: metav1.ConditionFalse,
},
},
SupportedFeatures: status.GatewaySupportedFeatures,
},
},
},
Expand Down
Loading

0 comments on commit 02e9367

Please sign in to comment.