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

Should respect +required #943

Closed
thockin opened this issue May 3, 2024 · 10 comments · Fixed by #944
Closed

Should respect +required #943

thockin opened this issue May 3, 2024 · 10 comments · Fixed by #944
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@thockin
Copy link

thockin commented May 3, 2024

What do you want to happen?

Generating CRD from a field defined as:

// +required
Foo string `json:"foo,omitempty" protobuf:"bytes,1,opt,name=foo"`

...should be determined as "required" and not optional. It's a little wonky, but context is kubernetes/kubernetes#124553 (comment) and kubernetes/kubernetes#124553 (comment)

Extra Labels

No response

@camilamacedo86
Copy link
Member

Hi @thockin,

The project responsible for generate the CRDs and etc is the controller-tools: https://github.com/kubernetes-sigs/controller-tools

So, can you please raise this issue against their repo?

Also, see that you are using omitempty therefore, you are saying that it can be empty so I do not think that the "+required" can work in this case. You must remove omitempty otherwise, an empty value is also acceptable.

Thank you for your understanding.
I hope that this can help you.

Cheers,

@camilamacedo86
Copy link
Member

Hi @thockin

Also, see: kubernetes-sigs/kubebuilder#3794
Note that we clarify it in the docs.

@thockin
Copy link
Author

thockin commented May 5, 2024

I am confused. I don't see +required documented, just +optional.

The point is that the cited example, with omitempty, does NOT get marked as required, despite the +required tag. I had to remove the omitempty.

Am I missing something?

@thockin
Copy link
Author

thockin commented May 5, 2024

Maybe to clarify - this is a tag used in kubernetes/api, which is being referenced by other CRDs. We don't want to use kubebuilder tags in k/k when we have "simple" equivalents.

@liggitt
Copy link
Contributor

liggitt commented May 7, 2024

agree this should be re-opened, so that kubebuilder can generate correct CRDs that embed built-in kubernetes go types

@liggitt
Copy link
Contributor

liggitt commented May 7, 2024

/reopen
/transfer controller-tools

@k8s-ci-robot k8s-ci-robot transferred this issue from kubernetes-sigs/kubebuilder May 7, 2024
@liggitt
Copy link
Contributor

liggitt commented May 7, 2024

omitempty means a zero value should not be serialized. That is independent of whether a value is required. An explicit +required indicates this in kube-openapi / kubernetes API types

@liggitt
Copy link
Contributor

liggitt commented May 7, 2024

/reopen

@k8s-ci-robot
Copy link
Contributor

@liggitt: Reopened this issue.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@sbueringer
Copy link
Member

sbueringer commented May 7, 2024

Agree, we should support +required. Just like we already support +optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants