Skip to content

Conversation

@lalitc375
Copy link

Validate listType usage on struct fields

Fixes : #554.

kube-openapi is updated to validate the usage of the // +listType marker. 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-openapi allows the // +listType marker 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=atomic marker was incorrectly applied to the metav1.Status.Details field, which is a struct, not a list type. This causes tools that consume the schema, such as controller-gen, to fail when generating Custom Resource Definitions (CRDs) that embed metav1.Status.

Solution:

This pull request introduces a validation check in kube-openapi to ensure that the +listType marker 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 +listType is used on a string field.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lalitc375
Once this PR has been reviewed and has the lgtm label, please assign jefftree for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 5, 2025
@k8s-ci-robot k8s-ci-robot requested review from jpbetz and sttts December 5, 2025 18:09
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 5, 2025
@lalitc375 lalitc375 marked this pull request as draft December 8, 2025 17:52
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align kube-openapi validation with controller-gen for +listType marker

2 participants