Skip to content

Commit ef904ff

Browse files
authored
Merge pull request kubernetes#1267 from johnbelamaric/conf-behavior-details
conformance: add design details, mark implementable
2 parents 81f6485 + 98e2973 commit ef904ff

File tree

1 file changed

+125
-35
lines changed

1 file changed

+125
-35
lines changed

keps/sig-architecture/20190412-conformance-behaviors.md

Lines changed: 125 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,43 @@ approvers:
1717
editor: TBD
1818
creation-date: 2019-04-12
1919
last-updated: 2010-07-30
20-
status: provisional
20+
status: implementable
2121
---
2222

2323
# Behavior-driven Conformance Testing
2424

2525
## Table of Contents
2626

27-
- [Title](#title)
28-
- [Table of Contents](#table-of-contents)
29-
- [Release Signoff Checklist](#release-signoff-checklist)
30-
- [Summary](#summary)
31-
- [Motivation](#motivation)
32-
- [Goals](#goals)
33-
- [Non-Goals](#non-goals)
34-
- [Proposal](#proposal)
35-
- [Representation of Behaviors](#representation-of-behaviors)
36-
- [Behavior and Test Generation Tooling](#behavior-and-test-generation-tooling)
37-
- [Coverage Tooling](#coverage-tooling)
38-
- [Risks and Mitigations](#risks-and-mitigations)
39-
- [Design Details](#design-details)
40-
- [Subsequent Phase](#subsequent-phase)
27+
<!-- toc -->
28+
- [Release Signoff Checklist](#release-signoff-checklist)
29+
- [Summary](#summary)
30+
- [Motivation](#motivation)
31+
- [Goals](#goals)
32+
- [Non-Goals](#non-goals)
33+
- [Proposal](#proposal)
34+
- [Representation of Behaviors](#representation-of-behaviors)
35+
- [Behavior and Test Generation Tooling](#behavior-and-test-generation-tooling)
36+
- [Handwritten Behaviour Scenarios](#handwritten-behaviour-scenarios)
37+
- [Coverage Tooling](#coverage-tooling)
38+
- [Risks and Mitigations](#risks-and-mitigations)
39+
- [Design Details](#design-details)
40+
- [Phase 1](#phase-1)
41+
- [Tying tests back to behaviors](#tying-tests-back-to-behaviors)
42+
- [kubetestgen](#kubetestgen)
43+
- [Phase 2](#phase-2)
44+
- [Graduation Criteria](#graduation-criteria)
45+
- [Future development](#future-development)
4146
- [Complex Storytelling combined with json/yaml](#complex-storytelling-combined-with-jsonyaml)
4247
- [Example patch test scenario](#example-patch-test-scenario)
4348
- [Generating scaffolding from Gherkin .feature files](#generating-scaffolding-from-gherkin-feature-files)
4449
- [Autogeneration of Test Scaffolding](#autogeneration-of-test-scaffolding)
4550
- [Combining gherkin with existing framework](#combining-gherkin-with-existing-framework)
46-
- [Implementation History](#implementation-history)
47-
- [Drawbacks](#drawbacks)
48-
- [Alternatives](#alternatives)
51+
- [Implementation History](#implementation-history)
52+
- [Drawbacks](#drawbacks)
53+
- [Alternatives](#alternatives)
54+
- [Annotate test files with behaviors](#annotate-test-files-with-behaviors)
55+
- [Annotate existing API documentation with behaviors](#annotate-existing-api-documentation-with-behaviors)
56+
<!-- /toc -->
4957

5058
## Release Signoff Checklist
5159

@@ -56,12 +64,12 @@ For enhancements that make changes to code or processes/procedures in core Kuber
5664

5765
Check these off as they are completed for the Release Team to track. These checklist items _must_ be updated for the enhancement to be released.
5866

59-
- [ ] kubernetes/enhancements issue in release milestone, which links to KEP (this should be a link to the KEP location in kubernetes/enhancements, not the initial KEP PR)
60-
- [ ] KEP approvers have set the KEP status to `implementable`
61-
- [ ] Design details are appropriately documented
62-
- [ ] Test plan is in place, giving consideration to SIG Architecture and SIG Testing input
63-
- [ ] Graduation criteria is in place
64-
- [ ] "Implementation History" section is up-to-date for milestone
67+
- [x] kubernetes/enhancements issue in release milestone, which links to KEP (this should be a link to the KEP location in kubernetes/enhancements, not the initial KEP PR)
68+
- [x] KEP approvers have set the KEP status to `implementable`
69+
- [x] Design details are appropriately documented
70+
- [x] Test plan is in place, giving consideration to SIG Architecture and SIG Testing input
71+
- [x] Graduation criteria is in place
72+
- [x] "Implementation History" section is up-to-date for milestone
6573
- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
6674
- [ ] Supporting documentation e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
6775

@@ -111,7 +119,8 @@ tests and test scaffolding to quickly cover those behaviors.
111119
* Enable separate review of behaviors and tests that evaluate those behaviors.
112120
* Provide a single location for defining conforming behavior.
113121
* Provide tooling to generate as many of the behaviors as possible from API
114-
schemas.
122+
schemas. This will be a seed for the behavior lists, which will in turn be
123+
human curated. Refinements can improve the quality of the seed over time.
115124
* Provide tooling to generate tests and test scaffolding for validating
116125
behaviors.
117126
* Provide tooling to measure the conformance test coverage of the behaviors.
@@ -125,13 +134,16 @@ tests and test scaffolding to quickly cover those behaviors.
125134
* Add new conformance tests. It is expected that during this effort new
126135
tests may be created using the proposed tooling, but it is not explicitly part
127136
of this proposal.
137+
* Provide tooling that perfectly populates the behaviors from the API schema.
138+
Not enough information is present in the schema to achieve this. The tooling
139+
is only intended to produce a seed for human curation.
128140

129141
## Proposal
130142

131143
The proposal consists of four deliverables:
132144
* A machine readable format to define conforming behaviors.
133145
* Tooling to generate lists of behaviors from the API schemas.
134-
* Tooling to generate tests and test scaffoloding to evaulate those behaviors.
146+
* Tooling to generate tests and test scaffolding to evaluate those behaviors.
135147
* Tooling to compare the implemented tests to the list of behaviors and
136148
calculate coverage.
137149

@@ -193,7 +205,7 @@ test/conformance
193205

194206
The structure of the behavior YAML files is described by these Go types:
195207

196-
```
208+
```go
197209
// Area defines a general grouping of behaviors
198210
type Area struct {
199211
// Area is the name of the area.
@@ -342,20 +354,97 @@ this is not a high risk.
342354

343355
## Design Details
344356

345-
TBD.
357+
Delivery of this KEP shall be done in the following phases:
358+
359+
### Phase 1
360+
361+
In Phase 1, we will:
362+
* Implement the behavior formats and types described above. This will include
363+
separate suites for tooling-generated behaviors and handcrafted behaviors.
364+
* Implement the directory structure described above to contain the behavior
365+
lists, including how to tie tests back to behaviors.
366+
* `kubetestgen`, a tool which reads the OpenAPI schema and generates the list of
367+
behaviors.
368+
* Migrate existing conformance tests to work with the new tooling. Existing
369+
tooling around generation of conformance reports will not be changed in this
370+
phase.
371+
372+
#### Tying tests back to behaviors
373+
The proposal above mentions `tests.yaml` but does not describe a format for that
374+
file. The current conformance frameworks requests that during promotion of the
375+
test to conformance, the developer adds metadata, including the release name,
376+
the test name, and description. Tests are identified in the
377+
[conformance.txt](https://github.com/kubernetes/kubernetes/blob/master/test/conformance/testdata/conformance.txt)
378+
file by their Ginko description. Unfortunately, this does not produce unique
379+
test names, as it does not include all of the `Describe` calls from higher in
380+
the call tree (see this
381+
[slack discussion](https://kubernetes.slack.com/archives/C78F00H99/p1566324743171500)
382+
for more details).
383+
384+
As part of this KEP, tests being promoted to conformance must add a unique
385+
identifier, `TestId`, in their conformance metadata. This will be used, along with
386+
the behavior IDs, to map which tests validate which behaviors in the
387+
`tests.yaml` file. The Go structures for `tests.yaml` are shown below.
388+
389+
```go
390+
type BehaviorTestList struct {
391+
Tests []BehaviorTest `json:"tests,omitempty"`
392+
}
393+
394+
type BehaviorTest struct {
395+
BehaviorId string `json:"behaviorId,omitempty"`
396+
TestId string `json:"testId,omitempty"`
397+
398+
// Description is optional and is intended to make reviewing easier; the
399+
// expectation would be that tooling would copy the value here.
400+
Description string `json:"description,omitempty"`
401+
}
402+
```
403+
404+
#### kubetestgen
405+
406+
In this phase, the tool will only generate behavior lists in the format defined
407+
above. It will accept the following flags:
408+
* `-schema` - a URL or local file name pointing to the JSON OpenAPI schema
409+
* `-resource` - the specific OpenAPI definition for which to generate behaviors
410+
* `-area` - the name to use for the area
411+
* `-suite` - the name to use for the suite
412+
* `-behaviorsdir` - the path to the behaviors directory (default current
413+
directory)
414+
415+
The tool will read the schema, locate the specific definition, and generate the
416+
`{area}` directory and `{suite}.yaml` as described in the proposal above.
417+
418+
### Phase 2
419+
420+
In Phase 2, we will:
421+
* Migrate existing tooling for conformance report generation to the new method,
422+
and remove older tooling. This will eliminate the need to maintain conformance
423+
tests in both the new and old manner.
424+
* Add test scaffolding generation in parallel with the behavior list generation.
425+
* Implement coverage metrics comparing behavior lists to the coverage captured
426+
by existing conformance tests.
427+
428+
### Graduation Criteria
429+
As this is a tooling component and is not user facing, it does not follow the
430+
ordinary alpha/beta/GA process. In 1.17, the intent is to implement Phase 1,
431+
without disruption to any feature development. The acceptance criteria here
432+
are that the deliverables described in Phase 1 are complete, and that no
433+
developers other than those writing or promoting conformance tests are
434+
affected by the changes introduced in this KEP.
346435

347-
## Subsequent Phase
436+
### Future development
348437

349438
The description above achieves the basic goals of the KEP. However, in the same
350-
timeframe as implementation of this KEP, we also plan to explore some furture
439+
timeframe as implementation of this KEP, we also plan to explore some future
351440
refinements. In particular, we will explore the use of an existing behavior-
352441
driven testing language to refine our *prose* behavior descriptions into
353442
*machine-readable* behavior descriptions.
354443

355444
One such language is [Gherkin](https://cucumber.io/docs/gherkin/). In Gherkin,
356445
specifications are defined around Features, which are collections of Scenarios.
357446

358-
### Complex Storytelling combined with json/yaml
447+
#### Complex Storytelling combined with json/yaml
359448

360449
Inline json or yaml as CRUD input/output can be autogenerated for verification. The
361450
json or yaml can also be contained in external files. The functions matching the
@@ -377,7 +466,7 @@ Feature: Intrapod Communication
377466
And this is fine
378467
```
379468

380-
### Example patch test scenario
469+
#### Example patch test scenario
381470

382471
```feature
383472
Feature: Manually using Manifests to CRUD and evaluate effects
@@ -404,7 +493,7 @@ Feature: Manually using Manifests to CRUD and evaluate effects
404493
"""
405494
And this is fine
406495
```
407-
### Generating scaffolding from Gherkin .feature files
496+
#### Generating scaffolding from Gherkin .feature files
408497

409498
A Gherkin **feature** is synonymous with our definition of **behaviour**, and
410499
tagging can be used for **@conformance** or **@release-X.Y** metadata.
@@ -436,7 +525,7 @@ Feature: Structured Metadata allowing Behaviour Driven tooling automation
436525
And this is fine
437526
```
438527

439-
### Autogeneration of Test Scaffolding
528+
#### Autogeneration of Test Scaffolding
440529

441530
```shell
442531
~/go/bin/godog --no-colors
@@ -511,7 +600,7 @@ func FeatureContext(s *godog.Suite) {
511600
These functions and the Suite.Step matchers that tie them to Gherkin steps can
512601
be pasted into a `test_steps.go` file as a initial scaffolding.
513602

514-
### Combining gherkin with existing framework
603+
#### Combining gherkin with existing framework
515604

516605
Our current tests are not super easy to write, read, or review. BDD in go was in
517606
it's early days when k8s started integration testing with a closely coupled
@@ -561,6 +650,7 @@ It('test string')`
561650
- 2019-07-24: Updated to add reviewers and an example on generated scaffolding
562651
- 2019-07-30: Updated to separate Gherkin / godog into second phase, include
563652
directory structure for showing behavior/test separation
653+
- 2019-10-01: Added detailed design; marked implementable
564654

565655
## Drawbacks
566656

0 commit comments

Comments
 (0)