-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Running End-to-end Tests on Remote Clusters
- Loading branch information
1 parent
8b57ecb
commit 220a116
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
**Running End-to-end Tests on Remote Clusters** | ||
|
||
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. | ||
|
||
The steps are as follow: | ||
1. Create a test file named `<some-file-name>_test.go` populated with template below (refer [this](https://github.com/foxish/application/blob/master/e2e/main_test.go)): | ||
``` | ||
import ( | ||
"k8s.io/client-go/tools/clientcmd" | ||
clientset "k8s.io/redis-operator/pkg/client/clientset/versioned/typed/<some-group>/<some-version>" | ||
...... | ||
) | ||
// Specify kubeconfig file | ||
func getClientConfig() (*rest.Config, error) { | ||
return clientcmd.BuildConfigFromFlags("", path.Join(os.Getenv("HOME"), "<file-path>")) | ||
} | ||
// Set up test environment | ||
var _ = Describe("<some-controller-name> should work", func() { | ||
config, err := getClientConfig() | ||
if err != nil { | ||
...... | ||
} | ||
// Construct kubernetes client | ||
k8sClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
...... | ||
} | ||
// Construct controller client | ||
client, err := clientset.NewForConfig(config) | ||
if err != nil { | ||
...... | ||
} | ||
BeforeEach(func() { | ||
// Create controller image StatefulSet using kubernetes client | ||
// Note: Refer `install.yaml` created via `kubebuilder create config` | ||
// to have an idea on what the StatefulSet's fields should look like | ||
...... | ||
// Create other necessary resources before starting each test | ||
...... | ||
}) | ||
AfterEach(func() { | ||
// Delete all created resources for testing purpose | ||
...... | ||
// Delete controller image StatefulSet | ||
...... | ||
}) | ||
// Declare a list of testing specifications and corresponding test functions | ||
It("should do something", func() { | ||
testDoSomething(k8sClient, roClient) | ||
}) | ||
...... | ||
``` | ||
2. Write some controller-specific e2e tests | ||
3. Build controller image and upload it to an image storage website such as [gcr.io](https://cloud.google.com/container-registry/) | ||
4. `go test .` to run the e2e tests |