Skip to content

Commit

Permalink
Merge pull request kubernetes#20674 from caesarxuchao/decode-status
Browse files Browse the repository at this point in the history
To be compatible with release 1.1, decode Status even if the APIVersion is not set in the response
  • Loading branch information
lavalamp committed Feb 5, 2016
2 parents 15df7c7 + 0d772a7 commit 2e7993e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions pkg/client/unversioned/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,13 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu

// Did the server give us a status response?
isStatusResponse := false
var status *unversioned.Status
result, err := runtime.Decode(r.content.Codec, body)
if out, ok := result.(*unversioned.Status); err == nil && ok && len(out.Status) > 0 {
status = out
// Because release-1.1 server returns Status with empty APIVersion at paths
// to the Extensions resources, we need to use DecodeInto here to provide
// default groupVersion, otherwise a status response won't be correctly
// decoded.
status := &unversioned.Status{}
err := runtime.DecodeInto(r.content.Codec, body, status)
if err == nil && len(status.Status) > 0 {
isStatusResponse = true
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/client/unversioned/restclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ func TestDoRequestFailed(t *testing.T) {
t.Errorf("unexpected error type %v", err)
}
actual := ss.Status()
if !reflect.DeepEqual(status, &actual) {
expected := *status
// The decoder will apply the default Version and Kind to the Status.
expected.APIVersion = "v1"
expected.Kind = "Status"
if !reflect.DeepEqual(&expected, &actual) {
t.Errorf("Unexpected mis-match: %s", util.ObjectDiff(status, &actual))
}
}
Expand Down

0 comments on commit 2e7993e

Please sign in to comment.