Skip to content

Commit c25c7c7

Browse files
author
Isaac Hollander McCreery
committed
Reconcile testing docs, fixes kubernetes#18606
1 parent 11c42f7 commit c25c7c7

File tree

2 files changed

+106
-128
lines changed

2 files changed

+106
-128
lines changed

docs/devel/development.md

+1-103
Original file line numberDiff line numberDiff line change
@@ -294,109 +294,7 @@ hack/test-integration.sh
294294

295295
## End-to-End tests
296296

297-
You can run an end-to-end test which will bring up a master and two nodes, perform some tests, and then tear everything down. Make sure you have followed the getting started steps for your chosen cloud platform (which might involve changing the `KUBERNETES_PROVIDER` environment variable to something other than "gce".
298-
299-
```sh
300-
cd kubernetes
301-
hack/e2e-test.sh
302-
```
303-
304-
Pressing control-C should result in an orderly shutdown but if something goes wrong and you still have some VMs running you can force a cleanup with this command:
305-
306-
```sh
307-
go run hack/e2e.go --down
308-
```
309-
310-
### Flag options
311-
312-
See the flag definitions in `hack/e2e.go` for more options, such as reusing an existing cluster, here is an overview:
313-
314-
```sh
315-
# Build binaries for testing
316-
go run hack/e2e.go --build
317-
318-
# Create a fresh cluster. Deletes a cluster first, if it exists
319-
go run hack/e2e.go --up
320-
321-
# Create a fresh cluster at a specific release version.
322-
go run hack/e2e.go --up --version=0.7.0
323-
324-
# Test if a cluster is up.
325-
go run hack/e2e.go --isup
326-
327-
# Push code to an existing cluster
328-
go run hack/e2e.go --push
329-
330-
# Push to an existing cluster, or bring up a cluster if it's down.
331-
go run hack/e2e.go --pushup
332-
333-
# Run all tests
334-
go run hack/e2e.go --test
335-
336-
# Run tests matching the regex "Pods.*env"
337-
go run hack/e2e.go -v -test --test_args="--ginkgo.focus=Pods.*env"
338-
339-
# Alternately, if you have the e2e cluster up and no desire to see the event stream, you can run ginkgo-e2e.sh directly:
340-
hack/ginkgo-e2e.sh --ginkgo.focus=Pods.*env
341-
```
342-
343-
### Combining flags
344-
345-
```sh
346-
# Flags can be combined, and their actions will take place in this order:
347-
# -build, -push|-up|-pushup, -test|-tests=..., -down
348-
# e.g.:
349-
go run hack/e2e.go -build -pushup -test -down
350-
351-
# -v (verbose) can be added if you want streaming output instead of only
352-
# seeing the output of failed commands.
353-
354-
# -ctl can be used to quickly call kubectl against your e2e cluster. Useful for
355-
# cleaning up after a failed test or viewing logs. Use -v to avoid suppressing
356-
# kubectl output.
357-
go run hack/e2e.go -v -ctl='get events'
358-
go run hack/e2e.go -v -ctl='delete pod foobar'
359-
```
360-
361-
## Local clusters
362-
363-
It can be much faster to iterate on a local cluster instead of a cloud-based one. To start a local cluster, you can run:
364-
365-
```sh
366-
# The PATH construction is needed because PATH is one of the special-cased
367-
# environment variables not passed by sudo -E
368-
sudo PATH=$PATH hack/local-up-cluster.sh
369-
```
370-
371-
This will start a single-node Kubernetes cluster than runs pods using the local docker daemon. Press Control-C to stop the cluster.
372-
373-
### E2E tests against local clusters
374-
375-
In order to run an E2E test against a locally running cluster, use the `e2e.test` binary built by `hack/build-go.sh`
376-
directly:
377-
378-
```sh
379-
export KUBECONFIG=/path/to/kubeconfig
380-
e2e.test --host=http://127.0.0.1:8080
381-
```
382-
383-
To control the tests that are run:
384-
385-
```sh
386-
e2e.test --host=http://127.0.0.1:8080 --ginkgo.focus="Secrets"
387-
```
388-
389-
## Conformance testing
390-
391-
End-to-end testing, as described above, is for [development
392-
distributions](writing-a-getting-started-guide.md). A conformance test is used on
393-
a [versioned distro](writing-a-getting-started-guide.md).
394-
395-
The conformance test runs a subset of the e2e-tests against a manually-created cluster. It does not
396-
require support for up/push/down and other operations. To run a conformance test, you need to know the
397-
IP of the master for your cluster and the authorization arguments to use. The conformance test is
398-
intended to run against a cluster at a specific binary release of Kubernetes.
399-
See [conformance-test.sh](http://releases.k8s.io/HEAD/hack/conformance-test.sh).
297+
See [End-to-End Testing in Kubernetes](e2e-tests.md).
400298

401299
## Testing out flaky tests
402300

docs/devel/e2e-tests.md

+105-25
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,91 @@ Documentation for other releases can be found at
3232

3333
<!-- END MUNGE: UNVERSIONED_WARNING -->
3434

35-
# End-2-End Testing in Kubernetes
35+
# End-to-End Testing in Kubernetes
3636

3737
## Overview
3838

39-
The end-2-end tests for kubernetes provide a mechanism to test behavior of the system, and to ensure end user operations match developer specifications. In distributed systems it is not uncommon that a minor change may pass all unit tests, but cause unforseen changes at the system level. Thus, the primary objectives of the end-2-end tests are to ensure a consistent and reliable behavior of the kubernetes code base, and to catch bugs early.
39+
End-to-end (e2e) tests for Kubernetes provide a mechanism to test end-to-end behavior of the system, and is the last signal to ensure end user operations match developer specifications. Although unit and integration tests should ideally provide a good signal, the reality is in a distributed system like Kubernetes it is not uncommon that a minor change may pass all unit and integration tests, but cause unforseen changes at the system level. e2e testing is very costly, both in time to run tests and difficulty debugging, though: it takes a long time to build, deploy, and exercise a cluster. Thus, the primary objectives of the e2e tests are to ensure a consistent and reliable behavior of the kubernetes code base, and to catch hard-to-test bugs before users do, when unit and integration tests are insufficient.
4040

41-
The end-2-end tests in kubernetes are built atop of [ginkgo] (http://onsi.github.io/ginkgo/) and [gomega] (http://onsi.github.io/gomega/). There are a host of features that this BDD testing framework provides, and it is recommended that the developer read the documentation prior to diving into the tests.
41+
The e2e tests in kubernetes are built atop of [Ginkgo](http://onsi.github.io/ginkgo/) and [Gomega](http://onsi.github.io/gomega/). There are a host of features that this BDD testing framework provides, and it is recommended that the developer read the documentation prior to diving into the tests.
4242

43-
The purpose of *this* document is to serve as a primer for developers who are looking to execute, or add tests, using a local development environment.
43+
The purpose of *this* document is to serve as a primer for developers who are looking to execute or add tests using a local development environment.
4444

4545
## Building and Running the Tests
4646

47-
**NOTE:** The tests have an array of options. For simplicity, the examples will focus on leveraging the tests on a local cluster using `sudo ./hack/local-up-cluster.sh`
47+
There are a variety of ways to run e2e tests, but we aim to decrease the number of ways to run e2e tests to a canonical way: `hack/e2e.go`.
4848

49-
### Building the Tests
49+
You can run an end-to-end test which will bring up a master and nodes, perform some tests, and then tear everything down. Make sure you have followed the getting started steps for your chosen cloud platform (which might involve changing the `KUBERNETES_PROVIDER` environment variable to something other than "gce").
5050

51-
The tests are built into a single binary which can be run against any deployed kubernetes system. To build the tests, navigate to your source directory and execute:
51+
To build Kubernetes, up a cluster, run tests, and tear everything down, use:
5252

53-
`$ make all`
53+
```sh
54+
go run hack/e2e.go -v --build --up --test --down
55+
```
56+
57+
If you'd like to just perform one of these steps, here are some examples:
58+
59+
```sh
60+
# Build binaries for testing
61+
go run hack/e2e.go -v --build
62+
63+
# Create a fresh cluster. Deletes a cluster first, if it exists
64+
go run hack/e2e.go -v --up
65+
66+
# Create a fresh cluster at a specific release version.
67+
go run hack/e2e.go -v --up --version=0.7.0
68+
69+
# Test if a cluster is up.
70+
go run hack/e2e.go -v --isup
71+
72+
# Push code to an existing cluster
73+
go run hack/e2e.go -v --push
74+
75+
# Push to an existing cluster, or bring up a cluster if it's down.
76+
go run hack/e2e.go -v --pushup
77+
78+
# Run all tests
79+
go run hack/e2e.go -v --test
5480

55-
The output for the end-2-end tests will be a single binary called `e2e.test` under the default output directory, which is typically `_output/local/bin/linux/amd64/`. Within the repository there are scripts that are provided under the `./hack` directory that are helpful for automation, but may not apply for a local development purposes. Instead, we recommend familiarizing yourself with the executable options. To obtain the full list of options, run the following:
81+
# Run tests matching the regex "\[Conformance\]" (the conformance tests)
82+
go run hack/e2e.go -v -test --test_args="--ginkgo.focus=\[Conformance\]"
5683

57-
`$ ./e2e.test --help`
84+
# Conversely, exclude tests that match the regex "Pods.*env"
85+
go run hack/e2e.go -v -test --test_args="--ginkgo.focus=Pods.*env"
5886

59-
### Running the Tests
87+
# Flags can be combined, and their actions will take place in this order:
88+
# --build, --push|--up|--pushup, --test|--tests=..., --down
89+
#
90+
# You can also specify an alternative provider, such as 'aws'
91+
#
92+
# e.g.:
93+
KUBERNETES_PROVIDER=aws go run hack/e2e.go -v --build --pushup --test --down
6094

61-
For the purposes of brevity, we will look at a subset of the options, which are listed below:
95+
# -ctl can be used to quickly call kubectl against your e2e cluster. Useful for
96+
# cleaning up after a failed test or viewing logs. Use -v to avoid suppressing
97+
# kubectl output.
98+
go run hack/e2e.go -v -ctl='get events'
99+
go run hack/e2e.go -v -ctl='delete pod foobar'
100+
101+
# Alternately, if you have the e2e cluster up and no desire to see the event stream, you can run ginkgo-e2e.sh directly:
102+
hack/ginkgo-e2e.sh --ginkgo.focus=\[Conformance\]
103+
```
104+
105+
The tests are built into a single binary which can be run used to deploy a Kubernetes system or run tests against an already-deployed Kubernetes system. See `go run hack/e2e.go --help` (or the flag definitions in `hack/e2e.go`) for more options, such as reusing an existing cluster.
106+
107+
### Cleaning up
108+
109+
During a run, pressing `control-C` should result in an orderly shutdown, but if something goes wrong and you still have some VMs running you can force a cleanup with this command:
110+
111+
```sh
112+
go run hack/e2e.go -v --down
113+
```
114+
115+
## Advanced testing
116+
117+
### Bringing up a cluster for testing
118+
119+
If you want, you may bring up a cluster in some other manner and run tests against it. To do so, or to do other non-standard test things, you can pass arguments into Ginkgo using `--test_args` (e.g. see above). For the purposes of brevity, we will look at a subset of the options, which are listed below:
62120

63121
```
64122
-ginkgo.dryRun=false: If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.
@@ -75,7 +133,7 @@ For the purposes of brevity, we will look at a subset of the options, which are
75133
-repo-root="../../": Root directory of kubernetes repository, for finding test files.
76134
```
77135

78-
Prior to running the tests, it is recommended that you first create a simple auth file in your home directory, e.g. `$HOME/.kube/config` , with the following:
136+
Prior to running the tests, you may want to first create a simple auth file in your home directory, e.g. `$HOME/.kube/config` , with the following:
79137

80138
```
81139
{
@@ -84,23 +142,39 @@ Prior to running the tests, it is recommended that you first create a simple aut
84142
}
85143
```
86144

87-
Next, you will need a cluster that you can test against. As mentioned earlier, you will want to execute `sudo ./hack/local-up-cluster.sh`. To get a sense of what tests exist, you may want to run:
145+
As mentioned earlier there are a host of other options that are available, but they are left to the developer.
88146

89-
`e2e.test --host="127.0.0.1:8080" --provider="local" --ginkgo.v=true -ginkgo.dryRun=true --kubeconfig="$HOME/.kube/config" --repo-root="$KUBERNETES_SRC_PATH"`
147+
**NOTE:** If you are running tests on a local cluster repeatedly, you may need to periodically perform some manual cleanup.
90148

91-
If you wish to execute a specific set of tests you can use the `-ginkgo.focus=` regex, e.g.:
149+
- `rm -rf /var/run/kubernetes`, clear kube generated credentials, sometimes stale permissions can cause problems.
150+
- `sudo iptables -F`, clear ip tables rules left by the kube-proxy.
92151

93-
`e2e.test ... --ginkgo.focus="DNS|(?i)nodeport(?-i)|kubectl guestbook"`
152+
### Local clusters
94153

95-
Conversely, if you wish to exclude a set of tests, you can run:
154+
It can be much faster to iterate on a local cluster instead of a cloud-based one. To start a local cluster, you can run:
96155

97-
`e2e.test ... --ginkgo.skip="Density|Scale"`
156+
```sh
157+
# The PATH construction is needed because PATH is one of the special-cased
158+
# environment variables not passed by sudo -E
159+
sudo PATH=$PATH hack/local-up-cluster.sh
160+
```
98161

99-
As mentioned earlier there are a host of other options that are available, but are left to the developer
162+
This will start a single-node Kubernetes cluster than runs pods using the local docker daemon. Press Control-C to stop the cluster.
100163

101-
**NOTE:** If you are running tests on a local cluster repeatedly, you may need to periodically perform some manual cleanup.
102-
- `rm -rf /var/run/kubernetes`, clear kube generated credentials, sometimes stale permissions can cause problems.
103-
- `sudo iptables -F`, clear ip tables rules left by the kube-proxy.
164+
#### Testing against local clusters
165+
166+
In order to run an E2E test against a locally running cluster, point the tests at a custom host directly:
167+
168+
```sh
169+
export KUBECONFIG=/path/to/kubeconfig
170+
go run hack/e2e.go -v --test_args="--host=http://127.0.0.1:8080"
171+
```
172+
173+
To control the tests that are run:
174+
175+
```sh
176+
go run hack/e2e.go -v --test_args="--host=http://127.0.0.1:8080" --ginkgo.focus="Secrets"
177+
```
104178

105179
## Kinds of tests
106180

@@ -114,7 +188,13 @@ We are working on implementing clearer partitioning of our e2e tests to make run
114188
- `[Skipped]`: `[Skipped]` is a legacy label that we're phasing out. If a test is marked `[Skipped]`, there should be an issue open to label it properly. `[Skipped]` tests are by default not run, unless a `focus` or `skip` argument is explicitly given.
115189
- `[Feature:.+]`: If a test has non-default requirements to run or targets some non-core functionality, and thus should not be run as part of the standard suite, it receives a `[Feature:.+]` label, e.g. `[Feature:Performance]` or `[Feature:Ingress]`. `[Feature:.+]` tests are not run in our core suites, instead running in custom suites. If a feature is experimental or alpha and is not enabled by default due to being incomplete or potentially subject to breaking changes, it does *not* block the merge-queue, and thus should run in some separate test suites owned by the feature owner(s) (see #continuous_integration below).
116190

117-
Finally, `[Conformance]` tests are tests we expect to pass on **any** Kubernetes cluster. The `[Conformance]` label does not supersede any other labels. `[Conformance]` test policies are a work-in-progress; see #18162.
191+
### Conformance tests
192+
193+
Finally, `[Conformance]` tests are tests we expect to pass on **any** Kubernetes cluster. The `[Conformance]` label does not supersede any other labels. `[Conformance]` test policies are a work-in-progress (see #18162).
194+
195+
End-to-end testing, as described above, is for [development distributions](writing-a-getting-started-guide.md). A conformance test is used on a [versioned distro](writing-a-getting-started-guide.md). (Links WIP)
196+
197+
The conformance test runs a subset of the e2e-tests against a manually-created cluster. It does not require support for up/push/down and other operations. To run a conformance test, you need to know the IP of the master for your cluster and the authorization arguments to use. The conformance test is intended to run against a cluster at a specific binary release of Kubernetes. See [conformance-test.sh](http://releases.k8s.io/HEAD/hack/conformance-test.sh).
118198

119199
## Continuous Integration
120200

@@ -166,7 +246,7 @@ If we have determined that a test is known-flaky and cannot be fixed in the shor
166246

167247
## Performance Evaluation
168248

169-
Another benefit of the end-2-end tests is the ability to create reproducible loads on the system, which can then be used to determine the responsiveness, or analyze other characteristics of the system. For example, the density tests load the system to 30,50,100 pods per/node and measures the different characteristics of the system, such as throughput, api-latency, etc.
249+
Another benefit of the e2e tests is the ability to create reproducible loads on the system, which can then be used to determine the responsiveness, or analyze other characteristics of the system. For example, the density tests load the system to 30,50,100 pods per/node and measures the different characteristics of the system, such as throughput, api-latency, etc.
170250

171251
For a good overview of how we analyze performance data, please read the following [post](http://blog.kubernetes.io/2015/09/kubernetes-performance-measurements-and.html)
172252

0 commit comments

Comments
 (0)