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

🐛 Add XPreserveUnknownFields to runtime.RawExtension #683

Merged
merged 4 commits into from Jun 14, 2022

Conversation

eddycharly
Copy link
Contributor

This PR adds XPreserveUnknownFields to runtime.RawExtension.

runtime.RawExtension has type: object but all fields will be pruned unless x-kubernetes-preserve-unknown-fields: true is specified.

It seems reasonable to add x-kubernetes-preserve-unknown-fields: true by default, as was done with apiextensions.JSON for example

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1": func(p *Parser, pkg *loader.Package) {
p.Schemata[TypeIdent{Name: "JSON", Package: pkg}] = apiext.JSONSchemaProps{
XPreserveUnknownFields: boolPtr(true),
}
p.AddPackage(pkg) // get the rest of the types
},

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 25, 2022
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 25, 2022
@eddycharly
Copy link
Contributor Author

/assign @joelanford

@joelanford
Copy link
Member

I think my main concern is that anyone already using runtime.RawExtension with controller-gen is already generating a CRD schema without x-kubernetes-preserve-unknown-fields. This PR would cause those users to get a potentially undesired CRD schema change.

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 time.Duration, which would make the schema more strict to align with the expectations of time.ParseDuration.

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?

@alvaroaleman
Copy link
Member

I think my main concern is that anyone already using runtime.RawExtension with controller-gen is already generating a CRD schema without x-kubernetes-preserve-unknown-fields. This PR would cause those users to get a potentially undesired CRD schema change.

But if ppl do that without x-kubernetes-preserve-unknown-fields. then everything in that field will be pruned today or not, as its schema is unknown at the CRD level?

/ok-to-test

If we merge this, it will need a test btw.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 25, 2022
@eddycharly
Copy link
Contributor Author

I wonder how one can use runtime.RawExtension without x-kubernetes-preserve-unknown-fields.

It looks like it just doesn’t work to me, all fields get pruned and the object ends up empty 🤔

@eddycharly
Copy link
Contributor Author

eddycharly commented May 25, 2022

But if ppl do that without x-kubernetes-preserve-unknown-fields. then everything in that field will be pruned today or not, as its schema is unknown at the CRD level?

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:
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@FillZpp
Copy link
Contributor

FillZpp commented Jun 13, 2022

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 allOf: x-kubernetes-preserve-unknown-fields. Am I right?

@eddycharly
Copy link
Contributor Author

@FillZpp Yes #689 was a prerequisite for this one.

@alvaroaleman
Copy link
Member

/label tide/merge-method-squash

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 13, 2022
@eddycharly
Copy link
Contributor Author

Rebased and updated manifest.

@FillZpp
Copy link
Contributor

FillZpp commented Jun 14, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2022
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2022
@alvaroaleman
Copy link
Member

thanks!

@k8s-ci-robot k8s-ci-robot merged commit 529c857 into kubernetes-sigs:master Jun 14, 2022
@eddycharly eddycharly deleted the raw-extension branch June 14, 2022 09:13
@eddycharly
Copy link
Contributor Author

@alvaroaleman do I need to create a cherry pick PR ?

@prateekpandey14
Copy link

/cherrypick release-0.9

@k8s-infra-cherrypick-robot

@prateekpandey14: only kubernetes-sigs org members may request cherry picks. You can still do the cherry-pick manually.

In response to this:

/cherrypick release-0.9

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.

@FillZpp
Copy link
Contributor

FillZpp commented Jul 2, 2022

/cherrypick release-0.9

@k8s-infra-cherrypick-robot

@FillZpp: new pull request created: #699

In response to this:

/cherrypick release-0.9

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.

@FillZpp
Copy link
Contributor

FillZpp commented Jul 5, 2022

/cherrypick release-0.9

@k8s-infra-cherrypick-robot

@FillZpp: new pull request created: #703

In response to this:

/cherrypick release-0.9

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants