This documentation provides detailed instructions for running tests in the Kubernetes source code, which is structured primarily in Go. Developers will learn how to run different types of tests, including integration tests, end-to-end tests, and command tests.
Overview of Test Types
Kubernetes categorizes its tests into several main types:
End-to-End (E2E) Tests: Focused on validating the entire system’s functionality. They are located in:
${KUBE_ROOT}/test/e2e/common
: Shared between Cluster and Node tests.${KUBE_ROOT}/test/e2e_node
: Specific to Node E2E tests.
Integration Tests: These test specific components or integrations within the Kubernetes ecosystem. They are typically found in the
test/integration
directory.Command Tests: Target the command-line interface of Kubernetes. They are located in
test/cmd
.
Running End-to-End Tests
To execute E2E tests, navigate to the Kubernetes root directory and create test resources using a YAML configuration file:
kubectl create -f conformance-e2e.yaml
(Refer to test/conformance/image/README.md for more details.)
Running Node E2E Tests
Run Node E2E tests from the command line after ensuring that your testing environment is properly set up. You can refer to test/e2e_node/README.md
for specific instructions related to Node testing.
Running Integration Tests
Integration tests can be executed by invoking the make
command. Here’s how to run the scheduler performance integration tests:
# In Kubernetes root path
make test-integration WHAT=./test/integration/scheduler_perf KUBE_TEST_ARGS=-use-testing-log
Stay informed on the specifics of the scheduler performance tests in test/integration/scheduler_perf/README.md
.
IPAM Performance Tests
To run IPAM performance tests, execute the following commands:
# In Kubernetes root path
cd test/integration/ipamperf
./test-performance.sh
The script has several options available for customization:
./test-performance.sh -h
This will display:
usage: ./test-performance.sh [-h] [-d] [-r <regex>] [-o <output_file>]
-h display this help message
-d enable debug logs in tests
-r regex pattern to match for tests
-o file to write JSON formatted results to
For additional information, refer to test/integration/ipamperf/README.md
.
Running Command Tests
To run the command test suite, use the following command from the top level of the Kubernetes repository:
make test-cmd
This command imports each file containing test functions, which follow the naming conventions specified in test/cmd/README.md
.
Running a Subset of Command Tests
If you wish to run a specific subset of tests, like deployment
and impersonation
tests, use the following:
make test-cmd WHAT="deployment impersonation"
(Refer to test/cmd/README.md
for more details on command test execution.)
Test Function Format
Any new test function that is added must follow the convention of being prefixed with run_*_tests
. This is necessary to ensure the function can be executed correctly. Here’s a typical example of how to add such tests in legacy-script.sh
:
###################### # Replica Sets # ######################
if kube::test::if_supports_resource "${replicasets}" ; then record_command run_rs_tests fi
In this example, validation for supported resources is handled by the kube::test::if_supports_resource
function, as outlined in test/cmd/README.md
.
Considerations When Running Tests
- Ensure that you run tests on supported architectures. The Kubernetes project has specific build constraints (
linux
,!windows
) which must be satisfied when executing tests. - When building with Go, do not use
-mod=vendor
as the build system for this project relies on Go modules.
For further guidance, always refer to the README files located within the appropriate test directories for the most relevant and up-to-date instructions specific to each testing category.
Sources
- test/integration/dryrun/dryrun_test.go
- test/images/agnhost/entrypoint-tester/ep.go
- pkg/kubelet/prober/common_test.go
- test/utils/oidc/testserver.go
- test/e2e_node/remote/types.go
- test/e2e/common/util.go
- test/integration/utils.go
- test/typecheck/main.go
- test/e2e/framework/ginkgowrapper.go
- test/conformance/walk.go
- pkg/proxy/nftables/helpers_test.go