Skip to content

Commit 9828ad6

Browse files
BenTheElderpohly
andcommitted
e2e framework WithFeatureGate adds [Feature:OffByDefault]
(when passed a feature that is not Default) This allows using the regex filter to skip tests that do not work on a cluster without optional configuration, while moving tests to use WithFeatureGate without also setting WithFeature unless they have some additional configuration required. Co-authored-by: Patrick Ohly <[email protected]>
1 parent aa08c90 commit 9828ad6

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

test/e2e/framework/ginkgowrapper.go

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,14 @@ func registerInSuite(ginkgoCall func(string, ...interface{}) bool, args []interf
208208
case label:
209209
fullLabel := strings.Join(arg.parts, ":")
210210
addLabel(fullLabel)
211-
if arg.extraFeature != "" {
212-
texts = append(texts, fmt.Sprintf("[%s]", arg.extraFeature))
213-
ginkgoArgs = append(ginkgoArgs, ginkgo.Label("Feature:"+arg.extraFeature))
211+
if arg.alphaBetaLevel != "" {
212+
texts = append(texts, fmt.Sprintf("[%[1]s]", arg.alphaBetaLevel))
213+
ginkgoArgs = append(ginkgoArgs, ginkgo.Label("Feature:"+arg.alphaBetaLevel))
214+
}
215+
if arg.offByDefault {
216+
texts = append(texts, "[Feature:OffByDefault]")
217+
// TODO: consider this once we have a plan to update the alpha/beta job filters
218+
// ginkgoArgs = append(ginkgoArgs, ginkgo.Label("Feature:OffByDefault"))
214219
}
215220
if fullLabel == "Serial" {
216221
ginkgoArgs = append(ginkgoArgs, ginkgo.Serial)
@@ -305,6 +310,12 @@ func validateText(location types.CodeLocation, text string, labels []string) {
305310
// Okay, was also set as label.
306311
continue
307312
}
313+
// TODO: we currently only set this as a text value
314+
// We should probably reflect it into labels, but that could break some
315+
// existing jobs and we're still setting on an exact plan
316+
if tag == "Feature:OffByDefault" {
317+
continue
318+
}
308319
if deprecatedTags.Has(tag) {
309320
recordTextBug(location, fmt.Sprintf("[%s] in plain text is deprecated and must be added through With%s instead", tag, tag))
310321
}
@@ -350,7 +361,8 @@ func withFeature(name Feature) interface{} {
350361
}
351362

352363
// WithFeatureGate specifies that a certain test or group of tests depends on a
353-
// feature gate being enabled. The return value must be passed as additional
364+
// feature gate and the corresponding API group (if there is one)
365+
// being enabled. The return value must be passed as additional
354366
// argument to [framework.It], [framework.Describe], [framework.Context].
355367
//
356368
// The feature gate must be listed in
@@ -359,9 +371,15 @@ func withFeature(name Feature) interface{} {
359371
// also need to be removed.
360372
//
361373
// [Alpha] resp. [Beta] get added to the test name automatically depending
362-
// on the current stability level of the feature. Feature:Alpha resp.
363-
// Feature:Beta get added to the Ginkgo labels because this is a special
364-
// requirement for how the cluster needs to be configured.
374+
// on the current stability level of the feature, to emulate historic
375+
// usage of those tags.
376+
//
377+
// In addition, [Feature:Alpha] resp. [Feature:Beta] get added to support
378+
// skipping a test with a dependency on an alpha or beta feature gate in
379+
// jobs which use the traditional \[Feature:.*\] skip regular expression.
380+
//
381+
// For label filtering, Feature:Alpha resp. Feature:Beta get added to the
382+
// Ginkgo labels.
365383
//
366384
// If the test can run in any cluster that has alpha resp. beta features and
367385
// API groups enabled, then annotating it with just WithFeatureGate is
@@ -390,7 +408,8 @@ func withFeatureGate(featureGate featuregate.Feature) interface{} {
390408
}
391409

392410
l := newLabel("FeatureGate", string(featureGate))
393-
l.extraFeature = level
411+
l.offByDefault = !spec.Default
412+
l.alphaBetaLevel = level
394413
return l
395414
}
396415

@@ -536,13 +555,19 @@ func withFlaky() interface{} {
536555
type label struct {
537556
// parts get concatenated with ":" to build the full label.
538557
parts []string
539-
// extra is an optional feature name. It gets added as [<extraFeature>]
540-
// to the test name and as Feature:<extraFeature> to the labels.
541-
extraFeature string
542558
// explanation gets set for each label to help developers
543559
// who pass a label to a ginkgo function. They need to use
544560
// the corresponding framework function instead.
545561
explanation string
562+
563+
// TODO: the fields below are only used for FeatureGates, we may want to refactor
564+
565+
// alphaBetaLevel is "Alpha", "Beta" or empty for GA features
566+
// It gets added as [<level>] [Feature:<level>]
567+
// to the test name and as Feature:<level> to the labels.
568+
alphaBetaLevel string
569+
// set based on featuregate default state
570+
offByDefault bool
546571
}
547572

548573
func newLabel(parts ...string) label {
@@ -565,7 +590,10 @@ func TagsEqual(a, b interface{}) bool {
565590
if !ok {
566591
return false
567592
}
568-
if al.extraFeature != bl.extraFeature {
593+
if al.alphaBetaLevel != bl.alphaBetaLevel {
594+
return false
595+
}
596+
if al.offByDefault != bl.offByDefault {
569597
return false
570598
}
571599
return slices.Equal(al.parts, bl.parts)

test/e2e/framework/internal/unittests/bugs/bugs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ ERROR: some/relative/path/buggy.go:200: with spaces
122122
`
123123
// Used by unittests/list-tests. It's sorted by test name, not source code location.
124124
ListTestsOutput = `The following spec names can be used with 'ginkgo run --focus/skip':
125-
../bugs/bugs.go:100: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [FeatureGate:no-such-feature-gate] [FeatureGate:TestAlphaFeature] [Alpha] [FeatureGate:TestBetaFeature] [Beta] [FeatureGate:TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz x [foo] should [bar]
126-
../bugs/bugs.go:95: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [FeatureGate:no-such-feature-gate] [FeatureGate:TestAlphaFeature] [Alpha] [FeatureGate:TestBetaFeature] [Beta] [FeatureGate:TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz y [foo] should [bar]
125+
../bugs/bugs.go:100: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [FeatureGate:no-such-feature-gate] [Feature:OffByDefault] [FeatureGate:TestAlphaFeature] [Alpha] [Feature:OffByDefault] [FeatureGate:TestBetaFeature] [Beta] [Feature:OffByDefault] [FeatureGate:TestGAFeature] [Feature:OffByDefault] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz x [foo] should [bar]
126+
../bugs/bugs.go:95: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [FeatureGate:no-such-feature-gate] [Feature:OffByDefault] [FeatureGate:TestAlphaFeature] [Alpha] [Feature:OffByDefault] [FeatureGate:TestBetaFeature] [Beta] [Feature:OffByDefault] [FeatureGate:TestGAFeature] [Feature:OffByDefault] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz y [foo] should [bar]
127127
128128
`
129129

0 commit comments

Comments
 (0)