-
Notifications
You must be signed in to change notification settings - Fork 427
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
🐛 Add XPreserveUnknownFields to runtime.RawExtension #683
🐛 Add XPreserveUnknownFields to runtime.RawExtension #683
Conversation
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
Hi @eddycharly. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/assign @joelanford |
I think my main concern is that anyone already using runtime.RawExtension with controller-gen is already generating a CRD schema without At a minimum, I think I'd label this as a breaking change rather than a bug fix. We might also need to consider making this behavior opt-in. @benluddy was actually chatting with me the other day about a similar request to improve the auto-generated schema for In this case, we would start allowing fields not mentioned in the schema to be preserved, which seems a little bit different than making a schema more strict. Maybe @alvaroaleman and @vincepri have opinions? |
But if ppl do that without /ok-to-test If we merge this, it will need a test btw. |
I wonder how one can use It looks like it just doesn’t work to me, all fields get pruned and the object ends up empty 🤔 |
Exactly what we observed, we ended up with empty objects, all fields were pruned. |
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
@@ -7340,9 +7341,11 @@ spec: | |||
minLength: 4 | |||
type: string | |||
unprunedEmbeddedResource: | |||
allOf: |
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.
This looks strange, not sure where I should look at.
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.
@joelanford @alvaroaleman do you have an idea where I should look in the code to find why this gets transformed into allOf
?
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.
From what I understand it happens in the flattener. I’m a bit lost in the code though. Any hint would be appreciated.
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.
I think it happens when kubebuilder:pruning:PreserveUnknownFields
is present on a field and the target type. I can reproduce with any struct. Is this a bug ? Should both markers get merged together when generating the CRD ?
cc @alvaroaleman @joelanford
This PR could solve the question asked on stackoverflow and slack https://stackoverflow.com/questions/72577439/k8s-operator-read-raw-data . Thanks @eddycharly , and this should be merged after #689 to avoid the |
/label tide/merge-method-squash |
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
Rebased and updated manifest. |
/lgtm |
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, eddycharly 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 |
thanks! |
@alvaroaleman do I need to create a cherry pick PR ? |
/cherrypick release-0.9 |
@prateekpandey14: only kubernetes-sigs org members may request cherry picks. You can still do the cherry-pick manually. 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. |
/cherrypick release-0.9 |
@FillZpp: new pull request created: #699 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. |
/cherrypick release-0.9 |
@FillZpp: new pull request created: #703 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. |
This PR adds
XPreserveUnknownFields
toruntime.RawExtension
.runtime.RawExtension
hastype: object
but all fields will be pruned unlessx-kubernetes-preserve-unknown-fields: true
is specified.It seems reasonable to add
x-kubernetes-preserve-unknown-fields: true
by default, as was done withapiextensions.JSON
for examplecontroller-tools/pkg/crd/known_types.go
Lines 106 to 111 in a260f13