Skip to content

Commit e666b9d

Browse files
camilamacedo86ci-robot
authored andcommitted
UPSTREAM: <carry>: OTE add first test from openshift/origin olmv1.go
1 parent ad73e97 commit e666b9d

File tree

2,377 files changed

+930604
-20578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,377 files changed

+930604
-20578
lines changed

openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@
88
"source": "openshift:payload:olmv1",
99
"lifecycle": "blocking",
1010
"environmentSelector": {}
11+
},
12+
{
13+
"name": "[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should be installed",
14+
"labels": {},
15+
"resources": {
16+
"isolation": {}
17+
},
18+
"source": "openshift:payload:olmv1",
19+
"lifecycle": "blocking",
20+
"environmentSelector": {}
1121
}
1222
]

openshift/tests-extension/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,110 @@ They use the framework: https://github.com/openshift-eng/openshift-tests-extensi
1515
| `./bin/olmv1-tests-ext run-suite olmv1/all` | Runs the full OLMv1 test suite. |
1616
| `./bin/olmv1-tests-ext run-test -n <test-name>` | Runs one specific test. Replace <test-name> with the test's full name. |
1717

18+
## How to Run the Tests locally
19+
20+
The tests can be run locally using the `olmv1-tests-ext` binary against an OpenShift cluster or a vanilla Kubernetes cluster.
21+
Features and checks which are OpenShift-specific will be skipped when running against a vanilla Kubernetes cluster.
22+
23+
Use the environment variable `KUBECONFIG` to point to your cluster configuration file.
24+
25+
```shell
26+
KUBECONFIG=path/to/kubeconfig ./bin/olmv1-tests-ext run-test -n <test-name>
27+
```
28+
29+
### Local Test using OLMv1 and Kind
30+
31+
**Prerequisites:**
32+
33+
Install OLMv1 before running the tests.
34+
You can use the `kind` tool to create a local Kubernetes cluster with OLMv1 installed.
35+
Furthermore, if you are using feature gates in your test you will need to
36+
ensure that those are enabled in your cluster.
37+
38+
**Example:**
39+
40+
export KUBECONFIG=$HOME/.kube/config
41+
42+
```shell
43+
$ ./bin/olmv1-tests-ext run-suite olmv1/all
44+
Running Suite: - /Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension
45+
===============================================================================================================
46+
Random Seed: 1753508546 - will randomize all specs
47+
48+
Will run 1 of 1 specs
49+
------------------------------
50+
[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should verify required CRDs are installed and active
51+
/Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension/test/olmv1.go:37
52+
[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
53+
STEP: verifying CRD clustercatalogs.olm.operatorframework.io @ 07/26/25 06:42:26.575
54+
• [0.026 seconds]
55+
------------------------------
56+
57+
Ran 1 of 1 Specs in 0.026 seconds
58+
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
59+
Running Suite: - /Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension
60+
===============================================================================================================
61+
Random Seed: 1753508546 - will randomize all specs
62+
63+
Will run 1 of 1 specs
64+
------------------------------
65+
[sig-olmv1] OLMv1 should pass a trivial sanity check
66+
/Users/camilam/go/src/github/operator-framework-operator-controller/openshift/tests-extension/test/olmv1.go:26
67+
• [0.000 seconds]
68+
------------------------------
69+
70+
Ran 1 of 1 Specs in 0.000 seconds
71+
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
72+
[
73+
{
74+
"name": "[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs should verify required CRDs are installed and active",
75+
"lifecycle": "blocking",
76+
"duration": 26,
77+
"startTime": "2025-07-26 05:42:26.553886 UTC",
78+
"endTime": "2025-07-26 05:42:26.580057 UTC",
79+
"result": "passed",
80+
"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"
81+
},
82+
{
83+
"name": "[sig-olmv1] OLMv1 should pass a trivial sanity check",
84+
"lifecycle": "blocking",
85+
"duration": 26,
86+
"startTime": "2025-07-26 05:42:26.553852 UTC",
87+
"endTime": "2025-07-26 05:42:26.580263 UTC",
88+
"result": "passed",
89+
"output": ""
90+
}
91+
]
92+
```
93+
94+
## Writing Tests
95+
96+
You can write tests in the `openshift/tests-extension/tests/` directory.
97+
Please follow these guidelines:
98+
99+
1. Skip OpenShift-specific logic on vanilla Kubernetes
100+
101+
If your test requires OpenShift-only APIs (e.g., clusterversions.config.openshift.io),
102+
guard it using `env.Get().IsOpenShift` to ensure it skips gracefully when running
103+
on vanilla Kubernetes clusters:
104+
105+
```go
106+
if !env.Get().IsOpenShift {
107+
extlogs.Warn("Skipping test: not running on OpenShift")
108+
Skip("This test requires OpenShift APIs")
109+
}
110+
```
111+
112+
Or, if used within helper functions:
113+
```go
114+
if !env.Get().IsOpenShift {
115+
extlogs.Warn("Skipping feature capability check: not OpenShift")
116+
return
117+
}
118+
```
119+
120+
This ensures compatibility when running tests in non-OpenShift environments such as KinD.
121+
18122
## Development Workflow
19123

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

openshift/tests-extension/cmd/main.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
// The import below is necessary to ensure that the OLMv1 tests are registered with the extension.
2323
_ "github/operator-framework-operator-controller/openshift/tests-extension/test"
24+
"github/operator-framework-operator-controller/openshift/tests-extension/test/env"
2425
)
2526

2627
func main() {
@@ -137,21 +138,10 @@ func main() {
137138
// Add more removed test names below
138139
)
139140

140-
// TODO: Init test framework for cluster-aware cases
141-
// --------------------------------------------------
142-
// The external binary doesn't currently init the test framework (e.g., kubeconfig, REST client).
143-
// That's fine for now since our tests don't access the cluster.
144-
// However, any test that does will fail when run with this binary.
145-
//
146-
// openshift-tests handles this via:
147-
// - SuiteWithKubeTestInitializationPreSuite()
148-
// -> calls DecodeProvider() and InitializeTestFramework()
149-
//
150-
// We'll need to add similar logic when we start add the tests here.
151-
//
152-
// References:
153-
// - https://github.com/openshift/origin/blob/main/pkg/cmd/openshift-tests/run/flags.go#L53
154-
// - https://github.com/openshift/origin/blob/main/pkg/clioptions/clusterdiscovery/provider.go#L100
141+
// Initialize the environment before running any tests.
142+
specs.AddBeforeAll(func() {
143+
env.Init()
144+
})
155145

156146
ext.AddSpecs(specs)
157147
registry.Register(ext)

openshift/tests-extension/go.mod

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,69 @@ module github/operator-framework-operator-controller/openshift/tests-extension
33
go 1.24.3
44

55
require (
6-
github.com/onsi/ginkgo/v2 v2.21.0
7-
github.com/onsi/gomega v1.35.1
6+
github.com/onsi/ginkgo/v2 v2.22.0
7+
github.com/onsi/gomega v1.36.1
88
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250722101414-8083129ab8f9
9+
github.com/openshift/api v0.0.0-20250718204806-3333746edfbf
10+
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee
911
github.com/spf13/cobra v1.8.1
12+
k8s.io/apiextensions-apiserver v0.33.2
13+
k8s.io/apimachinery v0.33.3
14+
k8s.io/client-go v0.33.2
15+
sigs.k8s.io/controller-runtime v0.21.0
1016
)
1117

1218
require (
13-
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
19+
cel.dev/expr v0.19.1 // indirect
20+
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
21+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
22+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
23+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
24+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
1425
github.com/go-logr/logr v1.4.2 // indirect
26+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
27+
github.com/go-openapi/jsonreference v0.20.2 // indirect
28+
github.com/go-openapi/swag v0.23.0 // indirect
1529
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
16-
github.com/google/cel-go v0.17.8 // indirect
17-
github.com/google/go-cmp v0.6.0 // indirect
30+
github.com/gogo/protobuf v1.3.2 // indirect
31+
github.com/google/cel-go v0.23.2 // indirect
32+
github.com/google/gnostic-models v0.6.9 // indirect
33+
github.com/google/go-cmp v0.7.0 // indirect
1834
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
35+
github.com/google/uuid v1.6.0 // indirect
1936
github.com/inconshreveable/mousetrap v1.1.0 // indirect
37+
github.com/josharian/intern v1.0.0 // indirect
38+
github.com/json-iterator/go v1.1.12 // indirect
39+
github.com/mailru/easyjson v0.7.7 // indirect
40+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
41+
github.com/modern-go/reflect2 v1.0.2 // indirect
42+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2043
github.com/pkg/errors v0.9.1 // indirect
2144
github.com/spf13/pflag v1.0.5 // indirect
22-
github.com/stoewer/go-strcase v1.2.0 // indirect
23-
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
24-
golang.org/x/net v0.30.0 // indirect
25-
golang.org/x/sys v0.26.0 // indirect
26-
golang.org/x/text v0.19.0 // indirect
45+
github.com/stoewer/go-strcase v1.3.0 // indirect
46+
github.com/x448/float16 v0.8.4 // indirect
47+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
48+
golang.org/x/net v0.38.0 // indirect
49+
golang.org/x/oauth2 v0.27.0 // indirect
50+
golang.org/x/sys v0.31.0 // indirect
51+
golang.org/x/term v0.30.0 // indirect
52+
golang.org/x/text v0.23.0 // indirect
53+
golang.org/x/time v0.9.0 // indirect
2754
golang.org/x/tools v0.26.0 // indirect
28-
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
29-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61 // indirect
30-
google.golang.org/protobuf v1.35.1 // indirect
55+
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
56+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
57+
google.golang.org/protobuf v1.36.5 // indirect
58+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
59+
gopkg.in/inf.v0 v0.9.1 // indirect
3160
gopkg.in/yaml.v3 v3.0.1 // indirect
61+
k8s.io/api v0.33.2 // indirect
62+
k8s.io/klog/v2 v2.130.1 // indirect
63+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
64+
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
65+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
66+
sigs.k8s.io/randfill v1.0.0 // indirect
67+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
68+
sigs.k8s.io/yaml v1.4.0 // indirect
3269
)
3370

3471
// This replace replace is required for we use the OCP fork of Ginkgo.

0 commit comments

Comments
 (0)