-
Notifications
You must be signed in to change notification settings - Fork 441
🐛 Don't generate schema with Any
in it, its not supported
#505
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
Conversation
This reverts commit e0d7c9d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This PR breaks the ability to generate CRDs that embed JSONSchemas. Is there some way to retain that support? At a minimum, maybe we can use x-kubernetes-preserve-unknown-fields? |
No it does not. |
The fact remains that previously it was possible to generate objects that had JSONSchema embedded in them via controller-gen and now it is not. From my eyes as a user, this is a regression. Before it would be possible for me to generate the CRD and clean it up later with kustomize or similar. Now that option is no longer available. Per my suggestion, finding some way to use |
Generating an invalid object that you can then manually fix is not a feature, its a bug. Please describe the problem you are having in a new issue rather than resurrecting old issues and PRs. |
From a pragmatic standpoint, I disagree. This eliminates the possibility of users who are aware that this is an edge case that needs to be handled including controller-gen in their generation pipeline. Generation pipelines are the purpose for which controller-gen was intended. If we want to assume that we only generate output that passes K8s validation (not necessarily wise, as it couples controller-gen to specific K8s versions), we could at least flag-gate the feature as in Further, there is a pre-existing issue that this PR re-breaks: I am happy to re-open |
This change broke anyones crds generation who had a type in them that had a JSONUnmarshaler implementation and no kubebuilder tags.
Please do that or create a new issue and please also feel free to suggest a fix that doesn't break ppl the way this one did. Conversations on old issues and PRs will go unnoticed for many. |
Interesting. Can you be more specific? This would happen even if the struct was not tagged with kubebuilder tags and happened to be in a package touched by controller-gen?
That is true for this specific instance. As a general design principal, I'm not sure it passes muster. Imagine
For sure, happy to continue the discussion. Note that the reason this thread was started is because this PR came up on a closed bug for which people were still experiencing issues. So far I have two (hand-wavy) proposals I've mentioned that satisfy your criteria:
Depending on if the bug gets re-opened, I'll add these suggestions there, though this PR is already linked to the old bug and will be linked to any new bugs. |
#502, as mentioned in the PR body. This would only happen if the struct was not tagged with kubebuilder tags.
Optimizing for something that one thinks could happen in the future without any evidence for that to actually happening is premature optimization. Once we would have this case, we would most likely allow it and tell ppl that it might fail on kube versions older min supported.
#291 is a kitchen sink bug for all kind of issues ppl had over time, mostly with types that are part of the k8s.io api. Please open a new bug, paste the relevant part of your type and mention what you want to happen. Right now this is a thin air discussion.
Its unclear to me what you mean by "if jsonschema is embedded'. The reverted change made the assumption that ppl want an invalid CRD if they have types that implement a JSONUnmarshaler and do not have kubebuilder tags. That assumption does definitely not make sense. The same would go for adding |
Ack, the linked bug clarifies what you were fixing.
In this case I am not suggesting optimizing for a case that we think could happen in the future.
Unless one of us is steering the actual direction behind this project, it's probably not worth continuing this discussion here, as it would be a lot of debate with zero impact.
#291 is most definitely not a kitchen sink bug. From its title, it is for users trying to embed JSONSchemaProps in their CRDs. I agree that this reverted fix cast too wide a net. I'm looking at what it would take to add a new tag so people can opt-in to the schema-less behavior wrapping CRDs inside of CRDs appears to require. |
controller-runtime 0.4.1 fixed the issue where they generated types as Any which was an invalid type (kubernetes-sigs/controller-tools#505) however that results in the type for proxy-defaults.config being "byte" which fails when creating proxy-defaults. I played around a long time trying to find a type that generates the CRD as expected and can be unmarshalled as expected and nothing worked so for now I think it's best to keep it as json.RawMessage and then patch the generated CRD.
controller-runtime 0.4.1 fixed the issue where they generated types as Any which was an invalid type (kubernetes-sigs/controller-tools#505) however that results in the type for proxy-defaults.config being "byte" which fails when creating proxy-defaults. I played around a long time trying to find a type that generates the CRD as expected and can be unmarshalled as expected and nothing worked so for now I think it's best to keep it as json.RawMessage and then patch the generated CRD.
controller-runtime 0.4.1 fixed the issue where they generated types as Any which was an invalid type (kubernetes-sigs/controller-tools#505) however that results in the type for proxy-defaults.config being "byte" which fails when creating proxy-defaults. I played around a long time trying to find a type that generates the CRD as expected and can be unmarshalled as expected and nothing worked so for now I think it's best to keep it as json.RawMessage and then patch the generated CRD.
controller-runtime 0.4.1 fixed the issue where they generated types as Any which was an invalid type (kubernetes-sigs/controller-tools#505) however that results in the type for proxy-defaults.config being "byte" which fails when creating proxy-defaults. I played around a long time trying to find a type that generates the CRD as expected and can be unmarshalled as expected and nothing worked so for now I think it's best to keep it as json.RawMessage and then patch the generated CRD.
This reverts commit e0d7c9d.
Any
is not a valid (tested with both v1.18 and v1.19):See also https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#type although that list doesn't match whats in the error
cc @skaslev
Fixes #502
/assign @vincepri