Skip to content

Commit 4c7a0fa

Browse files
k8s-ci-robotshaneutt
authored andcommitted
Merge pull request #1642 from gyohuangxin/all-features-conformance-flag
Add `all-features` flag to add ability to enable all supported feature conformance tests.
1 parent 9152db3 commit 4c7a0fa

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

conformance/conformance_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sigs.k8s.io/gateway-api/conformance/utils/flags"
2828
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2929

30+
"k8s.io/apimachinery/pkg/util/sets"
3031
_ "k8s.io/client-go/plugin/pkg/client/auth"
3132
"sigs.k8s.io/controller-runtime/pkg/client"
3233
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -47,29 +48,30 @@ func TestConformance(t *testing.T) {
4748
supportedFeatures := parseSupportedFeatures(*flags.SupportedFeatures)
4849
exemptFeatures := parseSupportedFeatures(*flags.ExemptFeatures)
4950
for feature := range exemptFeatures {
50-
supportedFeatures[feature] = false
51+
supportedFeatures.Delete(feature)
5152
}
5253

53-
t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]",
54-
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.SupportedFeatures, *flags.ExemptFeatures)
54+
t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]",
55+
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures)
5556

5657
cSuite := suite.New(suite.Options{
57-
Client: client,
58-
GatewayClassName: *flags.GatewayClassName,
59-
Debug: *flags.ShowDebug,
60-
CleanupBaseResources: *flags.CleanupBaseResources,
61-
SupportedFeatures: supportedFeatures,
58+
Client: client,
59+
GatewayClassName: *flags.GatewayClassName,
60+
Debug: *flags.ShowDebug,
61+
CleanupBaseResources: *flags.CleanupBaseResources,
62+
SupportedFeatures: supportedFeatures,
63+
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures,
6264
})
6365
cSuite.Setup(t)
6466
cSuite.Run(t, tests.ConformanceTests)
6567
}
6668

6769
// parseSupportedFeatures parses flag arguments and converts the string to
6870
// map[suite.SupportedFeature]bool
69-
func parseSupportedFeatures(f string) map[suite.SupportedFeature]bool {
70-
res := map[suite.SupportedFeature]bool{}
71+
func parseSupportedFeatures(f string) sets.Set[suite.SupportedFeature] {
72+
res := sets.Set[suite.SupportedFeature]{}
7173
for _, value := range strings.Split(f, ",") {
72-
res[suite.SupportedFeature(value)] = true
74+
res.Insert(suite.SupportedFeature(value))
7375
}
7476
return res
7577
}

conformance/utils/flags/flags.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
)
2525

2626
var (
27-
GatewayClassName = flag.String("gateway-class", "gateway-conformance", "Name of GatewayClass to use for tests")
28-
ShowDebug = flag.Bool("debug", false, "Whether to print debug logs")
29-
CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
30-
SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites")
31-
ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites")
27+
GatewayClassName = flag.String("gateway-class", "gateway-conformance", "Name of GatewayClass to use for tests")
28+
ShowDebug = flag.Bool("debug", false, "Whether to print debug logs")
29+
CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
30+
SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites")
31+
ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites")
32+
EnableAllSupportedFeatures = flag.Bool("all-features", false, "Whether to enable all supported features for conformance tests")
3233
)

conformance/utils/suite/suite.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,29 @@ const (
7474

7575
// StandardCoreFeatures are the features that are required to be conformant with
7676
// the Core API features that are part of the Standard release channel.
77-
var StandardCoreFeatures = map[SupportedFeature]bool{
78-
SupportReferenceGrant: true,
79-
}
77+
var StandardCoreFeatures = sets.New(
78+
SupportReferenceGrant,
79+
)
80+
81+
// AllFeatures contains all the supported features and can be used to run all
82+
// conformance tests with `all-features` flag.
83+
//
84+
// Note that the AllFeatures must in sync with defined features when the
85+
// feature constants change.
86+
var AllFeatures = sets.New(
87+
SupportReferenceGrant,
88+
SupportTLSRoute,
89+
SupportHTTPRouteQueryParamMatching,
90+
SupportHTTPRouteMethodMatching,
91+
SupportHTTPResponseHeaderModification,
92+
SupportRouteDestinationPortMatching,
93+
SupportGatewayClassObservedGenerationBump,
94+
SupportHTTPRoutePortRedirect,
95+
SupportHTTPRouteSchemeRedirect,
96+
SupportHTTPRoutePathRedirect,
97+
SupportHTTPRouteHostRewrite,
98+
SupportHTTPRoutePathRewrite,
99+
)
80100

81101
// ConformanceTestSuite defines the test suite used to run Gateway API
82102
// conformance tests.
@@ -89,7 +109,7 @@ type ConformanceTestSuite struct {
89109
Cleanup bool
90110
BaseManifests string
91111
Applier kubernetes.Applier
92-
SupportedFeatures map[SupportedFeature]bool
112+
SupportedFeatures sets.Set[SupportedFeature]
93113
TimeoutConfig config.TimeoutConfig
94114
SkipTests sets.Set[string]
95115
}
@@ -112,9 +132,10 @@ type Options struct {
112132

113133
// CleanupBaseResources indicates whether or not the base test
114134
// resources such as Gateways should be cleaned up after the run.
115-
CleanupBaseResources bool
116-
SupportedFeatures map[SupportedFeature]bool
117-
TimeoutConfig config.TimeoutConfig
135+
CleanupBaseResources bool
136+
SupportedFeatures sets.Set[SupportedFeature]
137+
EnableAllSupportedFeatures bool
138+
TimeoutConfig config.TimeoutConfig
118139
// SkipTests contains all the tests not to be run and can be used to opt out
119140
// of specific tests
120141
SkipTests []string
@@ -129,13 +150,13 @@ func New(s Options) *ConformanceTestSuite {
129150
roundTripper = &roundtripper.DefaultRoundTripper{Debug: s.Debug, TimeoutConfig: s.TimeoutConfig}
130151
}
131152

132-
if s.SupportedFeatures == nil {
153+
if s.EnableAllSupportedFeatures == true {
154+
s.SupportedFeatures = AllFeatures
155+
} else if s.SupportedFeatures == nil {
133156
s.SupportedFeatures = StandardCoreFeatures
134157
} else {
135-
for feature, val := range StandardCoreFeatures {
136-
if _, ok := s.SupportedFeatures[feature]; !ok {
137-
s.SupportedFeatures[feature] = val
138-
}
158+
for feature := range StandardCoreFeatures {
159+
s.SupportedFeatures.Insert(feature)
139160
}
140161
}
141162

@@ -222,7 +243,7 @@ func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {
222243
// Check that all features exercised by the test have been opted into by
223244
// the suite.
224245
for _, feature := range test.Features {
225-
if supported, ok := suite.SupportedFeatures[feature]; !ok || !supported {
246+
if !suite.SupportedFeatures.Has(feature) {
226247
t.Skipf("Skipping %s: suite does not support %s", test.ShortName, feature)
227248
}
228249
}

0 commit comments

Comments
 (0)