TestVersionedValidationByFuzzing swept a hand-maintained list of
group/versions that had a typo (network.k8s.io) and omitted several
groups (apps, policy, rbac, flowcontrol, scheduling). Replace it with a
sweep of the scheme for served GVKs that have declarative validation,
so new group/versions are covered automatically.
Skip extensions/v1beta1 centrally in VerifyVersionedValidationEquivalence
instead of via the per-call WithSkipGroupVersions option: it opts out of
declarative validation but shares an internal type with versions that do
not. Any other version missing declarative validation now fails the sweep
rather than being silently skipped.
Address review feedback on PR #139568:
- Group all test cases by the ObjectMeta field they cover (the stray
"finalizers: name too long" case previously sat at the bottom).
- Mirror the field grouping in the update suite. The update suite keeps
only the baseline valid case; field-level boundaries are covered by
the create suite and re-checking them on update adds no signal.
- Fix three errorlint warnings flagged by pull-kubernetes-linter-hints:
switch fmt.Errorf("...: %v", err) to %w in the metadata-accessor
failure paths of rest.ValidateCreate and validateCommonFields.
- Reword the extensions/v1beta1 skip comment in
TestVersionedValidationByFuzzing: drop the stray trailing semicolon
and explain that the group is unserved and does not carry DV.
The fields become beta, enabled by default. DeviceTaintRule gets
added to the v1beta2 API, but support for it must remain off by default
because that API group is also off by default.
The v1beta1 API is left unchanged. No-one should be using it
anymore (deprecated in 1.33, could be removed now if it wasn't for
reading old objects and version emulation).
To achieve consistent validation, declarative validation must be enabled also
for v1alpha3 (was already enabled for other versions). Otherwise,
TestVersionedValidationByFuzzing fails:
--- FAIL: TestVersionedValidationByFuzzing (0.09s)
--- FAIL: TestVersionedValidationByFuzzing/resource.k8s.io/v1beta2,_Kind=DeviceTaintRule (0.00s)
validation_test.go:109: different error count (0 vs. 1)
resource.k8s.io/v1alpha3: <no errors>
resource.k8s.io/v1beta2: "spec.taint.effect: Unsupported value: \"幤HxÒQP¹¬永唂ȳ垞ş]嘨鶊\": supported values: \"NoExecute\", \"NoSchedule\", \"None\""
...
Refactor TestVersionedValidationByFuzzing to use a declarative map,
subresourceOnly, for resources that must be validated via a specific
subresource path (like autoscaling/Scale).
GVKs not in this map default to root-level validation (""), which is
sufficient for resources that share validation logic between their root
and subresources. This replaces the previous ad-hoc special-casing
with a cleaner, extensible mapping.
Fuzzing must be performed on the internal version of objects because
custom fuzzing functions are typically registered for internal types.
This ensures that all fields are properly initialized with random values
before being converted to various API versions for validation.
Move fuzzing logic into VerifyVersionedValidationEquivalence via a new
WithFuzzer option. This also fixes a panic that occurred when attempting
to fuzz types without an internal version (e.g., APIGroupList) by adding
a nil check after internal conversion.
This commit adds an 'IgnoreObjectConversionErrors' option to the
validation testing framework in 'k8s.io/apimachinery' and exposes it
via 'pkg/api/testing'.
This is useful for fuzzing tests where we might want to skip object
versions that cannot be converted from the internal version (e.g. due to
missing fields or incompatible types in older versions) but still want
to test validation for the versions that *can* be converted.
The 'autoscaling' group versions are added to 'TestVersionedValidationByFuzzing'
with this option enabled.
This makes a bold assumption: that the errors (count and basic content)
will be the same across versions. If this turns out to be untrue, this
may need to get more sophisticated. It should fail obviously when we
hit that edge.