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

sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error instead of falling back to second Accept type #86253

Open
liggitt opened this issue Dec 13, 2019 · 5 comments
Assignees
Labels
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. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.

Comments

@liggitt
Copy link
Member

liggitt commented Dec 13, 2019

What happened:
Creating an example object against the sample-apiserver returns the following error with a default client:

test/e2e/framework/framework.go:639
Dec 13 01:57:24.796: creating a new flunders resource
Unexpected error:
    <*errors.StatusError | 0xc0011a4aa0>: {
        ErrStatus: {
            TypeMeta: {Kind: "", APIVersion: ""},
            ListMeta: {
                SelfLink: "",
                ResourceVersion: "",
                Continue: "",
                RemainingItemCount: nil,
            },
            Status: "Failure",
            Message: "object *v1alpha1.Flunder does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message",
            Reason: "NotAcceptable",
            Details: nil,
            Code: 406,
        },
    }
    object *v1alpha1.Flunder does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message
occurred
test/e2e/apimachinery/aggregator.go:396

What you expected to happen:
The sample-apiserver would fall back to encoding the object in json

How to reproduce it (as minimally and precisely as possible):

  • Define a type that does not support protobuf
  • Create a client that accepts protobuf,json
  • Use that client to submit an object to the server

Anything else we need to know?:
Seen in a PR attempting to update the sample-apiserver used in e2e to 1.17.0 levels (#84735, https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/84735/pull-kubernetes-e2e-kind/1205296180716638211)

/sig api-machinery
/assign @smarterclayton

@liggitt liggitt added the kind/bug Categorizes issue or PR as related to a bug. label Dec 13, 2019
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. labels Dec 13, 2019
@liggitt liggitt added this to the v1.17 milestone Dec 13, 2019
@tedyu
Copy link
Contributor

tedyu commented Dec 13, 2019

In TestWatchNonDefaultContentType, there is test for falling back to JSON serialization:

+       // set the default content type to protobuf so that we test falling back to JSON serialization
+       contentConfig := defaultContentConfig()
+       contentConfig.ContentType = "application/vnd.kubernetes.protobuf"

@liggitt liggitt changed the title sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error v1.17.0: sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error Dec 13, 2019
@liggitt
Copy link
Member Author

liggitt commented Dec 13, 2019

In TestWatchNonDefaultContentType, there is test for falling back to JSON serialization:

That's testing client-side fallback. This bug is about a server serving a type which cannot be serialized using protobuf.

@liggitt liggitt changed the title v1.17.0: sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error Dec 13, 2019
@liggitt
Copy link
Member Author

liggitt commented Dec 13, 2019

I set up a simple addition to the sample-apiserver integration test to exercise this:

       flunder := `{"apiVersion":"wardle.k8s.io/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"abc","namespace":"default"}}`
       result := wardleClient.Discovery().RESTClient().Post().
               AbsPath("/apis/wardle.k8s.io/v1alpha1/namespaces/default/flunders").
               Body([]byte(flunder)).
               SetHeader("Content-Type", "application/json").
               SetHeader("Accept", "application/vnd.kubernetes.protobuf,application/json").
               Do()
       if err := result.Error(); err != nil {
               t.Fatal(err)
       }

Tested this across all releases since the working 1.10 API server:

  • 1.10: returns 200 with "cannot encode to protobuf" error
  • 1.11: returns 200 with "cannot encode to protobuf" error
  • 1.12: returns 406 with "cannot encode to protobuf" error
  • 1.13: returns 406 with "cannot encode to protobuf" error
  • 1.14: returns 406 with "cannot encode to protobuf" error
  • 1.15: returns 406 with "cannot encode to protobuf" error
  • 1.16: returns 406 with "cannot encode to protobuf" error
  • 1.17: returns 406 with "cannot encode to protobuf" error

@liggitt
Copy link
Member Author

liggitt commented Dec 13, 2019

digging further, 1.10 and 1.11 did not actually succeed, but returned 200 responses containing status errors (issue reported in #50342, fixed in #67041 to correctly report the error attempting to encode to protobuf)

we should still improve the server to fall back to other supported Accept types when the type being encoded did not support the first requested Accept encoding, but this is not a new issue

@liggitt liggitt added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. labels Dec 13, 2019
@liggitt liggitt removed this from the v1.17 milestone Dec 13, 2019
@liggitt
Copy link
Member Author

liggitt commented Dec 13, 2019

The likely approach here is to filter the encoders the server supports to the ones the type for a particular endpoint supports when deciding what types a particular resource supports.

@liggitt liggitt changed the title sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error sample-apiserver returns "$type does not implement the protobuf marshalling interface and cannot be encoded to a protobuf message" error instead of falling back to second Accept type Dec 13, 2019
@k8s-ci-robot k8s-ci-robot added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Dec 13, 2019
@liggitt liggitt removed the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Dec 13, 2019
@liggitt liggitt added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
None yet
4 participants