@@ -8,35 +8,33 @@ https://github.com/openshift-eng/openshift-tests-extension/blob/main/cmd/example
88package main
99
1010import (
11- "context "
11+ "fmt "
1212 "os"
13+ "strings"
1314
15+ otecmd "github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
16+ oteextension "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
17+ et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
18+ g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
1419 "github.com/spf13/cobra"
1520 "k8s.io/component-base/cli"
1621
17- otecmd "github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
18- oteextension "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
1922 "github.com/openshift/cluster-kube-apiserver-operator/pkg/version"
2023
21- "k8s.io/klog/v2"
24+ // The import below is necessary to ensure that the tests are registered with the extension.
25+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e"
2226)
2327
2428func main () {
25- command := newOperatorTestCommand (context .Background ())
26- code := cli .Run (command )
27- os .Exit (code )
28- }
29-
30- func newOperatorTestCommand (ctx context.Context ) * cobra.Command {
3129 registry := prepareOperatorTestsRegistry ()
32-
3330 cmd := & cobra.Command {
3431 Use : "cluster-kube-apiserver-operator-tests" ,
3532 Short : "A binary used to run cluster-kube-apiserver-operator tests as part of OTE." ,
3633 Run : func (cmd * cobra.Command , args []string ) {
3734 // no-op, logic is provided by the OTE framework
3835 if err := cmd .Help (); err != nil {
39- klog .Fatal (err )
36+ fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
37+ os .Exit (1 )
4038 }
4139 },
4240 }
@@ -49,7 +47,8 @@ func newOperatorTestCommand(ctx context.Context) *cobra.Command {
4947
5048 cmd .AddCommand (otecmd .DefaultExtensionCommands (registry )... )
5149
52- return cmd
50+ code := cli .Run (cmd )
51+ os .Exit (code )
5352}
5453
5554// prepareOperatorTestsRegistry creates the OTE registry for this operator.
@@ -61,6 +60,109 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
6160 registry := oteextension .NewRegistry ()
6261 extension := oteextension .NewExtension ("openshift" , "payload" , "cluster-kube-apiserver-operator" )
6362
63+ // Suite: conformance/parallel (fast, parallel-safe)
64+ // Rule: Tests without [Serial], [Slow], or [Timeout:] tags run in parallel
65+ extension .AddSuite (oteextension.Suite {
66+ Name : "openshift/cluster-kube-apiserver-operator/conformance/parallel" ,
67+ Parents : []string {"openshift/conformance/parallel" },
68+ Qualifiers : []string {
69+ `!(name.contains("[Serial]") || name.contains("[Slow]") || name.contains("[Timeout:"))` ,
70+ },
71+ })
72+
73+ // Suite: conformance/serial (explicitly serial tests, but NOT slow tests)
74+ // Rule 2 & 4: Tests with [Serial] or [Serial][Disruptive] run only in serial suite
75+ // Tests with [Serial][Timeout:] go to serial (timeout on serial test)
76+ // Exclude [Slow] tests - they go to slow suite instead
77+ // Parallelism: 1 enforces serial execution even when run without -c 1 flag
78+ extension .AddSuite (oteextension.Suite {
79+ Name : "openshift/cluster-kube-apiserver-operator/conformance/serial" ,
80+ Parents : []string {"openshift/conformance/serial" },
81+ Parallelism : 1 ,
82+ Qualifiers : []string {
83+ `name.contains("[Serial]") && !name.contains("[Slow]")` ,
84+ },
85+ })
86+
87+ // Suite: optional/slow (long-running tests and non-serial timeout tests)
88+ // Rule 3 & 5: Tests with [Slow] OR tests with [Timeout:] that are NOT [Serial]
89+ // Tests with [Slow][Disruptive][Timeout:] will run serially due to [Serial] tag
90+ // Parallelism: 1 enforces serial execution even when run without -c 1 flag
91+ extension .AddSuite (oteextension.Suite {
92+ Name : "openshift/cluster-kube-apiserver-operator/optional/slow" ,
93+ Parents : []string {"openshift/optional/slow" },
94+ Parallelism : 1 ,
95+ Qualifiers : []string {
96+ `name.contains("[Slow]") || (name.contains("[Timeout:") && !name.contains("[Serial]"))` ,
97+ },
98+ })
99+
100+ // Suite: all (includes everything)
101+ extension .AddSuite (oteextension.Suite {
102+ Name : "openshift/cluster-kube-apiserver-operator/all" ,
103+ })
104+
105+ // Build ginkgo test specs from the test/e2e package
106+ specs , err := g .BuildExtensionTestSpecsFromOpenShiftGinkgoSuite ()
107+ if err != nil {
108+ panic (fmt .Sprintf ("couldn't build extension test specs from ginkgo: %+v" , err .Error ()))
109+ }
110+
111+ // Ensure [Disruptive] tests are also [Serial]
112+ specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
113+ if strings .Contains (spec .Name , "[Disruptive]" ) && ! strings .Contains (spec .Name , "[Serial]" ) {
114+ spec .Name = strings .ReplaceAll (
115+ spec .Name ,
116+ "[Disruptive]" ,
117+ "[Serial][Disruptive]" ,
118+ )
119+ }
120+ })
121+
122+ // Preserve original-name labels for renamed tests
123+ specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
124+ for label := range spec .Labels {
125+ if strings .HasPrefix (label , "original-name:" ) {
126+ parts := strings .SplitN (label , "original-name:" , 2 )
127+ if len (parts ) > 1 {
128+ spec .OriginalName = parts [1 ]
129+ }
130+ }
131+ }
132+ })
133+
134+ // Extract timeout from test name if present (e.g., [Timeout:50m])
135+ specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
136+ // Look for [Timeout:XXm] or [Timeout:XXh] pattern in test name
137+ if strings .Contains (spec .Name , "[Timeout:" ) {
138+ start := strings .Index (spec .Name , "[Timeout:" )
139+ if start != - 1 {
140+ end := strings .Index (spec .Name [start :], "]" )
141+ if end != - 1 {
142+ // Extract the timeout value (e.g., "50m" from "[Timeout:50m]")
143+ timeoutTag := spec .Name [start + len ("[Timeout:" ) : start + end ]
144+ if spec .Tags == nil {
145+ spec .Tags = make (map [string ]string )
146+ }
147+ spec .Tags ["timeout" ] = timeoutTag
148+ }
149+ }
150+ }
151+ })
152+
153+ // Ignore obsolete tests
154+ extension .IgnoreObsoleteTests (
155+ // "[sig-api-machinery] <test name here>",
156+ )
157+
158+ // Initialize environment before running any tests
159+ specs .AddBeforeAll (func () {
160+ // do stuff
161+ })
162+
163+ // Add the discovered test specs to the extension
164+ extension .AddSpecs (specs )
165+
64166 registry .Register (extension )
65167 return registry
66168}
0 commit comments