apiserver/pkg/endpoints
Tristan Burgess 753c6a1ccc 50342: Establish '406 Not Acceptable' response for protobuf serialization 'errNotMarshalable'
- Added metav1.Status() that enforces '406 Not Acceptable' response if
    protobuf serialization is not fully supported for the API resource type.
     - JSON and YAML serialization are supposed to be more completely baked
    in, so serialization involving those, and general errors with seralizing
    protobuf, will return '500 Internal Server Error'.
	- If serialization failure occurs and original HTTP status code is
    error, use the original status code, else use the serialization failure
    status code.
     - Write encoded API responses to intermediate buffer
     - Use apimachinery/runtime::Encode() instead of
    apimachinery/runtime/protocol::Encode() in
    apiserver/endpoints/handlers/responsewriters/writers::SerializeObject()
     - This allows for intended encoder error handling to fully work, facilitated by
    apiserver/endpoints/handlers/responsewriters/status::ErrorToAPIResponse() before officially
    writing to the http.ResponseWriter
     - The specific part that wasn't working by ErrorToAPIResponse() was the
    HTTP status code set. A direct call to
    http.ResponseWriter::WriteHeader(statusCode) was made in
    SerializeObject() with the original response status code, before
    performing the encode. Once this
    method is called, it can not again update the status code at a later
    time, with say, an erro status code due to encode failure.
     - Updated relevant apiserver unit test to reflect the new behavior
    (TestWriteJSONDecodeError())
     - Add build deps from make update for protobuf serializer

50342: Code review suggestion impl
 - Ensure that http.ResponseWriter::Header().Set() is called before http.ResponseWriter::WriteHeader()
    - This will avert a potential issue where changing the response media type to text/plain wouldn't work.
    - We want to respond with plain text if serialization fails of the original response, and serialization also fails for the resultant error response.

50342: wrapper for http.ResponseWriter
  - Prevent potential performance regression caused by modifying encode to use a buffer instead of streaming
    - This is achieved by creating a wrapper type for http.ResponseWriter that will use WriteHeader(statusCode) on the first
    call to Write(). Thus, on encode success, Write() will write the original statusCode. On encode failure, we pass control
    onto responsewriters::errSerializationFatal(), which will process the error to obtain potentially a new status code, depending
    on whether or not the original status code was itself an error.

50342: code review suggestions
  - Remove historical note from unit test comment
  - Don't export httpResponseWriterWithInit type (for now)

Kubernetes-commit: bcdf3bb64333ce12f15b1beebef48f554d69027f
2018-08-06 19:18:36 -04:00
..
discovery legacy api endpoints only support v1 ever 2018-06-22 08:58:32 -04:00
filters Escape illegal characters in remote extra keys 2018-07-03 21:19:15 -07:00
handlers 50342: Establish '406 Not Acceptable' response for protobuf serialization 'errNotMarshalable' 2018-08-06 19:18:36 -04:00
metrics Fix apiserver metrics 2018-06-29 14:15:53 +02:00
openapi Correctly identify types served in the kube-apiserver openapi doc 2018-05-22 19:29:00 -04:00
request remove request context.WithUID 2018-05-17 11:39:48 +08:00
testing sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:38:17 +00:00
apiserver_test.go 50342: Establish '406 Not Acceptable' response for protobuf serialization 'errNotMarshalable' 2018-08-06 19:18:36 -04:00
audit_test.go add ut for audit useragent 2018-06-08 17:06:39 +08:00
doc.go Mechanical fixup imports: pkg/genericapiserver 2017-02-13 07:36:41 -05:00
groupversion.go Add additional authorization check for create-on-update 2018-07-03 11:20:16 -07:00
installer.go Skip building openapi for ignored paths 2018-07-24 16:11:42 -07:00
installer_test.go remove go-restful from namer for rest handling 2017-04-10 20:35:11 +00:00
patchhandler_test.go apiserver: move patch tests to their own file 2018-04-18 10:54:35 -07:00
watch_test.go remove dead code 2017-07-16 04:08:41 +00:00