|
| 1 | +# Conformance Testing in Kubernetes |
| 2 | + |
| 3 | +The Kubernetes conformance test suite is a set of testcases, currently a |
| 4 | +subset of the integration/e2e tests, that the Architecture SIG has approved |
| 5 | +to define the core set of interoperable features that all Kubernetes |
| 6 | +deployments must support. |
| 7 | + |
| 8 | +Contributors must write and submit e2e tests first (approved by owning Sigs). |
| 9 | +Once the new tests prove to be stable in CI runs, later create a follow up PR |
| 10 | +to add the test to conformance. This approach also decouples the development |
| 11 | +of useful tests from their promotion to conformance. |
| 12 | + |
| 13 | +A conformance test verifies the expected functionality works as a user might encounter it in the wild, |
| 14 | +and tests should begin by covering the most important and visible aspects of the function. |
| 15 | + |
| 16 | +### Conformance Test Requirements |
| 17 | + |
| 18 | +A test is eligible for promotion to conformance if it meets the following requirements: |
| 19 | + |
| 20 | +- testing GA feature (not alpha or beta APIs, nor deprecated features) |
| 21 | +- must be portable (not dependent on provider-specific capabilities or on the public internet) |
| 22 | +- cannot test a feature which obviously cannot be supported on a broad range of platforms |
| 23 | +(i.e. testing of multiple disk mounts, GPUs, high density) |
| 24 | +- cannot test an optional feature (e.g. not policy enforcement) |
| 25 | +- should be non-privileged (neither root on nodes, network, nor cluster) |
| 26 | +- cannot rely on any particular non-standard file system permissions granted to containers or users |
| 27 | +(i.e. sharing writable host /tmp with a container) |
| 28 | +- should be stable and run consistently |
| 29 | +- cannot skip providers (there should be no Skip like directives added to the test), |
| 30 | +especially in the Nucleus or Application layers as described |
| 31 | +[here](https://github.com/kubernetes/community/blob/master/contributors/devel/architectural-roadmap.md). |
| 32 | +- cannot test cloud provider specific features (i.e. GCE monitoring, S3 Bucketing, ...) |
| 33 | +- should work with default settings for all configuration parameters |
| 34 | +(example: the default list of admission plugins should not have to be tweaked for passing conformance). |
| 35 | +- cannot rely on any binaries that are not required for the |
| 36 | +linux kernel or for a kubelet to run (i.e. git) |
| 37 | + |
| 38 | +### Conformance Test Version Skew Policy |
| 39 | + |
| 40 | +As each new release of Kubernetes provides new functionality, the subset of |
| 41 | +tests necessary to demonstrate conformance grows with each release. Conformance |
| 42 | +is thus considered versioned, with the same backwards compatibility guarantees |
| 43 | +as laid out in [our versioning policy](/contributors/design-proposals/release/versioning.md#supported-releases-and-component-skew). |
| 44 | +Conformance tests for a given version should be run off of the release branch |
| 45 | +that corresponds to that version. Thus `v1.2` conformance tests would be run |
| 46 | +from the head of the `release-1.2` branch. eg: |
| 47 | + |
| 48 | + - A v1.3 development cluster should pass v1.1, v1.2 conformance tests |
| 49 | + |
| 50 | + - A v1.2 cluster should pass v1.1, v1.2 conformance tests |
| 51 | + |
| 52 | + - A v1.1 cluster should pass v1.0, v1.1 conformance tests, and fail v1.2 |
| 53 | +conformance tests |
| 54 | + |
| 55 | + |
| 56 | +### Running Conformance Tests |
| 57 | + |
| 58 | +Conformance tests are designed to be run with no cloud provider configured. |
| 59 | +Conformance tests can be run against clusters that have not been created with |
| 60 | +`hack/e2e.go`, just provide a kubeconfig with the appropriate endpoint and |
| 61 | +credentials. |
| 62 | + |
| 63 | +```sh |
| 64 | +# setup for conformance tests |
| 65 | +export KUBECONFIG=/path/to/kubeconfig |
| 66 | +export KUBERNETES_CONFORMANCE_TEST=y |
| 67 | + |
| 68 | +# run all conformance tests |
| 69 | +go run hack/e2e.go -- --provider=skeleton --test --test_args="--ginkgo.focus=\[Conformance\]" |
| 70 | + |
| 71 | +# run all parallel-safe conformance tests in parallel |
| 72 | +GINKGO_PARALLEL=y go run hack/e2e.go -- --provider=skeleton --test --test_args="--ginkgo.focus=\[Conformance\] --ginkgo.skip=\[Serial\]" |
| 73 | + |
| 74 | +# ... and finish up with remaining tests in serial |
| 75 | +go run hack/e2e.go -- --provider=skeleton --test --test_args="--ginkgo.focus=\[Serial\].*\[Conformance\]" |
| 76 | +``` |
| 77 | + |
| 78 | +### Kubernetes Conformance Document |
| 79 | +For each Kubernetes release, a Conformance Document will be generated |
| 80 | +that lists all of the tests that comprise the conformance test suite, along |
| 81 | +with the formal specification of each test. For example conformance document for |
| 82 | +1.9 can be found [here](https://github.com/cncf/k8s-conformance/blob/master/docs/KubeConformance-1.9.md). |
| 83 | +This document will help people understand what features are being tested without having to look through |
| 84 | +the testcase's code directly. |
| 85 | + |
| 86 | + |
| 87 | +## Adding New Tests |
| 88 | + |
| 89 | +To promote a testcase to the conformance test suite, the following |
| 90 | +steps must be taken: |
| 91 | +- as a prerequisite, the test case is already part of e2e and is not flaky |
| 92 | +- the testcase must use the `framework.ConformanceIt()` function rather |
| 93 | + than the `framework.It()` function |
| 94 | +- the testcase must include a comment immediately before the |
| 95 | + `framework.ConformanceIt()` call that includes all of the required |
| 96 | + metadata about the test (see the [Test Metadata](#test-metadata) section) |
| 97 | +- use "Promote xxx e2e test to Conformance" as template of your PR title |
| 98 | +- tag your PR with "/area conformance" label |
| 99 | +- send your PR to Sig-Architecture for review by adding "@kubernetes/sig-architecture-pr-reviews" |
| 100 | +also CC the relevant Sig and Sig-Architecture |
| 101 | + |
| 102 | + |
| 103 | +### Test Metadata |
| 104 | + |
| 105 | +Each conformance test must include the following piece of metadata |
| 106 | +within its associated comment: |
| 107 | + |
| 108 | +- `Release`: indicates the Kubernetes release that the test was added to the |
| 109 | + conformance test suite. If the test was modified in subsequent releases |
| 110 | + then those releases should be included as well (comma separated) |
| 111 | +- `Testname`: a human readable short name of the test |
| 112 | +- `Description`: a detailed description of the test. This field must describe |
| 113 | + the required behaviour of the Kubernetes components being tested using |
| 114 | + [RFC2119](https://tools.ietf.org/html/rfc2119) keywords. This field |
| 115 | + is meant to be a "specification" of the tested Kubernetes features, as |
| 116 | + such, it must be detailed enough so that readers can fully understand |
| 117 | + the aspects of Kubernetes that are being tested without having to read |
| 118 | + the test's code directly. Additionally, this test should provide a clear |
| 119 | + distinction between the parts of the test that are there for the purpose |
| 120 | + of validating Kubernetes rather than simply infrastructure logic that |
| 121 | + is necessary to setup, or clean up, the test. |
| 122 | + |
| 123 | +### Sample Conformance Test |
| 124 | + |
| 125 | +The following snippet of code shows a sample conformance test's metadata: |
| 126 | + |
| 127 | +``` |
| 128 | +/* |
| 129 | + Release : v1.9 |
| 130 | + Testname: Kubelet: log output |
| 131 | + Description: By default the stdout and stderr from the process being |
| 132 | + executed in a pod MUST be sent to the pod's logs. |
| 133 | +*/ |
| 134 | +framework.ConformanceIt("it should print the output to logs", func() { |
| 135 | + ... |
| 136 | +}) |
| 137 | +``` |
| 138 | + |
| 139 | +The corresponding portion of the Kubernetes Conformance Documentfor this test would then look |
| 140 | +like this: |
| 141 | + |
| 142 | +> |
| 143 | +> ## [Kubelet: log output](https://github.com/kubernetes/kubernetes/tree/release-1.9/test/e2e_node/kubelet_test.go#L47) |
| 144 | +> |
| 145 | +> Release : v1.9 |
| 146 | +> |
| 147 | +> By default the stdout and stderr from the process being executed in a pod MUST be sent to the pod's logs. |
| 148 | +
|
| 149 | +### Reporting Conformance Test Results |
| 150 | + |
| 151 | +Conformance test results, by provider and releases, can be viewed in the |
| 152 | +federated [Conformance TestGrid dashboard](https://k8s-testgrid.appspot.com/conformance-all). |
| 153 | +If you wish to contribute conformance test results for your provider, |
| 154 | +please follow this [on-boarding document](https://docs.google.com/document/d/1lGvP89_DdeNO84I86BVAU4qY3h2VCRll45tGrpyx90A/edit#). |
| 155 | + |
0 commit comments