Skip to content

Commit 96b0e0b

Browse files
Merge pull request #1233 from Bowenislandsong/e2e_metric
adding e2e test framework for rh-operator metrics
2 parents 30838b7 + 8e4b5ad commit 96b0e0b

File tree

3 files changed

+737
-1
lines changed

3 files changed

+737
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ setup-bare: clean e2e.namespace
107107
. ./scripts/package_release.sh 1.0.0 test/e2e/resources test/e2e/e2e-bare-values.yaml
108108
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources
109109

110+
# e2e test exculding the rh-operators directory which tests rh-operators and their metric cardinality.
110111
e2e:
111-
go test -v $(MOD_FLAGS) -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager -dummyImage=bitnami/nginx:latest
112+
go test -v $(MOD_FLAGS) -failfast -timeout 70m `go list ./test/e2e/... | grep -v /rh-operators` -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager -dummyImage=bitnami/nginx:latest
112113

113114
e2e-local: build-linux build-wait
114115
. ./scripts/build_local.sh
@@ -121,6 +122,9 @@ e2e-local-docker:
121122
. ./scripts/build_local.sh
122123
. ./scripts/run_e2e_docker.sh $(TEST)
123124

125+
e2e-operator-metrics:
126+
go test -v $(MOD_FLAGS) -failfast -timeout 70m ./test/e2e/rh-operators
127+
124128
vendor:
125129
go mod tidy
126130
go mod vendor

test/e2e/rh-operators/metric_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package rh_operators
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
9+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
10+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
11+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
12+
pclient "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client"
13+
psVersioned "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned"
14+
15+
"github.com/sirupsen/logrus"
16+
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
18+
)
19+
20+
var (
21+
kubeconfig = os.Getenv("KUBECONFIG")
22+
testlog = logrus.New()
23+
)
24+
25+
// TestRHOperators installs all Red Hat Operators available on the cluster and see that they install successfully.
26+
func TestRHOperators(t *testing.T) {
27+
c := operatorclient.NewClientFromConfig(kubeconfig, testlog)
28+
29+
crc, err := pclient.NewClient(kubeconfig)
30+
require.NoError(t, err, "error creating package-server client")
31+
32+
vc, err := client.NewClient(kubeconfig)
33+
require.NoError(t, err, "error creating cr client")
34+
35+
// Serial Test operators with installModes other than typeOwnNamespace to avoid OperatorGroup intersection.
36+
operatorList, err := ListRHOperatorsWithoutInstallModes(crc, v1alpha1.InstallModeTypeOwnNamespace)
37+
require.NoError(t, err, "failed to list Red Hat Operators")
38+
39+
for _, operator := range operatorList {
40+
operatorName := operator
41+
t.Run(fmt.Sprintf("Testing for operator %s", operator), func(t *testing.T) {
42+
testInstallOperators(t, c, crc, vc, operatorName)
43+
})
44+
}
45+
46+
CleanupAll(t, c, vc)
47+
48+
operatorList, err = ListRHOperatorsByInstallModes(crc, v1alpha1.InstallModeTypeOwnNamespace)
49+
require.NoError(t, err, "failed to list Red Hat Operators with OwnNamespace InstallMode")
50+
51+
for _, operator := range operatorList {
52+
operatorName := operator
53+
t.Run(fmt.Sprintf("Testing for operator %s", operator), func(t *testing.T) {
54+
t.Parallel()
55+
testInstallOperators(t, c, crc, vc, operatorName)
56+
})
57+
}
58+
59+
CleanupAll(t, c, vc)
60+
}
61+
62+
// testInstallOperators installs operators and wait till its CSV is in succeeded phase then deletes created resources
63+
// and wait till the created Namespace is terminated.
64+
func testInstallOperators(t *testing.T, c operatorclient.ClientInterface, crc psVersioned.Interface,
65+
vc versioned.Interface, operatorName string) {
66+
t.Logf("Installing %s operator", operatorName)
67+
68+
o, err := NewOperator(c, crc, vc, operatorName)
69+
if err != nil {
70+
assert.Failf(t, err.Error(), "failed to load operator %s from packagemanifests", operatorName)
71+
return
72+
}
73+
74+
err = o.Subscribe()
75+
assert.NoError(t, err, "error creating subscription for operator %s", operatorName)
76+
77+
err = o.Unsubscribe(false)
78+
assert.NoError(t, err, "error cleaning up subscription for operator %s", operatorName)
79+
if err != nil {
80+
CleanupOperatorCSVs(t, o)
81+
CleanupOperatorNamespace(t, o)
82+
}
83+
84+
err = o.WaitToDeleteNamespace(o.namespace)
85+
if err != nil {
86+
t.Logf("error cleaning up Namespace: %s, %v", o.namespace, err)
87+
}
88+
}

0 commit comments

Comments
 (0)