-
Notifications
You must be signed in to change notification settings - Fork 294
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
cmd/cue: get go
should support optional field comments
#2679
Comments
get go
should support optional field comments
Even though this is something that the kubernetes ecosystem invented themselves, and is thus relatively niche, I'm fine with adding support. It shouldn't affect any other users. The heuristic should look for And, since we're adding support for |
I believe this is the underlying implementation to evaluate whether a field is optional, so it may be worth emulating this behaviour. |
Since the This implies a |
@justenstall the change that Thomas is proposing here makes sense regardless, I think, and we should do it. Adding another |
What I'm trying to argue is that Either way, the implementation in 67ea9cf isn't complete. There are a range of marker comments defined by kubebuilder/controller-gen to describe validation rules: https://book.kubebuilder.io/reference/markers/crd-validation. I think supporting a subset in |
To be clear, this is not specific to kubebuilder. This is a convention for the Kubernetes API, as outlined by the Kubernetes Architecture SIG. This directive has a direct impact on the OpenAPI schemas generated by kube-openapi. Implementation of kubebuilder specific directives is definitely out of scope. |
I don't think it's an all or nothing for what it's worth - In the same vein, I don't think we should reject other |
Let me just add that it's great to have these sorts of discussion, so thanks for contributing @uhthomas and @justenstall. In situations like this especially, we need to rely on the experience and expertise of others to help shape things. And often it's the case that we need/want patterns to emerge to help steer how we should do things. |
The Kuberentes ecosystem use comments to denote whether a field is optional or required. The comment has a direct effect on the produced OpenAPI schema, and often means otherwise correct Go "schemas" will be represented incorrectly with CUE. https://github.com/kubernetes/community/blob/e977e6ea355f26130ca555d1e8704893727ee024/contributors/devel/sig-architecture/api-conventions.md#optional-vs-required In addition to the heuristics of the "omitempty" struct tag, the "// +optional" comment will now also mark a field as optional. The behaviour from the Kubernetes project which parses this comment as a key/value pair (tag) is also preserved. https://pkg.go.dev/k8s.io/gengo/types#ExtractCommentTags Fixes: #2679 Change-Id: Ieeb2e7bee61e16ed9910ea46e68cb1a3eaa47197 Signed-off-by: Thomas Way <[email protected]>
Is your feature request related to a problem? Please describe.
The Kuberentes ecosystem use comments to denote whether a field is optional or required. The comment has a direct effect on the produced OpenAPI schema, and often means otherwise correct Go "schemas" will be represented incorrectly with CUE.
https://github.com/kubernetes/community/blob/e977e6ea355f26130ca555d1e8704893727ee024/contributors/devel/sig-architecture/api-conventions.md#optional-vs-required
Describe the solution you'd like
CUE should consider the
+optional
comment when evaluating whether a field is optional.https://github.com/cue-lang/cue/blob/273602f2266fd12b2aa6f42a6f3119c1294b7fb9/cmd/cue/cmd/get_go.go#L1397C21-L1397C31
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: