Skip to content

Add +k8s:maxBytes and +k8s:minBytes OpenAPI representation#578

Open
BasavarajBankolli wants to merge 3 commits into
kubernetes:masterfrom
BasavarajBankolli:openapi-maxbytes-137613
Open

Add +k8s:maxBytes and +k8s:minBytes OpenAPI representation#578
BasavarajBankolli wants to merge 3 commits into
kubernetes:masterfrom
BasavarajBankolli:openapi-maxbytes-137613

Conversation

@BasavarajBankolli

@BasavarajBankolli BasavarajBankolli commented Mar 12, 2026

Copy link
Copy Markdown

What this PR does

Adds support for the +k8s:maxBytes and +k8s:minBytes validation markers in kube-openapi.

These markers are mapped to OpenAPI maxLength and minLength respectively, allowing byte-based validation constraints to be expressed in API definitions.

Implementation

  • Added MaxBytes and MinBytes fields to commentTags
  • Added validation for negative values and range conflicts
  • Prevented simultaneous use of maxLength with maxBytes and minLength with minBytes
  • Mapped byte markers to length constraints during schema generation

Fixes: kubernetes/kubernetes#137613

Signed-off-by: Basavaraj PB <basavarajbankolli76@gmail.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Mar 12, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @BasavarajBankolli!

It looks like this is your first PR to kubernetes/kube-openapi 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-openapi has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 12, 2026
@BasavarajBankolli

Copy link
Copy Markdown
Author

@Jefftree @yujuhong could you please review this PR?

@Jefftree

Copy link
Copy Markdown
Member

/assign @aaron-prindle

Will pass this onto the declarative validation folks.

@BasavarajBankolli

Copy link
Copy Markdown
Author

Thanks! Appreciate you routing this to the declarative validation folks.
Happy to make any changes or provide more context if needed.

@Jefftree

Jefftree commented May 6, 2026

Copy link
Copy Markdown
Member

Sweeping open PRs, is this something we want merged @aaron-prindle @jpbetz?

@jpbetz

jpbetz commented May 6, 2026

Copy link
Copy Markdown
Contributor

I'll defer to @aaron-prindle who is tracking how we map JSONSchema/OpenAPI with k8s: tags.

Comment thread pkg/generators/markers.go Outdated
Comment thread pkg/generators/markers.go
Comment thread pkg/generators/markers.go Outdated
Comment thread pkg/generators/markers.go
@aaron-prindle

Copy link
Copy Markdown

Currently only maxBytes is implemented upstream in k/k, this PR would have to wait until minBytes is also implemented

@aaron-prindle

Copy link
Copy Markdown

Can you also add test cases for this in markers_test similar to [min|max]Length in https://github.com/kubernetes/kube-openapi/blob/master/pkg/generators/markers_test.go

@aaron-prindle

aaron-prindle commented May 7, 2026

Copy link
Copy Markdown

Thanks for the PR here @BasavarajBankolli. Currently the PR here opts to map maxBytes/minBytes directly onto OpenAPI's maxLength/minLength. This option makes k/k native type validation and OpenAPI-side validation disagree (OpenAPI counts characters; the k/k MaxBytes validator counts bytes).

The initial issue here: kubernetes/kubernetes#137613 left the OpenAPI representation as an explicit open design question ("new x-kubernetes tag? CEL rule?" which has not gotten consensus as you noted here: kubernetes/kubernetes#137613 (comment)). We likely want to get consensus on this before implementation here. I've added some comments here assuming the CEL method but realistically we want to get some sig-apimachinery folks to confirm on the issue there the approach before implementing.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BasavarajBankolli
Once this PR has been reviewed and has the lgtm label, please assign jpbetz 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

@BasavarajBankolli

Copy link
Copy Markdown
Author

Thanks for the detailed feedback!

Updated the PR to:

  • remove the direct maxBytes/minBytes -> maxLength/minLength mapping
  • remove the maxLength/maxBytes conflict checks
  • add string-type validation checks for maxBytes
  • reduce scope to maxBytes only since minBytes is not yet implemented upstream in k/k
  • add marker tests similar to maxLength/minLength

Comment thread pkg/generators/markers.go Outdated
Comment thread pkg/generators/markers.go Outdated
@coderabbitai coderabbitai Bot mentioned this pull request Jun 5, 2026
9 tasks
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. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Declarative Validation] +k8s:[min|max]Bytes openAPI representation

6 participants