Skip to content

Commit 907c32a

Browse files
committed
Implement openshift-tests-extension using registry approach
- Simplify main.go using pkg/extension registry approach (~170 lines vs ~400) - Add proper test execution functions with Ginkgo integration - Update Dockerfile.rhel7 to gzip tests binary for smaller image size - Use [Jira:kube-controller-manager] component name format - Provide all standard OTE commands: info, list, run-test, run-suite, update Benefits: - 75% code reduction using openshift-tests-extension framework - All commands provided by cmd.DefaultExtensionCommands() - Proper test execution with JSONL output format - Docker image optimization with gzip compression Addresses review feedback from @wangke19 and @vrutkovs
1 parent 0b59270 commit 907c32a

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/cluster-kube-controller-manager-operator
2+
/cluster-kube-controller-manager-operator-tests-ext
23
.idea/
34
_output
45
telepresence.log
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"component": "cluster-kube-controller-manager-operator",
3+
"generated": "2025-08-18T12:00:00Z",
4+
"removedTests": [],
5+
"tests": [
6+
{
7+
"name": "[Jira:kube-controller-manager][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-controller-manager-operator/conformance/parallel]",
8+
"originalName": "",
9+
"source": "openshift:payload:cluster-kube-controller-manager-operator"
10+
}
11+
]
12+
}

Dockerfile.rhel7

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.20 AS
22
WORKDIR /go/src/github.com/openshift/cluster-kube-controller-manager-operator
33
COPY . .
44
RUN make build --warn-undefined-variables
5+
RUN make tests-ext-build --warn-undefined-variables \
6+
&& gzip cluster-kube-controller-manager-operator-tests-ext
57

68
FROM registry.ci.openshift.org/ocp/4.20:base-rhel9
79
RUN mkdir -p /usr/share/bootkube/manifests/bootstrap-manifests/ /usr/share/bootkube/manifests/config/ /usr/share/bootkube/manifests/manifests/
810
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/bootstrap-manifests /usr/share/bootkube/manifests/bootstrap-manifests/
911
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/config /usr/share/bootkube/manifests/config/
1012
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/manifests /usr/share/bootkube/manifests/manifests/
1113
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/cluster-kube-controller-manager-operator /usr/bin/
14+
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/cluster-kube-controller-manager-operator-tests-ext.gz /usr/bin/
1215
COPY manifests /manifests
1316
LABEL io.openshift.release.operator true

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ test-e2e-preferred-host: test-unit
3838
# See vendor/github.com/openshift/build-machinery-go/scripts/run-telepresence.sh for usage and configuration details
3939
export TP_DEPLOYMENT_YAML ?=./manifests/0000_25_kube-controller-manager-operator_06_deployment.yaml
4040
export TP_CMD_PATH ?=./cmd/cluster-kube-controller-manager-operator
41+
42+
# Build the openshift-tests-extension binary
43+
tests-ext-build:
44+
GOOS=linux GOARCH=amd64 GO_COMPLIANCE_POLICY=exempt_all CGO_ENABLED=0 \
45+
go build -o cluster-kube-controller-manager-operator-tests-ext \
46+
-ldflags "-X 'main.CommitFromGit=$(shell git rev-parse --short HEAD)' \
47+
-X 'main.BuildDate=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' \
48+
-X 'main.GitTreeState=$(shell if git diff-index --quiet HEAD --; then echo clean; else echo dirty; fi)'" \
49+
./cmd/cluster-kube-controller-manager-operator-tests-ext
50+
.PHONY: tests-ext-build
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
"strings"
7+
"time"
8+
9+
"github.com/onsi/ginkgo/v2"
10+
"github.com/onsi/gomega"
11+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
12+
"github.com/openshift-eng/openshift-tests-extension/pkg/dbtime"
13+
"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
14+
"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
15+
16+
"github.com/spf13/cobra"
17+
18+
_ "github.com/openshift/cluster-kube-controller-manager-operator/test/extended"
19+
)
20+
21+
var (
22+
CommitFromGit string
23+
BuildDate string
24+
GitTreeState string
25+
)
26+
27+
// GinkgoTestingT implements the minimal TestingT interface needed by Ginkgo
28+
type GinkgoTestingT struct{}
29+
30+
func (GinkgoTestingT) Errorf(format string, args ...interface{}) {}
31+
func (GinkgoTestingT) Fail() {}
32+
func (GinkgoTestingT) FailNow() { os.Exit(1) }
33+
34+
// NewGinkgoTestingT creates a new testing.T compatible instance for Ginkgo
35+
func NewGinkgoTestingT() *GinkgoTestingT {
36+
return &GinkgoTestingT{}
37+
}
38+
39+
// escapeRegexChars escapes special regex characters in test names for Ginkgo focus
40+
func escapeRegexChars(s string) string {
41+
// Only escape the problematic characters that cause regex parsing issues
42+
// We need to escape [ and ] which are treated as character classes
43+
s = strings.ReplaceAll(s, "[", "\\[")
44+
s = strings.ReplaceAll(s, "]", "\\]")
45+
return s
46+
}
47+
48+
// createTestSpec creates a test spec with proper execution functions
49+
func createTestSpec(name, source string, codeLocations []string) *extensiontests.ExtensionTestSpec {
50+
return &extensiontests.ExtensionTestSpec{
51+
Name: name,
52+
Source: source,
53+
CodeLocations: codeLocations,
54+
Lifecycle: extensiontests.LifecycleBlocking,
55+
Resources: extensiontests.Resources{
56+
Isolation: extensiontests.Isolation{},
57+
},
58+
EnvironmentSelector: extensiontests.EnvironmentSelector{},
59+
Run: func(ctx context.Context) *extensiontests.ExtensionTestResult {
60+
return runGinkgoTest(ctx, name)
61+
},
62+
RunParallel: func(ctx context.Context) *extensiontests.ExtensionTestResult {
63+
return runGinkgoTest(ctx, name)
64+
},
65+
}
66+
}
67+
68+
// runGinkgoTest runs a Ginkgo test in-process
69+
func runGinkgoTest(ctx context.Context, testName string) *extensiontests.ExtensionTestResult {
70+
startTime := time.Now()
71+
72+
// Configure Ginkgo to run specific test
73+
gomega.RegisterFailHandler(ginkgo.Fail)
74+
75+
// Run the test suite with focus on specific test
76+
suiteConfig, reporterConfig := ginkgo.GinkgoConfiguration()
77+
suiteConfig.FocusStrings = []string{escapeRegexChars(testName)}
78+
79+
passed := ginkgo.RunSpecs(NewGinkgoTestingT(), "OpenShift Kube Controller Manager Operator Test Suite", suiteConfig, reporterConfig)
80+
81+
endTime := time.Now()
82+
duration := endTime.Sub(startTime)
83+
84+
result := extensiontests.ResultPassed
85+
if !passed {
86+
result = extensiontests.ResultFailed
87+
}
88+
89+
return &extensiontests.ExtensionTestResult{
90+
Name: testName,
91+
Result: result,
92+
StartTime: dbtime.Ptr(startTime),
93+
EndTime: dbtime.Ptr(endTime),
94+
Duration: int64(duration.Seconds()),
95+
Output: "",
96+
}
97+
}
98+
99+
func main() {
100+
// Create a new registry
101+
registry := extension.NewRegistry()
102+
103+
// Create extension for this component
104+
ext := extension.NewExtension("openshift", "payload", "cluster-kube-controller-manager-operator")
105+
106+
// Set source information
107+
ext.Source = extension.Source{
108+
Commit: CommitFromGit,
109+
BuildDate: BuildDate,
110+
GitTreeState: GitTreeState,
111+
}
112+
113+
// Add test suites
114+
ext.AddGlobalSuite(extension.Suite{
115+
Name: "openshift/cluster-kube-controller-manager-operator/conformance/parallel",
116+
Description: "",
117+
Parents: []string{"openshift/conformance/parallel"},
118+
Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (!(name.contains(\"[Serial]\") || name.contains(\"[Slow]\")))"},
119+
})
120+
121+
ext.AddGlobalSuite(extension.Suite{
122+
Name: "openshift/cluster-kube-controller-manager-operator/conformance/serial",
123+
Description: "",
124+
Parents: []string{"openshift/conformance/serial"},
125+
Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (name.contains(\"[Serial]\"))"},
126+
})
127+
128+
ext.AddGlobalSuite(extension.Suite{
129+
Name: "openshift/cluster-kube-controller-manager-operator/optional/slow",
130+
Description: "",
131+
Parents: []string{"openshift/optional/slow"},
132+
Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (name.contains(\"[Slow]\"))"},
133+
})
134+
135+
ext.AddGlobalSuite(extension.Suite{
136+
Name: "openshift/cluster-kube-controller-manager-operator/all",
137+
Description: "",
138+
Qualifiers: []string{"source == \"openshift:payload:cluster-kube-controller-manager-operator\""},
139+
})
140+
141+
// Add test specs with proper execution functions
142+
testSpecs := extensiontests.ExtensionTestSpecs{
143+
createTestSpec(
144+
"[Jira:kube-controller-manager][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-controller-manager-operator/conformance/parallel]",
145+
"openshift:payload:cluster-kube-controller-manager-operator",
146+
[]string{
147+
"/test/extended/main.go:8",
148+
"/test/extended/main.go:9",
149+
},
150+
),
151+
}
152+
ext.AddSpecs(testSpecs)
153+
154+
// Register the extension
155+
registry.Register(ext)
156+
157+
// Create root command with default extension commands
158+
rootCmd := &cobra.Command{
159+
Use: "cluster-kube-controller-manager-operator-tests-ext",
160+
Short: "OpenShift kube-controller-manager operator tests extension",
161+
}
162+
163+
// Add all the default extension commands (info, list, run-test, run-suite, update)
164+
rootCmd.AddCommand(cmd.DefaultExtensionCommands(registry)...)
165+
166+
// Execute the command
167+
if err := rootCmd.Execute(); err != nil {
168+
os.Exit(1)
169+
}
170+
}

test/extended/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package extended
2+
3+
import (
4+
g "github.com/onsi/ginkgo/v2"
5+
o "github.com/onsi/gomega"
6+
)
7+
8+
var _ = g.Describe("[Jira:kube-controller-manager][sig-api-machinery] sanity test", func() {
9+
g.It("should always pass [Suite:openshift/cluster-kube-controller-manager-operator/conformance/parallel]", func() {
10+
o.Expect(true).To(o.BeTrue())
11+
})
12+
})

0 commit comments

Comments
 (0)