kubernetes/test/e2e/framework
Kubernetes Prow Robot 3cf75a2f76
Merge pull request #103177 from arkbriar/support_cancelable_exec_stream
Support cancelable SPDY executor stream
2022-11-02 19:47:36 -07:00
..
auth e2e framework: eliminate redundant framework/[log|ginkgowrapper] 2022-10-06 08:16:47 +02:00
autoscaling e2e framework: move dumping of information into sub package 2022-10-06 08:16:47 +02:00
config Generate and format files 2022-07-26 13:14:05 -04:00
daemonset Make daemon.NodeShouldRunDaemonPod function public 2022-03-08 11:32:17 +00:00
debug e2e framework: remove AddonResourceConstraints 2022-10-06 08:19:47 +02:00
deployment Fix container name on NewDeployment() 2021-10-27 22:46:11 +00:00
endpoints hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
endpointslice Update e2e tests to use EndpointSlice v1 API 2021-03-08 09:44:47 -08:00
events e2e: deflake test by not relying on events 2021-05-06 10:49:21 +02:00
gpu hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
ingress e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
internal e2e: adapt to modified Ginkgo output 2022-10-17 15:12:41 +02:00
job e2e: adapt to moved code 2022-10-06 08:19:47 +02:00
kubectl e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
kubelet test/e2e: fix GetCurrentKubeletConfig 2022-06-30 14:57:12 +03:00
kubesystem hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
manifest e2e: adapt to moved code 2022-10-06 08:19:47 +02:00
metrics e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
network e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
node e2e: skip AllNodesReady when the test skipped framework initialization 2022-10-17 10:27:14 +02:00
perf various corrections in test/e2e package 2022-09-16 18:59:30 +05:30
pod Merge pull request #103177 from arkbriar/support_cancelable_exec_stream 2022-11-02 19:47:36 -07:00
providers e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
pv move storage class helpers to utils 2022-08-02 20:52:04 +02:00
rc e2e framework: move node helper code into sub package 2022-10-06 08:16:47 +02:00
replicaset align some of the pod start up times 2021-04-02 11:29:38 -07:00
resource Fix HPA E2E CRD test 2022-09-21 22:39:47 +00:00
security e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
service e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
skipper Define the const of GINKGO_PANIC directly 2022-07-08 10:44:53 +08:00
ssh e2e framework: eliminate redundant framework/[log|ginkgowrapper] 2022-10-06 08:16:47 +02:00
statefulset e2e framework: eliminate interim sub packages 2022-10-06 08:16:47 +02:00
testfiles Rename variable error to err 2022-03-09 10:39:34 +08:00
timer e2e: adapt to moved code 2022-10-06 08:19:47 +02:00
volume Merge pull request #109924 from mauriciopoppe/provisioning-sync 2022-10-17 15:49:17 -07:00
websocket hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
.import-restrictions add warning for PVC template in statefulset and in pod ephemeral volume source 2022-10-22 09:14:03 +08:00
expect.go e2e: make failure message for unexpected errors more readable 2022-06-03 13:41:02 +02:00
flake_reporting_util.go fix pass []any as any in variadic function 2022-07-09 18:53:54 +08:00
framework.go e2e: skip AllNodesReady when the test skipped framework initialization 2022-10-17 10:27:14 +02:00
ginkgowrapper.go e2e: improve description of framework callbacks 2022-09-13 14:27:32 +02:00
log_test.go e2e framework: fix incorrect backtrace in Failf 2022-10-27 12:24:00 +02:00
log.go e2e framework: fix incorrect backtrace in Failf 2022-10-27 12:24:00 +02:00
nodes_util.go e2e framework: move NodeKiller into framework/node 2022-10-06 08:16:47 +02:00
OWNERS OWNERS cleanup - Jan 2021 Week 1 2022-01-10 08:14:29 -05:00
ports.go refactor(e2e): grab metrics from controller-manager via nginx 2021-05-03 00:12:06 +08:00
provider.go Fix volume creation and deletion of Azure File tests 2022-03-25 08:56:56 -03:00
README.md e2e framework: add top-level README.md 2022-10-06 08:19:47 +02:00
size.go
test_context.go e2e framework: move NodeKiller into framework/node 2022-10-06 08:16:47 +02:00
timeouts.go honor the framework delete timeout for pv 2022-05-03 17:20:10 +00:00
util.go e2e framework: move node helper code into sub package 2022-10-06 08:16:47 +02:00

Overview

The Kubernetes E2E framework simplifies writing Ginkgo tests suites. It's main usage is for these tests suites in the Kubernetes repository itself:

  • test/e2e: runs as client for a Kubernetes cluster. The e2e.test binary is used for conformance testing.
  • test/e2e_node: runs on the same node as a kublet instance. Used for testing kubelet.
  • test/e2e_kubeadm: test suite for kubeadm.

Usage of the framework outside of Kubernetes is possible, but not encouraged. Downstream users have to be prepared to deal with API changes.

Code Organization

The core framework is the k8s.io/kubernetes/test/e2e/framework package. It contains functionality that all E2E suites are expected to need:

  • connecting to the apiserver
  • managing per-test namespaces
  • logging (Logf)
  • failure handling (Fail, Failf)
  • writing concise JUnit test results

It also contains a TestContext with settings that can be controlled via command line flags. For historic reasons, this also contains settings for individual tests or packages that are not part of the core framework.

Optional functionality is placed in sub packages like test/e2e/framework/pod. The core framework does not depend on those. Sub packages may depend on the core framework.

The advantages of splitting the code like this are:

  • leaner go doc packages by grouping related functions together
  • not forcing all E2E suites to import all functionality
  • avoiding import cycles

Execution Flow

When a test suite gets invoked, the top-level Describe calls register the callbacks that define individual tests, but does not invoke them yet. After that init phase, command line flags are parsed and the Describe callbacks are invoked. Those then define the actual tests for the test suite. Command line flags can be used to influence the test definitions.

Now Context/BeforeEach/AfterEach/It define code that will be called later when executing a specific test. During this setup phase, f := framework.NewDefaultFramework("some tests") creates a Framework instance for one or more tests. NewDefaultFramework initializes that instance anew for each test with a BeforeEach callback. Starting with Kubernetes 1.26, that instance gets cleaned up after all other code for a test has been invoked, so the following code is correct:

f := framework.NewDefaultFramework("some tests")

ginkgo.AfterEach(func() {
    # Do something with f.ClientSet.
}

ginkgo.It("test something", func() {
    # The actual test.
})

Optional functionality can be injected into each test by adding a callback to NewFrameworkExtensions in an init function. NewDefaultFramework will invoke those callbacks as if the corresponding code had been added to each test like this:

f := framework.NewDefaultFramework("some tests")

optional.SomeCallback(f)

SomeCallback then can register additional BeforeEach or AfterEach callbacks that use the test's Framework instance.

When a test runs, callbacks defined for it with BeforeEach and AfterEach are called in first-in-first-out order. Since the migration to ginkgo v2 in Kubernetes 1.25, the AfterEach callback is called also when there has been a test failure. This can be used to run cleanup code for a test reliably. However, ginkgo.DeferCleanup is often a better alternative. Its callbacks are executed in first-in-last-out order.

test/e2e/framework/internal/unittests/cleanup/cleanup.go shows how these different callbacks can be used and in which order they are going to run.