Validate listType usage on struct fields #569
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Validate listType usage on struct fields
Fixes : #554.
kube-openapiis updated to validate the usage of the// +listTypemarker. The tool will now generate an error if this marker is applied to any field that is not a slice or an array. This change ensures that the OpenAPI specifications for core Kubernetes types are generated with the same strictness as those for CRDs, preventing downstream tooling failures.Problem:
Currently,
kube-openapiallows the// +listTypemarker to be used on fields that are not lists or slices. This can result in the generation of an invalid OpenAPI schema. For example, a+listType=atomicmarker was incorrectly applied to themetav1.Status.Detailsfield, which is a struct, not a list type. This causes tools that consume the schema, such ascontroller-gen, to fail when generating Custom Resource Definitions (CRDs) that embedmetav1.Status.Solution:
This pull request introduces a validation check in
kube-openapito ensure that the+listTypemarker is only used on slice or array fields. If the marker is used on any other type of field, an error will be returned.Unit tests have been added to verify the new validation logic, including a test case that is expected to fail when
+listTypeis used on a string field.