Skip to content

v0.1.0

Compare
Choose a tag to compare
@vladimirvivien vladimirvivien released this 03 Jan 23:01
· 376 commits to main since this release
8c683de

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

New Contributors

Full Changelog: v0.0.8...v0.1.0