Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
bin/
.DS_Store
_output
.openshift-tests-extension

This file was deleted.

82 changes: 82 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Cluster Version Operator Tests

We hold all e2e tests and related common methods in this folder.
Test script are using client-go, here is the document: https://pkg.go.dev/k8s.io/client-go

## Prerequisites
- Install golang, the version should match it in go.mod. Here is the how-to doc https://go.dev/doc/install
- Have the environment variable `KUBECONFIG` set pointing to your cluster.

## Compile the executable binary
In root folder, run below command to build executable binary:
```
$ make update
```
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.

## Run test case

- Run below command to list all available tests:
```
$ _output/linux/amd64/cluster-version-operator-tests list
```
Output:
```
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$ _output/linux/amd64/cluster-version-operator-tests list
[
{
"name": "[Jira:Cluster Version Operator] cluster-version-operator-tests Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster",
"labels": {
"42543": {},
"High": {},
"cvo": {}
},
"resources": {
"isolation": {}
},
"source": "openshift:payload:cluster-version-operator",
"lifecycle": "blocking",
"environmentSelector": {}
}
]
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$
```
- Run below command to execute a test case
```
$ _output/linux/amd64/cluster-version-operator-tests run-test <test case name>
```
or run test case in one line:

```
$ _output/linux/amd64/cluster-version-operator-tests list | jq '.[] | select(.name | contains("42543")) | .name' | xargs _output/linux/amd64/cluster-version-operator-tests run-test
```
Output:
```
[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
Running Suite: - /home/jianl/1_code/cluster-version-operator
=============================================================
Random Seed: 1761292866 - will randomize all specs
Will run 1 of 1 specs
------------------------------
[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]
/home/jianl/1_code/cluster-version-operator/test/cvo/cvo.go:22
STEP: Validate resource with 'release.openshift.io/delete: "true"' annotation is not installed @ 10/24/25 16:01:06.862
• [1.428 seconds]
------------------------------
Ran 1 of 1 Specs in 1.428 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
[
{
"name": "[Jira:Cluster Version Operator] cluster-version-operator-tests Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster",
"lifecycle": "blocking",
"duration": 1428,
"startTime": "2025-10-24 08:01:06.858981 UTC",
"endTime": "2025-10-24 08:01:08.287644 UTC",
"result": "passed",
"output": " STEP: Validate resource with 'release.openshift.io/delete: \"true\"' annotation is not installed @ 10/24/25 16:01:06.862\n"
}
]
[jianl@jianl-thinkpadt14gen4 cluster-version-operator]$
```
32 changes: 27 additions & 5 deletions test/cvo/cvo.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
package cvo

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"context"

g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
"github.com/openshift/cluster-version-operator/test/utilities"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

var _ = Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", func() {
It("should support passing tests", func() {
Expect(true).To(BeTrue())
var _ = g.Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", g.Ordered, g.Label("cvo"), func() {
defer g.GinkgoRecover()
var oc *kubernetes.Clientset

g.BeforeAll(func() {
oc, _ = utilities.GetClient()
o.Expect(oc).NotTo(o.BeNil())
})

g.It("Author:jianl-High-42543-the removed resources are not created in a fresh installed cluster", g.Label("High", "42543"), func() {
g.By("Validate resource with 'release.openshift.io/delete: \"true\"' annotation is not installed")

_, err := oc.CoreV1().Services("openshift-cloud-credential-operator").Get(context.TODO(), "controller-manager-service", metav1.GetOptions{})
o.Expect(err).To(o.HaveOccurred(), "Service controller-manager-service was accidentally installed")

_, err = oc.RbacV1().ClusterRoleBindings().Get(context.TODO(), "default-account-openshift-machine-config-operator", metav1.GetOptions{})
o.Expect(err).To(o.HaveOccurred(), "ClusterRoleBinding default-account-openshift-machine-config-operator was accidentally installed")

_, err = oc.BatchV1().CronJobs("openshift-machine-config-operator").Get(context.TODO(), "machine-config-nodes-crd-cleanup", metav1.GetOptions{})
o.Expect(err).To(o.HaveOccurred(), "CronJob machine-config-nodes-crd-cleanup was accidentally installed")
})
})
31 changes: 31 additions & 0 deletions test/utilities/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utilities

import (
"errors"
"os"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

// getClient
// @Description create a kubernetes.Clientset object
// @Create jianl Oct 23 2025
// @Return (Instance of kubernetes.Clientset, error)
func GetClient() (*kubernetes.Clientset, error) {
configPath, present := os.LookupEnv("KUBECONFIG")
if present {
config, err := clientcmd.BuildConfigFromFlags("", configPath)
if err != nil {
return nil, err
}
// Create the Clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
return clientset, nil
} else {
return nil, errors.New("KUBECONFIG not set")
}
}