Skip to content

Commit 89ef392

Browse files
committed
set up openshift-tests-extension and add a sanity test
1 parent 216cf83 commit 89ef392

File tree

7 files changed

+180
-1
lines changed

7 files changed

+180
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/cluster-openshift-apiserver-operator
2+
/cluster-openshift-apiserver-operator-tests-ext
23
.idea/
34
telepresence.log

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.20 AS builder
22
WORKDIR /go/src/github.com/openshift/cluster-openshift-apiserver-operator
33
COPY . .
4-
RUN GODEBUG=tls13=1 go build ./cmd/cluster-openshift-apiserver-operator
4+
RUN GODEBUG=tls13=1 make build \
5+
&& make tests-ext-build \
6+
&& gzip cluster-openshift-apiserver-operator-tests-ext
57

68
FROM registry.ci.openshift.org/ocp/4.20:base-rhel9
79
COPY --from=builder /go/src/github.com/openshift/cluster-openshift-apiserver-operator/cluster-openshift-apiserver-operator /usr/bin/
10+
COPY --from=builder /go/src/github.com/openshift/cluster-openshift-apiserver-operator/cluster-openshift-apiserver-operator-tests-ext.gz /usr/bin/
811
COPY manifests /manifests
912
LABEL io.openshift.release.operator true

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ IMAGE_REGISTRY :=registry.svc.ci.openshift.org
1515
ENCRYPTION_PROVIDERS=aescbc aesgcm
1616
ENCRYPTION_PROVIDER?=aescbc
1717

18+
# -------------------------------------------------------------------
19+
# OpenShift Tests Extension (Cluster OpenShift API Server Operator)
20+
# -------------------------------------------------------------------
21+
TESTS_EXT_BINARY := cluster-openshift-apiserver-operator-tests-ext
22+
TESTS_EXT_PACKAGE := ./cmd/cluster-openshift-apiserver-operator-tests-ext
23+
24+
TESTS_EXT_GIT_COMMIT := $(shell git rev-parse --short HEAD)
25+
TESTS_EXT_BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
26+
TESTS_EXT_GIT_TREE_STATE := $(shell if git diff --quiet; then echo clean; else echo dirty; fi)
27+
28+
TESTS_EXT_LDFLAGS := -X 'github.com/openshift-eng/openshift-tests-extension/pkg/version.CommitFromGit=$(TESTS_EXT_GIT_COMMIT)' \
29+
-X 'github.com/openshift-eng/openshift-tests-extension/pkg/version.BuildDate=$(TESTS_EXT_BUILD_DATE)' \
30+
-X 'github.com/openshift-eng/openshift-tests-extension/pkg/version.GitTreeState=$(TESTS_EXT_GIT_TREE_STATE)'
31+
32+
1833
# This will call a macro called "build-image" which will generate image specific targets based on the parameters:
1934
# $0 - macro name
2035
# $1 - target name
@@ -77,6 +92,24 @@ test-e2e: GO_TEST_PACKAGES :=./test/e2e/...
7792
test-e2e: GO_TEST_FLAGS += -timeout 1h
7893
test-e2e: test-unit
7994

95+
# -------------------------------------------------------------------
96+
# Build binary with metadata (CI-compliant)
97+
# -------------------------------------------------------------------
98+
.PHONY: tests-ext-build
99+
tests-ext-build:
100+
GOOS=$(GOOS) GOARCH=$(GOARCH) GO_COMPLIANCE_POLICY=exempt_all CGO_ENABLED=0 \
101+
go build -o $(TESTS_EXT_BINARY) -ldflags "$(TESTS_EXT_LDFLAGS)" $(TESTS_EXT_PACKAGE)
102+
103+
# -------------------------------------------------------------------
104+
# Run "update" and strip env-specific metadata
105+
# -------------------------------------------------------------------
106+
.PHONY: tests-ext-update
107+
tests-ext-update: tests-ext-build
108+
./$(TESTS_EXT_BINARY) update
109+
for f in .openshift-tests-extension/*.json; do \
110+
jq 'map(del(.codeLocations))' "$$f" > tmpp && mv tmpp "$$f"; \
111+
done
112+
80113
# Configure the 'telepresence' target
81114
# See vendor/github.com/openshift/build-machinery-go/scripts/run-telepresence.sh for usage and configuration details
82115
export TP_DEPLOYMENT_YAML ?=./manifests/0000_30_openshift-apiserver-operator_07_deployment.yaml
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
This command is used to run the Cluster OpenShift API Server Operator tests extension for OpenShift.
3+
It registers the Cluster OpenShift API Server Operator tests with the OpenShift Tests Extension framework
4+
and provides a command-line interface to execute them.
5+
For further information, please refer to the documentation at:
6+
https://github.com/openshift-eng/openshift-tests-extension/blob/main/cmd/example-tests/main.go
7+
*/
8+
package main
9+
10+
import (
11+
"fmt"
12+
"os"
13+
"strings"
14+
15+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
16+
e "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"
19+
20+
"github.com/spf13/cobra"
21+
22+
// The import below is necessary to ensure that the OAS operator tests are registered with the extension.
23+
_ "github.com/openshift/cluster-openshift-apiserver-operator/test/extended"
24+
)
25+
26+
func main() {
27+
registry := e.NewRegistry()
28+
ext := e.NewExtension("openshift", "payload", "cluster-openshift-apiserver-operator")
29+
30+
// Suite: conformance/parallel (fast, parallel-safe)
31+
ext.AddSuite(e.Suite{
32+
Name: "openshift/cluster-openshift-apiserver-operator/conformance/parallel",
33+
Parents: []string{"openshift/conformance/parallel"},
34+
Qualifiers: []string{
35+
`!(name.contains("[Serial]") || name.contains("[Slow]"))`,
36+
},
37+
})
38+
39+
// Suite: conformance/serial (explicitly serial tests)
40+
ext.AddSuite(e.Suite{
41+
Name: "openshift/cluster-openshift-apiserver-operator/conformance/serial",
42+
Parents: []string{"openshift/conformance/serial"},
43+
Qualifiers: []string{
44+
`name.contains("[Serial]")`,
45+
},
46+
})
47+
48+
// Suite: optional/slow (long-running tests)
49+
ext.AddSuite(e.Suite{
50+
Name: "openshift/cluster-openshift-apiserver-operator/optional/slow",
51+
Parents: []string{"openshift/optional/slow"},
52+
Qualifiers: []string{
53+
`name.contains("[Slow]")`,
54+
},
55+
})
56+
57+
// Suite: all (includes everything)
58+
ext.AddSuite(e.Suite{
59+
Name: "openshift/cluster-openshift-apiserver-operator/all",
60+
})
61+
62+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
63+
if err != nil {
64+
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
65+
}
66+
67+
// Ensure [Disruptive] tests are also [Serial]
68+
specs = specs.Walk(func(spec *et.ExtensionTestSpec) {
69+
if strings.Contains(spec.Name, "[Disruptive]") && !strings.Contains(spec.Name, "[Serial]") {
70+
spec.Name = strings.ReplaceAll(
71+
spec.Name,
72+
"[Disruptive]",
73+
"[Serial][Disruptive]",
74+
)
75+
}
76+
})
77+
78+
// Preserve original-name labels for renamed tests
79+
specs = specs.Walk(func(spec *et.ExtensionTestSpec) {
80+
for label := range spec.Labels {
81+
if strings.HasPrefix(label, "original-name:") {
82+
parts := strings.SplitN(label, "original-name:", 2)
83+
if len(parts) > 1 {
84+
spec.OriginalName = parts[1]
85+
}
86+
}
87+
}
88+
})
89+
90+
// Ignore obsolete tests
91+
ext.IgnoreObsoleteTests(
92+
// "[sig-openshift-apiserver] <test name here>",
93+
)
94+
95+
// Initialize environment before running any tests
96+
specs.AddBeforeAll(func() {
97+
// do stuff
98+
})
99+
100+
ext.AddSpecs(specs)
101+
registry.Register(ext)
102+
103+
root := &cobra.Command{
104+
Long: "Cluster OpenShift API Server Operator Tests Extension",
105+
}
106+
107+
root.AddCommand(cmd.DefaultExtensionCommands(registry)...)
108+
109+
if err := root.Execute(); err != nil {
110+
os.Exit(1)
111+
}
112+
}

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ require (
66
github.com/ghodss/yaml v1.0.0
77
github.com/go-bindata/go-bindata v3.1.2+incompatible
88
github.com/gonum/graph v0.0.0-20190426092945-678096d81a4b
9+
github.com/onsi/ginkgo/v2 v2.23.4
10+
github.com/onsi/gomega v1.38.0
11+
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
912
github.com/openshift/api v0.0.0-20250724151358-f313adb86331
1013
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
1114
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee
@@ -123,3 +126,6 @@ require (
123126
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
124127
sigs.k8s.io/yaml v1.4.0 // indirect
125128
)
129+
130+
// This replace is required for we use the OCP fork of Ginkgo.
131+
replace github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241205171354-8006f302fd12
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"name": "[Jira:openshift-apiserver][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-apiserver-operator/conformance/parallel]",
4+
"labels": {},
5+
"resources": {
6+
"isolation": {}
7+
},
8+
"source": "openshift:payload:cluster-kube-apiserver-operator",
9+
"lifecycle": "blocking",
10+
"environmentSelector": {}
11+
}
12+
]

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:openshift-apiserver][sig-api-machinery] sanity test", func() {
9+
g.It("should always pass [Suite:openshift/cluster-openshift-apiserver-operator/conformance/parallel]", func() {
10+
o.Expect(true).To(o.BeTrue())
11+
})
12+
})

0 commit comments

Comments
 (0)