Skip to content

Commit bac7793

Browse files
committed
jianl - First e2e test
1 parent 75c15b5 commit bac7793

File tree

5 files changed

+141
-17
lines changed

5 files changed

+141
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
bin/
33
.DS_Store
44
_output
5+
.openshift-tests-extension

.openshift-tests-extension/openshift_payload_cluster-version-operator.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Cluster Version Operator Tests
2+
3+
We hold all e2e tests and related common methods in this folder.
4+
Test script are using client-go, here is the document: https://pkg.go.dev/k8s.io/client-go
5+
6+
## Prerequisites
7+
- Install golang, the version should match it in go.mod. Here is the how-to doc https://go.dev/doc/install
8+
- Have the environment variable `KUBECONFIG` set pointing to your cluster.
9+
10+
## Compile the executable binary
11+
In root folder, run below command to build executable binary:
12+
```
13+
$ make update
14+
```
15+
The executable binary can be found in ${BIN_PATH} folder, BIN_PATH is set in hack/build-info.sh, in linux it is _output/linux/amd64/ folder.
16+
17+
## Run test case
18+
19+
- Run below command to list all available tests:
20+
```
21+
$ _output/linux/amd64/cluster-version-operator-tests list
22+
```
23+
Output:
24+
```
25+
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$ _output/linux/amd64/cluster-version-operator-tests list
26+
[
27+
{
28+
"name": "[Jira:Cluster Version Operator] cluster-version-operator-tests Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster",
29+
"labels": {
30+
"42543": {},
31+
"High": {},
32+
"cvo": {}
33+
},
34+
"resources": {
35+
"isolation": {}
36+
},
37+
"source": "openshift:payload:cluster-version-operator",
38+
"lifecycle": "blocking",
39+
"environmentSelector": {}
40+
}
41+
]
42+
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$
43+
```
44+
- Run below command to execute a test case
45+
```
46+
$ _output/linux/amd64/cluster-version-operator-tests run-test <test case name>
47+
```
48+
or run test case in one line:
49+
50+
```
51+
$ _output/linux/amd64/cluster-version-operator-tests list | jq '.[] | select(.name | contains("42543")) | .name' | xargs _output/linux/amd64/cluster-version-operator-tests run-test
52+
```
53+
Output:
54+
```
55+
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$ _output/linux/amd64/cluster-version-operator-tests list | jq '.[] | select(.name | contains("42543")) | .name' | xargs _output/linux/amd64/cluster-version-operator-tests run-test
56+
Running Suite: - /home/jianl/1_code/cluster-version-operator
57+
=============================================================
58+
Random Seed: 1761292866 - will randomize all specs
59+
60+
Will run 1 of 1 specs
61+
------------------------------
62+
[Jira:Cluster Version Operator] cluster-version-operator-tests Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster [cvo, High, 42543]
63+
/home/jianl/1_code/cluster-version-operator/test/cvo/cvo.go:22
64+
STEP: Validate resource with 'release.openshift.io/delete: "true"' annotation is not installed @ 10/24/25 16:01:06.862
65+
• [1.428 seconds]
66+
------------------------------
67+
68+
Ran 1 of 1 Specs in 1.428 seconds
69+
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
70+
[
71+
{
72+
"name": "[Jira:Cluster Version Operator] cluster-version-operator-tests Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster",
73+
"lifecycle": "blocking",
74+
"duration": 1428,
75+
"startTime": "2025-10-24 08:01:06.858981 UTC",
76+
"endTime": "2025-10-24 08:01:08.287644 UTC",
77+
"result": "passed",
78+
"output": " STEP: Validate resource with 'release.openshift.io/delete: \"true\"' annotation is not installed @ 10/24/25 16:01:06.862\n"
79+
}
80+
]
81+
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$
82+
```

test/cvo/cvo.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
package cvo
22

33
import (
4-
. "github.com/onsi/ginkgo/v2"
5-
. "github.com/onsi/gomega"
4+
"context"
5+
6+
g "github.com/onsi/ginkgo/v2"
7+
o "github.com/onsi/gomega"
8+
"github.com/openshift/cluster-version-operator/test/utilities"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/client-go/kubernetes"
611
)
712

8-
var _ = Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", func() {
9-
It("should support passing tests", func() {
10-
Expect(true).To(BeTrue())
13+
var _ = g.Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", g.Ordered, g.Label("cvo"), func() {
14+
defer g.GinkgoRecover()
15+
var oc *kubernetes.Clientset
16+
17+
g.BeforeAll(func() {
18+
oc, _ = utilities.GetClient()
19+
o.Expect(oc).NotTo(o.BeNil())
20+
})
21+
22+
g.It("Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster", g.Label("High", "42543"), func() {
23+
g.By("Validate resource with 'release.openshift.io/delete: \"true\"' annotation is not installed")
24+
25+
_, err := oc.CoreV1().Services("openshift-cloud-credential-operator").Get(context.TODO(), "controller-manager-service", metav1.GetOptions{})
26+
o.Expect(err).To(o.HaveOccurred(), "Service controller-manager-service was accidentally installed")
27+
28+
_, err = oc.RbacV1().ClusterRoleBindings().Get(context.TODO(), "default-account-openshift-machine-config-operator", metav1.GetOptions{})
29+
o.Expect(err).To(o.HaveOccurred(), "ClusterRoleBinding default-account-openshift-machine-config-operator was accidentally installed")
30+
31+
_, err = oc.BatchV1().CronJobs("openshift-machine-config-operator").Get(context.TODO(), "machine-config-nodes-crd-cleanup", metav1.GetOptions{})
32+
o.Expect(err).To(o.HaveOccurred(), "CronJob machine-config-nodes-crd-cleanup was accidentally installed")
1133
})
1234
})

test/utilities/connection.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package utilities
2+
3+
import (
4+
"errors"
5+
"os"
6+
7+
"k8s.io/client-go/kubernetes"
8+
"k8s.io/client-go/tools/clientcmd"
9+
)
10+
11+
// getClient
12+
// @Description create a kubernetes.Clientset object
13+
// @Create jianl Oct 23 2025
14+
// @Return (Instance of kubernetes.Clientset, error)
15+
func GetClient() (*kubernetes.Clientset, error) {
16+
configPath, present := os.LookupEnv("KUBECONFIG")
17+
if present {
18+
config, err := clientcmd.BuildConfigFromFlags("", configPath)
19+
if err != nil {
20+
return nil, err
21+
}
22+
// Create the Clientset
23+
clientset, err := kubernetes.NewForConfig(config)
24+
if err != nil {
25+
return nil, err
26+
}
27+
return clientset, nil
28+
} else {
29+
return nil, errors.New("KUBECONFIG not set")
30+
}
31+
}

0 commit comments

Comments
 (0)