-
Notifications
You must be signed in to change notification settings - Fork 411
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
markers to skip fields that does not have json tags for crd generation #391
Comments
/kind feature I'm assuming URL has custom serialization. We need a good way to detect that a type has custom serialization and use that instead of the fields. |
/help |
@DirectXMan12: Please ensure the request meets the requirements listed here. If this request no longer meets these requirements, the label can be removed In response to this:
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/test-infra repository. |
I'm running into the same issue. Is there a reasonable workaround for this? |
I've managed to work around the specific knative issues with the following patches: master...vishvananda:fix-known There must be a better way to do this than adding custom exceptions for every type, but I'm not sure of the best approach. Both of these objects have a MarshalJSON that writes the data as a string. |
The fix should be to check during schema generation if a type implements the {Marshal,Unmarshal}JSON interfaces, and if so treat it as opaque. We have type-checking information, so we can do this. |
Do you mean here?
|
@DirectXMan12 I'm interested in working on fix for this. Can you elaborate on what do you mean by treat them as opaque? Should schema generated for types with custom json serialization get declared as Any type? |
So, our code generator is built on introspection: for each type, visit its sub-types, etc, mapping them to jsonschema. Some types, however, can't or shouldn't be introspected. For these types, introspection produces bad results, because their serialized form is not equivalent to their Go form under our normal generation rules. Instead, we have to treat these types as if they're "opaque" -- i.e. we cannot see into them to look at their fields. Instead, we want to treat them as if they were That's a really longwinded way of saying "treat them like primitive types". |
@yuzisun I have also run into this issue attempting to add ducktyping into our CRD status (ie SeldonIO/seldon-core#1572). Is there a workaround for this? |
I have tried controller-gen built with #427 in my Kubernetes v1.15.3 cluster.
I have also tried on Kubernetes v1.17.0 cluster and |
You'll have to manually override the type when you use that capability. e.g. // +kubebuilder:validation:type=string
// +kubebuilder:validation:pattern="[😀-🙏]"
type SerializesAsEmoji uint8
func (v SerializesAsEmoji) MarshalJSON() ([]byte, error) {
return []byte(`"` + string(rune(0x1f600+v)) + `"`)
} |
@alvaroaleman: Reopened this issue. In response to this:
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/test-infra repository. |
So, I think the intent of #427 was that custom marshallers generate an invalid type (but doesn't traverse further), which you then must specify a valid type for. |
The description doesn't sound like that to me:
and IMHO generating invalid schema is not a great error handling strategy. On top of that, it irrevocably breaks everyone who has type with a custom marshaller as a dependency in their api. |
Fair, I think we were operating under the assumption that it wasn't possible before, but had overlooked the case of "you use all the normal JSON tags, but are using jsoniterator for performance" (which is the only case where we could generate valid openapi) |
(FWIW, with the revert, there's currently no way to make use of certain classes of custom-serialized types, even with markers) |
But how did this work before the revert? We generated |
Before the revert, you could do something like // +kubebuilder:validation:Type=object
type Weird map[string]interface{} // map[string]interface{} is normally invalid, but...
// ... custom marshalling means we *just* use the markers
func (w *Weird) UnmarshalJSON(data []byte) error { ... }
func (w *Weird) MarshalJSON() ([]byte, error) { ... } Which would get interpreted as:
So it supported cases where you don't want an object or you just want a catch-all object, but didn't support cases where you want a partially-specified object, or a fully specified object, which was an oversight. For whatever we merge, we should attempt to support both usecases. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Like yuzisun, I'm trying to add a field of type |
Rotten issues close after 30d of inactivity. Send feedback to sig-contributor-experience at kubernetes/community. |
@fejta-bot: Closing this issue. In response to this:
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/test-infra repository. |
Any update on this? I am working on a project using Knative and I have the exact same issue with OP. I am using controller-gen v0.5.0.
As #427 is reverted, is there a workaround for the issue? Or should this be an issue with Knative? Can I reopen this? |
@Ruminateer: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
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/test-infra repository. |
It looks like this may now be addressed in knative: knative/pkg#2431 |
controller-tools
version: 0.2.2Currently I am getting this error after upgrading controller-tools from 0.2.2 from 0.1.9 because in our CRD status we included a go struct
URL
(https://github.com/knative/pkg/blob/43ca049cdbdad4892b0c926e7c6536d064efde72/apis/duck/v1beta1/addressable_types.go#L40) which does not have json tags and this blocks generating the crd manifests.We want a way to skip fields when generating crd manifests.
The text was updated successfully, but these errors were encountered: