Skip to content

Commit f9ba4b9

Browse files
authored
Merge pull request #7182 from mattcary/fuzz
Clarify fuzzer operation
2 parents bc2cb20 + c3c4496 commit f9ba4b9

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

contributors/devel/sig-architecture/api_changes.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -878,16 +878,29 @@ You need to regenerate the generated code as instructed in the sections above.
878878
Part of our testing regimen for APIs is to "fuzz" (fill with random values) API
879879
objects and then convert them to and from the different API versions. This is
880880
a great way of exposing places where you lost information or made bad
881-
assumptions. If you have added any fields which need very careful formatting
882-
(the test does not run validation) or if you have made assumptions such as
883-
"this slice will always have at least 1 element", you may get an error or even
884-
a panic from the `serialization_test`. If so, look at the diff it produces (or
885-
the backtrace in case of a panic) and figure out what you forgot. Encode that
886-
into the fuzzer's custom fuzz functions. Hint: if you added defaults for a
887-
field, that field will need to have a custom fuzz function that ensures that the
888-
field is fuzzed to a non-empty value.
889-
890-
The fuzzer can be found in `pkg/api/testing/fuzzer.go`.
881+
assumptions.
882+
883+
The fuzzer works by creating a random API object and calling the custom fuzzer
884+
function in `pkg/apis/$GROUP/fuzzer/fuzzer.go`. The resulting object is then
885+
round-tripped from one api version to another, and verified to be the same as
886+
what was started with. Validation is not run during this process, but defaulting
887+
is.
888+
889+
If you have added any fields which need very careful formatting (the test does
890+
not run validation) or if you have made assumptions during defaulting such as
891+
"this slice will always have at least 1 element", you may get an error or even a
892+
panic from the `k8s.io/kubernetes/pkg/api/testing.TestRoundTripTypes` in
893+
`./pkg/api/testing/serialization_test.go`.
894+
895+
If you default any fields, you must check that in the custom fuzzer function,
896+
because the fuzzer may leave some fields empty. If your object has a structure
897+
reference, the fuzzer may leave that nil, or it may create a random object. Your
898+
custom fuzzer function must ensure that defaulting does not further change the
899+
object, as that will show up as a diff in the round trip test.
900+
901+
Finally, the fuzz test runs without any feature gate configuration. If
902+
defaulting or other behavior is behind a feature gate, beware that the fuzz
903+
behavior will change when the feature gate becomes default on.
891904

892905
## Update the semantic comparisons
893906

0 commit comments

Comments
 (0)