Skip to content

Commit 51facb3

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

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-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.

cmd/cluster-version-operator-tests/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ It integrates [openshift-tests-extension](https://github.com/openshift-eng/opens
44
cluster-version-operator which allows openshift components to contribute tests to openshift-tests' suites with
55
extension binaries.
66

7+
## Prerequisites
8+
- Install golang, the version number must be greater than or equal to the version number in go.mod. Here is the how-to doc https://go.dev/doc/install
9+
- Have the environment variable `KUBECONFIG` set pointing to your cluster.
10+
11+
## Build the executable binary
12+
In root folder, run below command to build executable binary:
13+
```console
14+
$ make build
15+
```
16+
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.
717

818
## Run the tests locally
919

@@ -21,4 +31,10 @@ After [installing-ginkgo](https://onsi.github.io/ginkgo/#installing-ginkgo):
2131
$ ginkgo ./test/...
2232
```
2333

34+
## Using binary
35+
```console
36+
$ _output/linux/amd64/cluster-version-operator-tests run-test <test case name>
37+
```
38+
Note: `test case name` can be found in .openshift-tests-extension/openshift_payload_cluster-version-operator.json
39+
2440
The output looks nicer this way.

test/cvo/cvo.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
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+
kerrors "k8s.io/apimachinery/pkg/api/errors"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/client-go/kubernetes"
11+
12+
"github.com/openshift/cluster-version-operator/test/utilities"
613
)
714

8-
var _ = Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", func() {
9-
It("should support passing tests", func() {
10-
Expect(true).To(BeTrue())
15+
var _ = g.Describe("[Jira:Cluster Version Operator] The cluster version operator", g.Ordered, g.Label("cvo"), func() {
16+
defer g.GinkgoRecover()
17+
var client *kubernetes.Clientset
18+
19+
g.BeforeAll(func() {
20+
client = utilities.MustGetKubeClient()
21+
})
22+
23+
24+
g.It("the removed resources are not created in a fresh installed cluster", g.Label("High", "42543"), func() {
25+
g.By("Service controller-manager-service should not be installed")
26+
_, err := client.CoreV1().Services("openshift-cloud-credential-operator").Get(context.TODO(), "controller-manager-service", metav1.GetOptions{})
27+
o.Expect(kerrors.IsNotFound(err)).To(o.BeTrue(), "Service controller-manager-service was accidentally installed")
28+
29+
g.By("ClusterRoleBindings default-account-openshift-machine-config-operator should not be installed")
30+
_, err = client.RbacV1().ClusterRoleBindings().Get(context.TODO(), "default-account-openshift-machine-config-operator", metav1.GetOptions{})
31+
o.Expect(kerrors.IsNotFound(err)).To(o.BeTrue(), "ClusterRoleBinding default-account-openshift-machine-config-operator was accidentally installed")
32+
33+
g.By("CronJobs machine-config-nodes-crd-cleanup should not be installed")
34+
_, err = client.BatchV1().CronJobs("openshift-machine-config-operator").Get(context.TODO(), "machine-config-nodes-crd-cleanup", metav1.GetOptions{})
35+
o.Expect(kerrors.IsNotFound(err)).To(o.BeTrue(), "CronJob machine-config-nodes-crd-cleanup was accidentally installed")
1136
})
1237
})

test/utilities/connection.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package utilities
2+
3+
import (
4+
"os"
5+
6+
"k8s.io/client-go/kubernetes"
7+
"k8s.io/client-go/tools/clientcmd"
8+
)
9+
10+
// MustGetKubeClient will create a kubernetes.Clientset object instance.
11+
//
12+
// The function returns an instance of kubernetes.Clientset when it success
13+
func MustGetKubeClient() *kubernetes.Clientset {
14+
configPath, present := os.LookupEnv("KUBECONFIG")
15+
if present {
16+
config, err := clientcmd.BuildConfigFromFlags("", configPath)
17+
if err != nil {
18+
panic("Unable not load KUBECONFIG: " + err.Error())
19+
}
20+
// Create the Clientset
21+
clientset, err := kubernetes.NewForConfig(config)
22+
if err != nil {
23+
panic("Create kubernetes.Clientset failed: " + err.Error())
24+
}
25+
return clientset
26+
} else {
27+
panic("Environment variable KUBECONFIG must be set")
28+
}
29+
}

0 commit comments

Comments
 (0)