Skip to content

Commit 64e953e

Browse files
authored
Merge pull request #238 from crimsonfaith91/patch-3
Running End-to-end Tests on Remote Clusters
2 parents 800df6f + 364ec1c commit 64e953e

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

e2e.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
**Running End-to-end Tests on Remote Clusters**
2+
3+
This article outlines steps to run e2e tests on remote clusters for controllers created using `kubebuilder`. For example, after developing a database controller, the developer may want to run some e2e tests on a GKE cluster to verify the controller is working as expected. Currently, `kubebuilder` does not provide a template for running the e2e tests. This article serves to address this deficit.
4+
5+
The steps are as follow:
6+
1. Create a test file named `<some-file-name>_test.go` populated with template below (referring [this](https://github.com/foxish/application/blob/master/e2e/main_test.go)):
7+
```
8+
import (
9+
"k8s.io/client-go/tools/clientcmd"
10+
clientset "k8s.io/redis-operator/pkg/client/clientset/versioned/typed/<some-group>/<some-version>"
11+
......
12+
)
13+
14+
// Specify kubeconfig file
15+
func getClientConfig() (*rest.Config, error) {
16+
return clientcmd.BuildConfigFromFlags("", path.Join(os.Getenv("HOME"), "<file-path>"))
17+
}
18+
19+
// Set up test environment
20+
var _ = Describe("<some-controller-name> should work", func() {
21+
config, err := getClientConfig()
22+
if err != nil {
23+
......
24+
}
25+
26+
// Construct kubernetes client
27+
k8sClient, err := kubernetes.NewForConfig(config)
28+
if err != nil {
29+
......
30+
}
31+
32+
// Construct controller client
33+
client, err := clientset.NewForConfig(config)
34+
if err != nil {
35+
......
36+
}
37+
38+
BeforeEach(func() {
39+
// Create environment-specific resources such as controller image StatefulSet,
40+
// CRDs etc. Note: refer "install.yaml" created via "kubebuilder create config"
41+
// command to have an idea of what resources to be created.
42+
......
43+
})
44+
45+
AfterEach(func() {
46+
// Delete all test-specific resources
47+
......
48+
49+
// Delete all environment-specific resources
50+
......
51+
})
52+
53+
// Declare a list of testing specifications with corresponding test functions
54+
// Note: test-specific resources are normally created within the test functions
55+
It("should do something", func() {
56+
testDoSomething(k8sClient, roClient)
57+
})
58+
59+
......
60+
```
61+
2. Write some controller-specific e2e tests
62+
3. Build controller image and upload it to an image storage website such as [gcr.io](https://cloud.google.com/container-registry/)
63+
4. `go test <path-to-test-file>`

0 commit comments

Comments
 (0)