Skip to content

Commit c4b20bb

Browse files
authored
CLOUDP-81150: Replace operator-sdk test with envtest (#315)
1 parent a9b6102 commit c4b20bb

File tree

29 files changed

+483
-1175
lines changed

29 files changed

+483
-1175
lines changed

deploy/e2e/role.yaml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
creationTimestamp: null
5+
name: e2e-test
6+
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- pods
11+
- serviceaccounts
12+
- services
13+
- services/finalizers
14+
- endpoints
15+
- persistentvolumeclaims
16+
- events
17+
- configmaps
18+
- secrets
19+
- namespaces
20+
verbs:
21+
- create
22+
- delete
23+
- get
24+
- list
25+
- patch
26+
- update
27+
- watch
28+
- apiGroups:
29+
- apps
30+
resources:
31+
- deployments
32+
- daemonsets
33+
- replicasets
34+
- statefulsets
35+
verbs:
36+
- create
37+
- delete
38+
- get
39+
- list
40+
- patch
41+
- update
42+
- watch
43+
- apiGroups:
44+
- monitoring.coreos.com
45+
resources:
46+
- servicemonitors
47+
verbs:
48+
- get
49+
- create
50+
- apiGroups:
51+
- apps
52+
resourceNames:
53+
- mongodb-kubernetes-operator
54+
resources:
55+
- deployments/finalizers
56+
verbs:
57+
- update
58+
- apiGroups:
59+
- ""
60+
resources:
61+
- pods
62+
verbs:
63+
- get
64+
- apiGroups:
65+
- apps
66+
resources:
67+
- replicasets
68+
- deployments
69+
verbs:
70+
- get
71+
- apiGroups:
72+
- mongodb.com
73+
resources:
74+
- mongodbcommunity
75+
- mongodbcommunity/status
76+
- mongodbcommunity/spec
77+
verbs:
78+
- create
79+
- delete
80+
- get
81+
- list
82+
- patch
83+
- update
84+
- watch
85+
- apiGroups:
86+
- rbac.authorization.k8s.io
87+
resources:
88+
- rolebindings
89+
- roles
90+
- clusterrolebindings
91+
- clusterroles
92+
verbs:
93+
- create
94+
- delete
95+
- get
96+
- list
97+
- patch
98+
- update
99+
- watch

deploy/e2e/role_binding.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: e2e-test
5+
subjects:
6+
- kind: ServiceAccount
7+
name: e2e-test
8+
namespace: default
9+
roleRef:
10+
kind: ClusterRole
11+
name: e2e-test
12+
apiGroup: rbac.authorization.k8s.io

deploy/e2e/service_account.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: e2e-test

docs/contributing.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ realized that is is very important to have a clean environment to work, and as s
99
adopted a strategy that makes it easier for everyone to contribute.
1010

1111
This strategy is based on using
12-
[`operator-sdk`](https://github.com/operator-framework/operator-sdk) for running
13-
the tests, and making the test-runner itself run as a Kubernetes Pod. This
12+
[`envtest`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest) for setting up the tests
13+
and `go test` for running the tests, and making the test-runner itself run as a Kubernetes Pod. This
1414
makes it easier to run the tests in environments with access to a Kubernetes
1515
cluster with no go toolchain installed locally, making it easier to reproduce
1616
our local working environments in CI/CD systems.
@@ -41,7 +41,7 @@ each one of them in charge of some part of the lifecycle of the MongoDB database
4141

4242
# Developing locally
4343

44-
The operator is built using the latest stable `operator-sdk` and `golang`. We use a simple
44+
The operator is built using `golang`. We use a simple
4545
json file that describe some local options that you need to set for the testing environment
4646
to be able to run properly. Create a json file with the following content:
4747

@@ -137,13 +137,13 @@ python scripts/dev/e2e.py --help
137137
to get a list.
138138

139139
## Troubleshooting
140-
When you run a test locally, if the `operator-sdk-test` pod is present, you will have to
140+
When you run a test locally, if the `e2e-test` pod is present, you will have to
141141
first manually delete it; failing to do so will cause the `test-runner` pod to fail.
142142

143143
# Writing new E2E tests
144144

145145
You can start with `replica_set` test as an starting point to write a new test.
146-
The tests are written using `operator-sdk`.
146+
The tests are written using `envtest` and they are run using `go test`.
147147

148148
Adding a new test is as easy as to create a new directory in `test/e2e` with the
149149
new E2E test, and to run them:

go.mod

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@ go 1.14
44

55
require (
66
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
7+
github.com/go-logr/zapr v0.1.1 // indirect
8+
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
9+
github.com/golang/protobuf v1.4.2 // indirect
710
github.com/hashicorp/go-multierror v1.0.0
811
github.com/hashicorp/golang-lru v0.5.4 // indirect
912
github.com/imdario/mergo v0.3.9
1013
github.com/klauspost/compress v1.9.8 // indirect
11-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
12-
github.com/operator-framework/operator-sdk v0.19.4
14+
github.com/onsi/ginkgo v1.12.0 // indirect
15+
github.com/onsi/gomega v1.9.0 // indirect
1316
github.com/pkg/errors v0.9.1
17+
github.com/prometheus/client_golang v1.5.1 // indirect
1418
github.com/prometheus/procfs v0.0.11 // indirect
15-
github.com/rogpeppe/go-internal v1.5.2 // indirect
1619
github.com/stretchr/objx v0.3.0
1720
github.com/stretchr/testify v1.5.1
1821
github.com/xdg/stringprep v1.0.0
1922
go.mongodb.org/mongo-driver v1.3.2
2023
go.uber.org/zap v1.14.1
24+
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
25+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
26+
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
27+
golang.org/x/text v0.3.3 // indirect
28+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
29+
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b // indirect
2130
google.golang.org/appengine v1.6.6 // indirect
31+
google.golang.org/protobuf v1.25.0 // indirect
2232
k8s.io/api v0.18.2
2333
k8s.io/apimachinery v0.18.2
2434
k8s.io/client-go v12.0.0+incompatible

0 commit comments

Comments
 (0)