Skip to content

Commit 0cb24d2

Browse files
committed
Describe ratcheting validation
Signed-off-by: Maciej Szulik <[email protected]>
1 parent 7b61a36 commit 0cb24d2

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

contributors/devel/sig-architecture/api_changes.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ found at [API Conventions](api-conventions.md).
3939
- [Alpha, Beta, and Stable Versions](#alpha-beta-and-stable-versions)
4040
- [Adding Unstable Features to Stable Versions](#adding-unstable-features-to-stable-versions)
4141
- [New field in existing API version](#new-field-in-existing-api-version)
42+
- [Ratcheting validation](#ratcheting-validation)
4243
- [New enum value in existing field](#new-enum-value-in-existing-field)
4344
- [New alpha API version](#new-alpha-api-version)
4445

@@ -878,13 +879,13 @@ You need to regenerate the generated code as instructed in the sections above.
878879
Part of our testing regimen for APIs is to "fuzz" (fill with random values) API
879880
objects and then convert them to and from the different API versions. This is
880881
a great way of exposing places where you lost information or made bad
881-
assumptions.
882+
assumptions.
882883

883884
The fuzzer works by creating a random API object and calling the custom fuzzer
884885
function in `pkg/apis/$GROUP/fuzzer/fuzzer.go`. The resulting object is then
885886
round-tripped from one api version to another, and verified to be the same as
886887
what was started with. Validation is not run during this process, but defaulting
887-
is.
888+
is.
888889

889890
If you have added any fields which need very careful formatting (the test does
890891
not run validation) or if you have made assumptions during defaulting such as
@@ -998,9 +999,9 @@ complexity of upgradeability and lack of long-term support and lack of
998999
upgradability.
9991000
- Beta level:
10001001
- Object Versioning: API version name contains `beta` (e.g. `v2beta3`)
1001-
- Availability: in official Kubernetes releases; API is disabled by default
1002+
- Availability: in official Kubernetes releases; API is disabled by default
10021003
but may be enabled by a flag.
1003-
(Note: beta APIs introduced before v1.24 were enabled by default, but this
1004+
(Note: beta APIs introduced before v1.24 were enabled by default, but this
10041005
[changed for new beta APIs](https://github.com/kubernetes/enhancements/blob/master/keps/sig-architecture/3136-beta-apis-off-by-default/README.md))
10051006
- Audience: users interested in providing feedback on features
10061007
- Completeness: all API operations, CLI commands, and UI support should be
@@ -1225,6 +1226,37 @@ In future Kubernetes versions:
12251226
}
12261227
```
12271228

1229+
#### Ratcheting validation
1230+
1231+
The word "ratcheting" refers to a process of incremental and often irreversible
1232+
progression or change, typically in a single direction. The term originates from
1233+
a mechanical device called a [ratchet](https://en.wikipedia.org/wiki/Ratchet_(device)),
1234+
which consists of a toothed wheel or bar and a pawl (a catch) that allows movement
1235+
in only one direction while preventing backward motion.
1236+
1237+
In the Kubernetes world, a ratcheting validation refers to an incremental tightening
1238+
of validation. This means we allow current resources to either remain invalid or
1239+
be fixed, but all new resources must pass the validation. The following table
1240+
best illustrates these cases:
1241+
1242+
| Resource | Validation |
1243+
|-------------|------------|
1244+
| new valid | succeeds |
1245+
| new invalid | fails |
1246+
| old valid | succeeds |
1247+
| old invalid | succeeds |
1248+
1249+
A good example of ratcheting validation was introduced in [this pull request](https://github.com/kubernetes/kubernetes/pull/130233).
1250+
It introduced validation for the optional `.spec.serviceName` field for StatefulSet,
1251+
such that old resources (nregarldess of whether they are valid or not) will succeed
1252+
the validation check, but new resources must adhere to stricter validation rules
1253+
for that field. The relevant changes include:
1254+
- A struct with options passed to validation methods (here it's the `StatefulSetValidationOptions`
1255+
struct, with `AllowInvalidServiceName` to handle this specific case).
1256+
- Appropriate changes inside `Validate*` methods which ensure the rules from the
1257+
table above are implemented.
1258+
- Tests ensuring all the cases from the above table are covered.
1259+
12281260
#### New enum value in existing field
12291261
12301262
A developer is considering adding a new allowed enum value of `"OnlyOnTuesday"`

0 commit comments

Comments
 (0)