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