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

[client-go] Renegotiate Streaming Content-Type #62175

Conversation

DirectXMan12
Copy link
Contributor

REST clients in client-go have two content type fields -- the "accepted"
content types, and the default content type. When we set up
serializers and such, we set up default decoders, etc for the default
content type, and set up a "renegotiation function" to renegotiate in
case the server sends some other content type.

However, in the case of streaming, we don't do renegotiation properly --
we assume whatever the server sent is compatible with our default stream
framing/decoding.

This is fine an dandy when it actually is compatible, and is generally
fine an dandy when using the JSON content type as the default, because
most things support JSON. However, if you set your default up to, say,
protobuf, and then try to use that REST config to construct a REST
client for talking to the custom resources API server, you're going to
have a bad time, since it doesn't support protobuf, only JSON.

This in turn causes weird behavior like watches starting succesfully,
but never actuall firing any watch events.

To fix this, this commit introduces a new renegotiation function for
streaming serialization and framing, and checks to see if it needs to be
used.

Release note:

Fix content-type negotiation in streaming watch requests in client-go

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 5, 2018
@DirectXMan12
Copy link
Contributor Author

cc @kubernetes/sig-api-machinery-bugs @kubernetes/sig-api-machinery-pr-reviews

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. kind/bug Categorizes issue or PR as related to a bug. labels Apr 5, 2018
if err != nil {
return nil, err
}
normalDecoder, streamingSerializer, framer, err = r.serializers.RenegotiatedStreaming(mediaType, params)
Copy link
Member

Choose a reason for hiding this comment

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

this assumes RenegotiatedStreaming is non-nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the code seemed to assume StreamingSerializer was non-nil before. I'll add a check in to be safe.

@@ -200,6 +201,14 @@ func createSerializers(config ContentConfig) (*Serializers, error) {
if info.StreamSerializer != nil {
s.StreamingSerializer = info.StreamSerializer.Serializer
s.Framer = info.StreamSerializer.Framer
s.RenegotiatedStreaming = func(contentType string, params map[string]string) (runtime.Decoder, runtime.Serializer, runtime.Framer, error) {
Copy link
Member

Choose a reason for hiding this comment

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

definitely needs tests to cover positive and negative cases around this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, will do. Wanted to make sure there wasn't something I missed with the approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed some basic tests, can do more if needed (will probably write a few more on monday anyway)

REST clients in client-go have two content type fields -- the "accepted"
content types, and the default content type.  When we set up
serializers and such, we set up default decoders, etc for the default
content type, and set up a "renegotiation function" to renegotiate in
case the server sends some other content type.

However, in the case of streaming, we don't do renegotiation properly --
we assume whatever the server sent is compatible with our default stream
framing/decoding.

This is fine an dandy when it actually is compatible, and is generally
fine an dandy when using the JSON content type as the default, because
most things support JSON.  However, if you set your default up to, say,
protobuf, and then try to use that REST config to construct a REST
client for talking to the custom resources API server, you're going to
have a bad time, since it doesn't support protobuf, only JSON.

This in turn causes weird behavior like watches starting succesfully,
but never actuall firing any watch events.

To fix this, this commit introduces a new renegotiation function for
streaming serialization and framing, and checks to see if it needs to be
used.
@DirectXMan12 DirectXMan12 force-pushed the bug/renegotiate-streaming-content-type branch from 2ca9e67 to bd2f112 Compare April 5, 2018 22:23
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 5, 2018
@rmmh rmmh removed their request for review April 6, 2018 21:56
@wenjiaswe
Copy link
Contributor

cc @yliaog

@k8s-ci-robot
Copy link
Contributor

@DirectXMan12: PR needs rebase.

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2018
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 25, 2018
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 24, 2018
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

@liggitt liggitt added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Oct 17, 2018
@k8s-ci-robot
Copy link
Contributor

@DirectXMan12: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-kops-aws bd2f112 link /test pull-kubernetes-e2e-kops-aws
pull-kubernetes-integration bd2f112 link /test pull-kubernetes-integration
pull-kubernetes-e2e-gce bd2f112 link /test pull-kubernetes-e2e-gce
pull-kubernetes-e2e-gce-device-plugin-gpu bd2f112 link /test pull-kubernetes-e2e-gce-device-plugin-gpu
pull-kubernetes-e2e-gce-100-performance bd2f112 link /test pull-kubernetes-e2e-gce-100-performance
pull-kubernetes-node-e2e bd2f112 link /test pull-kubernetes-node-e2e
pull-kubernetes-bazel-test bd2f112 link /test pull-kubernetes-bazel-test
pull-kubernetes-bazel-build bd2f112 link /test pull-kubernetes-bazel-build
pull-kubernetes-kubemark-e2e-gce-big bd2f112 link /test pull-kubernetes-kubemark-e2e-gce-big
pull-kubernetes-typecheck bd2f112 link /test pull-kubernetes-typecheck
pull-kubernetes-verify bd2f112 link /test pull-kubernetes-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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 understand the commands that are listed here.

@jsafrane
Copy link
Member

seems related to #67803 (comment)

Yes, symptoms described here is what I saw in #67803 (review). Client created there worked just fine with JSON, only watch events were sent by API server as protobuf and the client failed to parse them. My informer thus did not get any events.

@DirectXMan12
Copy link
Contributor Author

I'll try and rebase this soonish

smarterclayton added a commit to smarterclayton/kubernetes that referenced this pull request Feb 11, 2019
This e2e test reproduces kubernetes#62175 and will be expanded to check for other
negotiation related errors against real servers.
smarterclayton added a commit to smarterclayton/kubernetes that referenced this pull request Feb 18, 2019
This e2e test reproduces kubernetes#62175 and will be expanded to check for other
negotiation related errors against real servers.
@liggitt liggitt removed their assignment Apr 2, 2019
smarterclayton added a commit to smarterclayton/kubernetes that referenced this pull request Nov 3, 2019
This e2e test reproduces kubernetes#62175 and will be expanded to check for other
negotiation related errors against real servers.
smarterclayton added a commit to smarterclayton/kubernetes that referenced this pull request Nov 3, 2019
This e2e test reproduces kubernetes#62175 and will be expanded to check for other
negotiation related errors against real servers.
@liggitt
Copy link
Member

liggitt commented Nov 11, 2019

/close

in favor of #84692

@k8s-ci-robot
Copy link
Contributor

@liggitt: Closed this PR.

In response to this:

/close

in favor of #84692

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.

smarterclayton added a commit to smarterclayton/kubernetes that referenced this pull request Nov 11, 2019
This e2e test reproduces kubernetes#62175 and will be expanded to check for other
negotiation related errors against real servers.
@DirectXMan12 DirectXMan12 deleted the bug/renegotiate-streaming-content-type branch December 4, 2019 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.

None yet

7 participants