apiserver/pkg/endpoints/handlers
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
..
negotiation sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:38:17 +00:00
responsewriters 50342: Establish '406 Not Acceptable' response for protobuf serialization 'errNotMarshalable' 2018-08-06 19:18:36 -04:00
create.go Support dry run in admission plugins 2018-08-06 10:37:44 -07:00
delete.go Support dry run in admission plugins 2018-08-06 10:37:44 -07:00
doc.go Mechanical fixup imports: pkg/genericapiserver 2017-02-13 07:36:41 -05:00
get.go change field selector conversion registration to be strongly typed 2018-07-03 15:47:20 -04:00
namer.go Remove request context mapper 2018-04-18 11:12:15 -04:00
namer_test.go Add unittests for GenerateLink 2017-08-29 13:15:22 +00:00
patch.go Support dry run in admission plugins 2018-08-06 10:37:44 -07:00
response.go replace request.Context with context.Context 2018-04-24 08:10:34 -07:00
rest.go Remove rest.ConnectRequest. 2018-07-30 18:35:51 -07:00
rest_test.go remove useless codec param from strategicPatchObject 2018-07-17 11:33:53 +08:00
update.go Support dry run in admission plugins 2018-08-06 10:37:44 -07:00
watch.go Make conversion function names match expected values 2018-07-03 16:06:44 -04:00