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

allow unknown metadata fields #2249

Merged

Conversation

dprotaso
Copy link
Member

@dprotaso dprotaso commented Sep 1, 2021

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 1, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 1, 2021
@dprotaso
Copy link
Member Author

dprotaso commented Sep 1, 2021

/assign @julz @markusthoemmes @shinigambit
/hold

I'm going to test downstream

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2021
Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

I love this 🥳 . Had something similar in mind but didn't dare doing the parsing shenanigans. Great stuff!

if v == "metadata" && level == 1 {
start = dec.InputOffset()
x := struct{}{}
if err = dec.Decode(&x); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this guaranteed to move the decoder to the end of the entire metadata object? Even if there's sub objects like annotations for example? Is that worth an extra test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this guaranteed to move the decoder to the end of the entire metadata object?

Yeah - it's decoding the metadata value into the empty struct.

Even if there's sub objects like annotations for example? Is that worth an extra test?

It's easy enough to add so we can catch regressions if someone changes the implementation

@dprotaso
Copy link
Member Author

dprotaso commented Sep 1, 2021

I love this 🥳 . Had something similar in mind but didn't dare doing the parsing shenanigans. Great stuff!

The biggest gain over the naive implementation is because we bail out early after we have the metadata byte offsets.

@codecov
Copy link

codecov bot commented Sep 1, 2021

Codecov Report

Merging #2249 (801d2af) into main (e957ee5) will increase coverage by 0.13%.
The diff coverage is 93.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2249      +/-   ##
==========================================
+ Coverage   63.92%   64.05%   +0.13%     
==========================================
  Files         220      221       +1     
  Lines        9550     9596      +46     
==========================================
+ Hits         6105     6147      +42     
- Misses       3172     3174       +2     
- Partials      273      275       +2     
Impacted Files Coverage Δ
webhook/resourcesemantics/defaulting/defaulting.go 79.62% <75.00%> (-0.50%) ⬇️
...k/resourcesemantics/validation/validation_admit.go 92.94% <75.00%> (-0.32%) ⬇️
webhook/json/decode.go 96.29% <96.29%> (ø)
test/gcs/mock/mock.go 90.32% <0.00%> (-1.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82f3a9f...801d2af. Read the comment docs.


for {
t, err = dec.Token()
if err == io.EOF { //nolint
Copy link
Contributor

Choose a reason for hiding this comment

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

can we not do the errors.Is thing? (I guess this is asking for that?)

Copy link
Member Author

Choose a reason for hiding this comment

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

You could but it's not necessary - https://pkg.go.dev/encoding/json#Decoder.Token states it will return io.EOF

@dprotaso
Copy link
Member Author

dprotaso commented Sep 1, 2021

Downstream serving passes
/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2021
Copy link
Contributor

@markusthoemmes markusthoemmes 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

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 2, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, markusthoemmes

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

@knative-prow-robot knative-prow-robot merged commit 0482448 into knative:main Sep 2, 2021
@dprotaso dprotaso deleted the allow-unknown-metadata-fields branch September 2, 2021 14:36
@dprotaso
Copy link
Member Author

dprotaso commented Sep 2, 2021

/cherry-pick release-0.25
/cherry-pick release-0.24
/cherry-pick release-0.23
/cherry-pick release-0.22

@knative-prow-robot
Copy link
Contributor

@dprotaso: new pull request created: #2254

In response to this:

/cherry-pick release-0.25
/cherry-pick release-0.24
/cherry-pick release-0.23
/cherry-pick release-0.22

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.

@dprotaso
Copy link
Member Author

dprotaso commented Sep 2, 2021

@chizhg do we have the latest cherry pick plugin? It should support multiple invocations

kubernetes/test-infra#21714

@dprotaso
Copy link
Member Author

dprotaso commented Sep 2, 2021

/cherry-pick release-0.24

@dprotaso
Copy link
Member Author

dprotaso commented Sep 2, 2021

/cherry-pick release-0.23

@dprotaso
Copy link
Member Author

dprotaso commented Sep 2, 2021

/cherry-pick release-0.22

@knative-prow-robot
Copy link
Contributor

@dprotaso: new pull request created: #2255

In response to this:

/cherry-pick release-0.24

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.

@knative-prow-robot
Copy link
Contributor

@dprotaso: new pull request created: #2256

In response to this:

/cherry-pick release-0.23

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.

@knative-prow-robot
Copy link
Contributor

@dprotaso: new pull request created: #2257

In response to this:

/cherry-pick release-0.22

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.

benmoss pushed a commit to benmoss/eventing-rabbitmq that referenced this pull request Sep 17, 2021
Need to pull in knative/pkg#2249 for k8s 1.22
support
benmoss pushed a commit to benmoss/eventing-rabbitmq that referenced this pull request Sep 20, 2021
Need to pull in knative/pkg#2249 for k8s 1.22
support
knative-prow-robot pushed a commit to knative-extensions/eventing-rabbitmq that referenced this pull request Sep 20, 2021
* Bump to cert-manager 1.5.3

1.2.0 no longer works with k8s 1.22

* Bump to latest eventing patch releases

Need to pull in knative/pkg#2249 for k8s 1.22
support
egegunes added a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Oct 15, 2021
Validation webhook was failing with `json: unknown field "subresource"`
on decoding the admission request. It's because of the new "subresource"
field in `metadata.managedFields`[^0]. Folks in Knative fixed the
issue[^1] with creating a custom json decoder that ignores unknown
fields *only* in metadata.

[^0]: kubernetes/apimachinery@5c420e5
[^1]: knative/pkg#2249
hors pushed a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Oct 18, 2021
* K8SPXC-885: Fix validation webhook on k8s 1.22

Validation webhook was failing with `json: unknown field "subresource"`
on decoding the admission request. It's because of the new "subresource"
field in `metadata.managedFields`[^0]. Folks in Knative fixed the
issue[^1] with creating a custom json decoder that ignores unknown
fields *only* in metadata.

[^0]: kubernetes/apimachinery@5c420e5
[^1]: knative/pkg#2249

* address review comments

Co-authored-by: Mykola Marzhan <mykola.marzhan@percona.com>

Co-authored-by: Mykola Marzhan <mykola.marzhan@percona.com>
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mutation failed: cannot decode incoming new object: json: unknown field "subresource"
5 participants