Skip to content

Commit 3640c9f

Browse files
camilamacedo86ci-robot
authored andcommitted
UPSTREAM: <carry>: OTE: Simplify by remove option to configure tests to run outside of OCP
1 parent 34553e8 commit 3640c9f

10 files changed

Lines changed: 21 additions & 209 deletions

File tree

openshift/tests-extension/README.md

Lines changed: 5 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========================
33

44
This repository contains the OLMv1 tests for OpenShift.
5-
These tests run against OpenShift clusters and are meant to be used in the OpenShift CI/CD pipeline.
5+
These tests are designed to run exclusively on OpenShift clusters and are used in the OpenShift CI/CD pipeline.
66
They use the framework: https://github.com/openshift-eng/openshift-tests-extension
77

88
## How it works
@@ -117,8 +117,8 @@ Example ([source](https://github.com/openshift/release/blob/main/ci-operator/con
117117

118118
## How to Run the Tests Locally
119119

120-
The tests can be run locally using the `olmv1-tests-ext` binary against an OpenShift cluster or a vanilla Kubernetes cluster.
121-
Features and checks which are OpenShift-specific will be skipped when running against a vanilla Kubernetes cluster.
120+
The tests can be run locally using the `olmv1-tests-ext` binary against an OpenShift cluster.
121+
These tests are specifically designed for OpenShift and require OpenShift-specific APIs and features.
122122

123123
Use the environment variable `KUBECONFIG` to point to your cluster configuration file such as:
124124

@@ -127,9 +127,9 @@ KUBECONFIG=path/to/kubeconfig ./bin/olmv1-tests-ext run-test -n <test-name>
127127
```
128128

129129
To run tests that include tech preview features,
130-
you need a cluster with OLMv1 installed and those features enabled.
130+
you need an OpenShift cluster with OLMv1 installed and those features enabled.
131131

132-
### Local Test using OLMv1 and OCP
132+
### Local Test using OLMv1 on OpenShift
133133

134134
1. Use the `Cluster Bot` to create an OpenShift cluster with OLMv1 installed.
135135

@@ -155,99 +155,6 @@ export KUBECONFIG=~/.kube/cluster-bot.kubeconfig
155155
./bin/olmv1-tests-ext run-suite olmv1/all
156156
```
157157

158-
### Local Test using OLMv1 and Kind
159-
160-
**Prerequisites:**
161-
162-
Install OLMv1 before running the tests.
163-
You can use the `kind` tool to create a local Kubernetes cluster with OLMv1 installed.
164-
Furthermore, if you are using feature gates in your test you will need to
165-
ensure that those are enabled in your cluster.
166-
167-
**Example:**
168-
169-
export KUBECONFIG=$HOME/.kube/config
170-
171-
```shell
172-
$ ./bin/olmv1-tests-ext run-suite olmv1/all
173-
Running Suite: - /Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension
174-
===============================================================================================================
175-
Random Seed: 1753508546 - will randomize all specs
176-
177-
Will run 1 of 1 specs
178-
------------------------------
179-
[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should verify required CRDs are installed and active
180-
/Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension/test/olmv1.go:37
181-
[INFO] [env] Using kubeconfig: /Users/camilam/.kube/config[WARN] Skipping feature capability check: not OpenShift STEP: verifying CRD clusterextensions.olm.operatorframework.io @ 07/26/25 06:42:26.57
182-
STEP: verifying CRD clustercatalogs.olm.operatorframework.io @ 07/26/25 06:42:26.575
183-
• [0.026 seconds]
184-
------------------------------
185-
186-
Ran 1 of 1 Specs in 0.026 seconds
187-
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
188-
Running Suite: - /Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension
189-
===============================================================================================================
190-
Random Seed: 1753508546 - will randomize all specs
191-
192-
Will run 1 of 1 specs
193-
------------------------------
194-
[sig-olmv1] OLMv1 should pass a trivial sanity check
195-
/Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension/test/olmv1.go:26
196-
• [0.000 seconds]
197-
------------------------------
198-
199-
Ran 1 of 1 Specs in 0.000 seconds
200-
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
201-
[
202-
{
203-
"name": "[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should verify required CRDs are installed and active",
204-
"lifecycle": "blocking",
205-
"duration": 26,
206-
"startTime": "2025-07-26 05:42:26.553886 UTC",
207-
"endTime": "2025-07-26 05:42:26.580057 UTC",
208-
"result": "passed",
209-
"output": "[INFO] [env] Using kubeconfig: /Users/camilam/.kube/config[WARN] Skipping feature capability check: not OpenShift STEP: verifying CRD clusterextensions.olm.operatorframework.io @ 07/26/25 06:42:26.57\n STEP: verifying CRD clustercatalogs.olm.operatorframework.io @ 07/26/25 06:42:26.575\n"
210-
},
211-
{
212-
"name": "[sig-olmv1] OLMv1 should pass a trivial sanity check",
213-
"lifecycle": "blocking",
214-
"duration": 26,
215-
"startTime": "2025-07-26 05:42:26.553852 UTC",
216-
"endTime": "2025-07-26 05:42:26.580263 UTC",
217-
"result": "passed",
218-
"output": ""
219-
}
220-
]
221-
```
222-
223-
## Writing Tests
224-
225-
You can write tests in the `openshift/tests-extension/tests/` directory.
226-
Please follow these guidelines:
227-
228-
1. Skip OpenShift-specific logic on vanilla Kubernetes
229-
230-
If your test requires OpenShift-only APIs (e.g., clusterversions.config.openshift.io),
231-
guard it using `env.Get().IsOpenShift` to ensure it skips gracefully when running
232-
on vanilla Kubernetes clusters:
233-
234-
```go
235-
if !env.Get().IsOpenShift {
236-
extlogs.Warn("Skipping test: not running on OpenShift")
237-
Skip("This test requires OpenShift APIs")
238-
}
239-
```
240-
241-
Or, if used within helper functions:
242-
```go
243-
if !env.Get().IsOpenShift {
244-
extlogs.Warn("Skipping feature capability check: not OpenShift")
245-
return
246-
}
247-
```
248-
249-
This ensures compatibility when running tests in non-OpenShift environments such as KinD.
250-
251158
## Development Workflow
252159

253160
- Add or update tests in: `openshift/tests-extension/tests/`

openshift/tests-extension/pkg/env/cluster.go

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2020
"k8s.io/apimachinery/pkg/runtime"
2121
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
22-
"k8s.io/client-go/discovery"
2322
"k8s.io/client-go/rest"
2423
"k8s.io/client-go/tools/clientcmd"
2524
crclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -30,18 +29,16 @@ import (
3029
)
3130

3231
// TestEnv holds the test environment state, including the Kubernetes REST config,
33-
// controller-runtime client, and a flag indicating if the cluster is OpenShift.
32+
// controller-runtime client, and OpenShift version.
33+
// These tests are designed to run on OpenShift clusters only.
3434
type TestEnv struct {
3535
// RestCfg stores the Kubernetes REST configuration used by clients
3636
RestCfg *rest.Config
3737

3838
// Controller-runtime client for interacting with the cluster
3939
K8sClient crclient.Client
4040

41-
// True if the cluster is detected as an OpenShift environment
42-
IsOpenShift bool
43-
44-
// Set to the MAJOR.MINOR version of OpenShift, blank otherwise
41+
// Set to the MAJOR.MINOR version of OpenShift
4542
OpenShiftVersion string
4643
}
4744

@@ -79,8 +76,6 @@ func Init() *TestEnv {
7976
// })
8077
func initTestEnv() *TestEnv {
8178
cfg := getRestConfig()
82-
discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(cfg)
83-
isOcp := detectOpenShift(discoveryClient)
8479

8580
// Create the runtime scheme and register all necessary types
8681
scheme := runtime.NewScheme()
@@ -91,29 +86,28 @@ func initTestEnv() *TestEnv {
9186
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
9287
utilruntime.Must(admissionregistrationv1.AddToScheme(scheme))
9388
utilruntime.Must(olmv1.AddToScheme(scheme))
94-
95-
if isOcp {
96-
utilruntime.Must(buildv1.AddToScheme(scheme))
97-
utilruntime.Must(configv1.AddToScheme(scheme))
98-
utilruntime.Must(imagev1.AddToScheme(scheme))
99-
utilruntime.Must(operatorv1.AddToScheme(scheme))
100-
}
89+
utilruntime.Must(buildv1.AddToScheme(scheme))
90+
utilruntime.Must(configv1.AddToScheme(scheme))
91+
utilruntime.Must(imagev1.AddToScheme(scheme))
92+
utilruntime.Must(operatorv1.AddToScheme(scheme))
10193

10294
k8sClient, err := crclient.New(cfg, crclient.Options{Scheme: scheme})
10395
if err != nil {
10496
log.Fatalf("failed to create controller-runtime client: %v", err)
10597
}
10698

107-
version := ""
108-
if isOcp {
109-
extlogs.Infof("[env] Cluster environment initialized (OpenShift: %t)\n", isOcp)
110-
version = getOcpVersion(k8sClient)
99+
version := getOcpVersion(k8sClient)
100+
if version != "" {
101+
extlogs.Infof("[env] Detected OpenShift version: %s\n", version)
102+
} else {
103+
extlogs.Warn("[env] Could not detect OpenShift version")
111104
}
112105

106+
extlogs.Infof("[env] Cluster environment initialized successfully\n")
107+
113108
return &TestEnv{
114109
RestCfg: cfg,
115110
K8sClient: k8sClient,
116-
IsOpenShift: isOcp,
117111
OpenShiftVersion: version,
118112
}
119113
}
@@ -122,10 +116,12 @@ func getOcpVersion(c crclient.Client) string {
122116
cv := &configv1.ClusterVersion{}
123117
err := c.Get(context.Background(), crclient.ObjectKey{Name: "version"}, cv)
124118
if err != nil {
119+
extlogs.WarnContextf("failed to get ClusterVersion resource: %v", err)
125120
return ""
126121
}
127122
v, err := bsemver.Parse(cv.Status.Desired.Version)
128123
if err != nil {
124+
extlogs.WarnContextf("failed to parse OpenShift version '%s': %v", cv.Status.Desired.Version, err)
129125
return ""
130126
}
131127
return fmt.Sprintf("%d.%d", v.Major, v.Minor)
@@ -153,23 +149,6 @@ func getRestConfig() *rest.Config {
153149
return configureQPS(cfg)
154150
}
155151

156-
// detectOpenShift checks if the cluster is an OpenShift cluster.
157-
// It does this by looking for the "config.openshift.io" API group,
158-
// which only exists in OpenShift environments.
159-
func detectOpenShift(d discovery.DiscoveryInterface) bool {
160-
groups, err := d.ServerGroups()
161-
if err != nil {
162-
extlogs.WarnContextf("failed to list API groups: %v", err)
163-
return false
164-
}
165-
for _, g := range groups.Groups {
166-
if g.Name == "config.openshift.io" {
167-
return true
168-
}
169-
}
170-
return false
171-
}
172-
173152
// configureQPS sets high QPS and burst values to avoid client-side throttling during tests.
174153
// This makes tests faster by allowing many API calls without delay.
175154
// It's mainly needed in serial tests, where slow or throttled requests can cause flakes.

openshift/tests-extension/pkg/helpers/feature_capability.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ import (
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515

1616
"github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/env"
17-
"github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/extlogs"
1817
)
1918

2019
// RequireOLMv1CapabilityOnOpenshift checks if the OpenShift cluster has
2120
// OLMv1 capability enabled. If not, it skips the test with a message.
2221
func RequireOLMv1CapabilityOnOpenshift() {
23-
if !env.Get().IsOpenShift {
24-
extlogs.Warn("Skipping feature capability check: not OpenShift")
25-
return
26-
}
2722
ctx := context.TODO()
2823
clientset := configv1Client()
2924
cv, err := clientset.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{})

openshift/tests-extension/pkg/helpers/image_registry.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import (
1818
// This is necessary for tests that depend on the internal image registry service at
1919
// image-registry.openshift-image-registry.svc:5000
2020
func RequireImageRegistry(ctx context.Context) {
21-
if !env.Get().IsOpenShift {
22-
extlogs.Warn("Skipping image-registry check: not OpenShift")
23-
return
24-
}
25-
2621
clientset, err := kubernetes.NewForConfig(env.Get().RestCfg)
2722
if err != nil {
2823
extlogs.WarnContextf("Failed to create kubernetes client for image-registry check: %v", err)

openshift/tests-extension/test/olmv1-boxcutter.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMBoxCutterRuntime] OLMv1 Boxcu
2727
var unique, nsName, ccName, opName string
2828

2929
BeforeEach(func(ctx SpecContext) {
30-
if !env.Get().IsOpenShift {
31-
Skip("Requires OpenShift for Boxcutter runtime tests")
32-
}
3330
helpers.RequireFeatureGateEnabled(features.FeatureGateNewOLMBoxCutterRuntime)
3431
helpers.RequireImageRegistry(ctx)
3532

openshift/tests-extension/test/olmv1-catalog.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1
3333
})
3434

3535
It("should be installed", func(ctx SpecContext) {
36-
if !env.Get().IsOpenShift {
37-
Skip("Skipping test because it requires OpenShift Catalogs")
38-
}
39-
4036
k8sClient := env.Get().K8sClient
4137

4238
catalogs := []string{
@@ -159,9 +155,6 @@ func verifyCatalogEndpoint(ctx SpecContext, catalog, endpoint, query string) {
159155
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 openshift-community-operators Catalog", func() {
160156
BeforeEach(func() {
161157
helpers.RequireOLMv1CapabilityOnOpenshift()
162-
if !env.Get().IsOpenShift {
163-
Skip("This test requires OpenShift Catalogs")
164-
}
165158
})
166159
It("should serve FBC via the /v1/api/all endpoint", func(ctx SpecContext) {
167160
verifyCatalogEndpoint(ctx, "openshift-community-operators", "all", "")
@@ -171,9 +164,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1
171164
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 openshift-certified-operators Catalog", func() {
172165
BeforeEach(func() {
173166
helpers.RequireOLMv1CapabilityOnOpenshift()
174-
if !env.Get().IsOpenShift {
175-
Skip("This test requires OpenShift Catalogs")
176-
}
177167
})
178168
It("should serve FBC via the /v1/api/all endpoint", func(ctx SpecContext) {
179169
verifyCatalogEndpoint(ctx, "openshift-certified-operators", "all", "")
@@ -183,9 +173,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1
183173
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 openshift-redhat-operators Catalog", func() {
184174
BeforeEach(func() {
185175
helpers.RequireOLMv1CapabilityOnOpenshift()
186-
if !env.Get().IsOpenShift {
187-
Skip("This test requires OpenShift Catalogs")
188-
}
189176
})
190177
It("should serve FBC via the /v1/api/all endpoint", func(ctx SpecContext) {
191178
verifyCatalogEndpoint(ctx, "openshift-redhat-operators", "all", "")
@@ -195,9 +182,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1
195182
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected] OLMv1 openshift-community-operators Catalog", func() {
196183
BeforeEach(func() {
197184
helpers.RequireOLMv1CapabilityOnOpenshift()
198-
if !env.Get().IsOpenShift {
199-
Skip("This test requires OpenShift Catalogs")
200-
}
201185
})
202186
It("should serve FBC via the /v1/api/metas endpoint", func(ctx SpecContext) {
203187
verifyCatalogEndpoint(ctx, "openshift-community-operators", "metas", "?schema=olm.package")
@@ -207,9 +191,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:D
207191
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected] OLMv1 openshift-certified-operators Catalog", func() {
208192
BeforeEach(func() {
209193
helpers.RequireOLMv1CapabilityOnOpenshift()
210-
if !env.Get().IsOpenShift {
211-
Skip("This test requires OpenShift Catalogs")
212-
}
213194
})
214195
It("should serve FBC via the /v1/api/metas endpoint", func(ctx SpecContext) {
215196
verifyCatalogEndpoint(ctx, "openshift-certified-operators", "metas", "?schema=olm.package")
@@ -219,9 +200,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:D
219200
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected] OLMv1 openshift-redhat-operators Catalog", func() {
220201
BeforeEach(func() {
221202
helpers.RequireOLMv1CapabilityOnOpenshift()
222-
if !env.Get().IsOpenShift {
223-
Skip("This test requires OpenShift Catalogs")
224-
}
225203
})
226204
It("should serve FBC via the /v1/api/metas endpoint", func(ctx SpecContext) {
227205
verifyCatalogEndpoint(ctx, "openshift-redhat-operators", "metas", "?schema=olm.package")

openshift/tests-extension/test/olmv1-deploymentconfig.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMConfigAPI][Skipped:Disconnect
4141

4242
BeforeAll(func(ctx SpecContext) {
4343
By("checking prerequisites")
44-
if !env.Get().IsOpenShift {
45-
Skip("Requires OpenShift for the tests")
46-
}
4744
helpers.RequireOLMv1CapabilityOnOpenshift()
4845
helpers.RequireImageRegistry(ctx)
4946
k8sClient = env.Get().K8sClient

openshift/tests-extension/test/olmv1-incompatible.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 operator installation
4747
})
4848
It("should block cluster upgrades if an incompatible operator is installed",
4949
Label("original-name:[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator installation should block cluster upgrades if an incompatible operator is installed"), func(ctx SpecContext) {
50-
if !env.Get().IsOpenShift {
51-
Skip("Requires OCP APIs: not OpenShift")
52-
}
53-
5450
By("waiting for InstalledOLMOperatorUpgradable to be true")
5551
waitForOlmUpgradeStatus(ctx, operatorv1.ConditionTrue, "")
5652

0 commit comments

Comments
 (0)