Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubebuilder docs should more clearly state the interaction between kubebuilder:validation:Required and omitempty #3794

Open
jmeyers35 opened this issue Feb 21, 2024 · 4 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/documentation Categorizes issue or PR as related to documentation.

Comments

@jmeyers35
Copy link

What broke? What's expected?

This is purely a docs ask. I've run into the behavior noted in kubernetes-sigs/controller-tools#599 a handful of times, and I think that it can be pretty surprising. The most recent time I've hit this, it caused us to break backwards compatibility in a user's CRD when we removed an omitempty tag on a field. I think that the interaction between the required tag and omitempty should be more explicitly stated in the documentation (and maybe a warning added at generation time: you probably don't actually want both required and omitempty).

Reproducing this issue

No response

KubeBuilder (CLI) Version

N/A

PROJECT version

No response

Plugin versions

No response

Other versions

No response

Extra Labels

/kind documentation

@jmeyers35 jmeyers35 added the kind/bug Categorizes issue or PR as related to a bug. label Feb 21, 2024
@k8s-ci-robot k8s-ci-robot added the kind/documentation Categorizes issue or PR as related to documentation. label Feb 21, 2024
@camilamacedo86
Copy link
Member

Hi @jmeyers35,

Thank you for raising this one.

However, note that all documentation in kubebuilder is generated automatically via what is the doc in the source code of controller-tools. Therefore:

  • a) Can you please transfer this issue to the controller-tools repo. Your request cannot be addressed via Kubebuilder repo/code source or project

  • b) WDYT about open a pull request for controller-tools with the changes that you suggest. Therefore, when a new controller-tool release is made with it, the Kubebuilder docs will be updated.

Thank you for attention.

@vincepri @joelanford (could you please move this issue to controller-tools if the owner be unable to do so?)

@jmeyers35
Copy link
Author

I'm happy to open a PR for this at some point, but I wanted to flag this in case someone can get around to it before I can. I also could've been a bit more specific - when I said "documentation", I really meant the book, which I believe is indeed in this repo. But this is probably worth noting in the generated docs as well.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Feb 22, 2024

Hi @jmeyers35,

That is great. I see, the info that you would like to add in the docs is:

Update:
The omitempty tag in Foo string json:"foo,omitempty" had more precedence than the kubebuilder marker +kubebuilder:validation:Required therefore making the resultant generated crd field to be optional.

The +kubebuilder:validation:Required marker does works as desired when omitempty is not used.

I am not able to recall if docs(https://book.kubebuilder.io/) mentions it, but I hope it does.

With that I mark this issue to be closed.

Following some examples that I hope that help you:

Please feel free to open a PR with your suggestion on where you see that it should fit, and then we can move forward from there. Thank you for your collaboration 🥇

@camilamacedo86
Copy link
Member

Hi @jmeyers35

After share above the info to you, do you think that it still requiring further explanation?
Would you like to contribute with this one?

@camilamacedo86 camilamacedo86 added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. and removed kind/bug Categorizes issue or PR as related to a bug. labels May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/documentation Categorizes issue or PR as related to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants