kubernetes/test/e2e/framework
Kubernetes Prow Robot ec16c90aaf
Merge pull request #126593 from stlaz/trustbundles-e2e
KEP-3257: e2e: extend cluster trust bundles coverage
2024-10-19 00:51:03 +01:00
..
auth drop deprecated PollWithContext and adopt PollUntilContextTimeout instead 2024-06-21 19:23:31 +08:00
autoscaling test/e2e: do not use global variable for image 2024-04-22 19:29:39 +08:00
config e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
daemonset e2e daemon set: better polling in CheckDaemonStatus 2024-10-15 10:12:28 +02:00
debug Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
deployment e2e: add TERM trap to pod sleep command 2024-06-11 13:52:47 +08:00
endpoints e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
endpointslice e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
events use PollUntilContextTimeout to replace PollImmediateWithContext in test 2023-10-19 22:50:21 +08:00
gpu Remove remants of broken stuff - nvidia/autoscaling 2024-09-23 13:17:00 +00:00
ingress Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
internal fix: enable and fixes rules from testifylint on test package 2024-06-30 05:44:47 +00:00
job Fail fast when waiting for job conditions in e2e tests 2024-10-10 20:18:21 +00:00
kubectl e2e-framework: code cleanup for mismatched comments 2023-05-26 12:36:19 +08:00
kubelet e2e framework: remove dependency on k8s.io/kubernetes/pkg/api/v1/pod 2023-05-12 08:39:37 +08:00
kubesystem e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
manifest e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
metrics e2e/framework/metrics: handle index out of bounds panic 2024-06-15 00:42:11 +05:30
network Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
node test: refactor duplicate inplace pod resize test utilities 2024-10-17 05:35:40 -07:00
perf e2e framework: remove dependency on k8s.io/kubernetes/pkg/api/v1/pod 2023-05-12 08:39:37 +08:00
pod Merge pull request #126593 from stlaz/trustbundles-e2e 2024-10-19 00:51:03 +01:00
providers Remove gcp in-tree cloud provider and credential provider 2024-05-01 09:03:53 -04:00
pv Add Happy Path VolumeAttributesClass CSI E2E Tests 2024-06-10 20:03:54 +00:00
rc Replace a function closure 2023-02-27 09:13:36 -08:00
replicaset drop deprecated PollWithContext and adopt PollUntilContextTimeout instead 2024-06-21 19:23:31 +08:00
resource use PollUntilContextTimeout to replace PollImmediateWithContext in test 2023-10-19 22:50:21 +08:00
security Update AppArmor e2e tests 2024-03-05 12:22:50 -08:00
service drop deprecated PollWithContext and adopt PollUntilContextTimeout instead 2024-06-21 19:23:31 +08:00
skipper Merge pull request #123981 from lzhecheng/update-traffic-distribution-test 2024-10-01 15:53:49 +01:00
ssh Fix for DaemonRestart [Disruptive] tests 2024-08-31 21:15:23 -04:00
statefulset Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
testfiles fix: enable and fixes rules from testifylint on test package 2024-06-30 05:44:47 +00:00
timer remove deprecated framework.ExpectEqual 2023-10-11 12:43:10 +08:00
volume use PollUntilContextTimeout to replace PollImmediateWithContext in test 2023-10-19 22:50:21 +08:00
websocket e2e framework: control k/k/pkg imports 2023-04-17 00:17:16 +03:00
.import-restrictions Use sigs.k8s.io/yaml instead of gopkg.in/yaml 2024-10-07 15:32:00 +02:00
bugs.go e2e framework: track and report internal bugs 2023-10-10 18:15:46 +02:00
expect.go e2e framework: better documentation of ExpectNoError 2024-09-23 10:58:06 +02:00
expect_test.go fix: enable and fixes rules from testifylint on test package 2024-06-30 05:44:47 +00:00
flake_reporting_util.go Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
framework.go Fix Go vet errors for master golang 2024-09-20 12:36:38 +05:30
get.go e2e framework retry on Service unavailable errors 2023-05-25 11:22:45 +00:00
ginkgologger.go e2e framework: configure Ginkgo logger and klog consistently 2024-04-15 10:10:56 +02:00
ginkgowrapper.go e2e framework: clarify Alpha/Beta requirement for feature gates 2024-04-18 07:48:21 +02:00
ginkgowrapper_test.go e2e storage: use framework to tag tests 2023-10-23 17:32:06 +02:00
log.go e2e framework: unify logging, support skipping helpers 2024-01-20 18:23:31 +01:00
log_test.go enhance boolean assertions 2024-07-31 15:58:15 +00:00
namespacedname.go e2e framework: add NamespacedName 2023-01-16 09:05:37 +01:00
nodes_util.go e2e framework: move NodeKiller into framework/node 2022-10-06 08:16:47 +02:00
OWNERS /cmd/kubeadm,/test/e2e*: update OWNERS for fabriziopandini & RA489 2023-09-12 12:35:40 +03:00
ports.go refactor(e2e): grab metrics from controller-manager via nginx 2021-05-03 00:12:06 +08:00
provider.go e2e: use Ginkgo context 2022-12-16 20:14:04 +01:00
README.md Fix typos in markdown 2023-10-17 10:55:40 -04:00
size.go Separate e2enetwork from e2e core framework 2019-10-25 17:58:20 +00:00
test_context.go feat: Add cri proxy for e2e_node 2024-10-16 20:53:28 +08:00
timeouts.go DRA: e2e: test non-graceful node shutdown 2023-10-19 22:09:11 +03:00
util.go Print tested command only once 2024-10-01 15:28:55 +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 kubelet 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(ctx context.Context) {
    # 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.