v0.1.0
The e2e-framework continues to evolve with useful features for code writers looking for tooling to test their components running in Kubernetes. As with previous releases, members of the community contributed the lion share of this release.
Version number change
After nearly 2 years of being in development, this release will adopt the minor version number, starting with v0.1.0
, to indicate the relative stability and continued adoption of the project.
Run commands inside pods
New in this release is the ability to programmatically launch commands that get executed inside a pod. This a useful feature that allows e2e-framework test writers to test code from within the pod itself. For instance, the following uses the ExecInPod
method call to check connectivity from whithin a running pod.
func TestExecPod(t *testing.T) {
deploymentName := "test-deployment"
containerName := "curl"
feature := features.New("Call external service").
Assess("check connectivity to wikipedia.org main page", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
client, _ := c.NewClient()
pods := &corev1.PodList{}
err = client.Resources(c.Namespace()).List(context.TODO(), pods)
if err != nil || pods.Items == nil {
t.Error("error while getting pods", err)
}
var stdout, stderr bytes.Buffer
podName := pods.Items[0].Name
command := []string{"curl", "-I", "https://en.wikipedia.org/wiki/Main_Page"}
err := client.Resources().ExecInPod(c.Namespace(), podName, containerName, command, &stdout, &stderr)
if err != nil {
t.Log(stderr.String())
t.Fatal(err)
}
httpStatus := strings.Split(stdout.String(), "\n")[0]
if !strings.Contains(httpStatus, "200") {
t.Fatal("Couldn't connect to en.wikipedia.org")
}
return ctx
}).Feature()
testEnv.Test(t, feature)
}
For further detail, see the example on ExecInPod
.
Support for Kubernetes-SIGs/Kubetest2
Another feature introduced in this release is the support for running e2e-framework tests using the kubetest2. Assuming that your environment has the kubetest2
binary and KinD installed on the OS path, the following example will launch kind, run the e2e-framework tests found in the specified package directory, and shutdown kind when done.
kubetest2 kind --up --down \
--test=e2e-framework -- \
--packages ./cluster \
--kubeconfig=$HOME/.kube/config \
--skip-assessments=pod-count
For additional detail on kubetest2 support, see README in the third_party directory.
Access to Controller-Runtime client
When writing tests, sometimes you may want to have direct access to the controller-runtime client being used in the framework or use an existing client in your code. This release allows test writers to inject an existing client or access the client being used by e2e-framework.
func TestClient() {
func TestExecPod(t *testing.T) {
feature := features.New("Client").
Assess("access client", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
e2eC, _ := c.NewClient()
ctrlC := e2eC.GetControllerRuntimeClient()
// use controller-runtime client directly
...
return ctx
}).Feature()
...
}
Other notable updates
- @harshanarayana added as project approver/maintainer for his many contributions
- Setup of GitHub
depabot
for automatic updates of source dependencies - Minor documentation and code fix updates
Contributors
Special thanks to all who contributed:
@harshanarayana
@v0lkc
@matrus2
@mitchmckenzie
@sozercan
@jbpratt
@cpanato
What's Changed
- chore: bump vladimirvivien/gexe to v0.2.0 by @v0lkc in #166
- Add ExecInPod method with an example test by @matrus2 in #167
- controller-runtime: enable ability to fetch controller runtime client by @harshanarayana in #156
- Fix decoder delete ignore not found by @mitchmckenzie in #170
- bump kind to 0.17 by @sozercan in #172
- enable dependabot scheduled updates by @jbpratt in #171
- update k8s dependencies by @cpanato in #181
- Bump sigs.k8s.io/controller-runtime from 0.13.1 to 0.14.0 by @dependabot in #182
- Bump sigs.k8s.io/controller-runtime from 0.14.0 to 0.14.1 by @dependabot in #183
- Support for an e2e-framework kubetest2 tester by @vladimirvivien in #168
- Adding harshanarayana as review/approver by @vladimirvivien in #184
New Contributors
- @v0lkc made their first contribution in #166
- @mitchmckenzie made their first contribution in #170
- @sozercan made their first contribution in #172
- @jbpratt made their first contribution in #171
Full Changelog: v0.0.8...v0.1.0