From 0d772a7a529208cc70432ddee0b24c907312d10c Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Thu, 4 Feb 2016 13:51:37 -0800 Subject: [PATCH] To be compatible with release 1.1, decode Status even if the APIVersion is not set. --- pkg/client/unversioned/request.go | 11 +++++++---- pkg/client/unversioned/restclient_test.go | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/client/unversioned/request.go b/pkg/client/unversioned/request.go index 3789cdccd2..66fc7b367a 100644 --- a/pkg/client/unversioned/request.go +++ b/pkg/client/unversioned/request.go @@ -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 } diff --git a/pkg/client/unversioned/restclient_test.go b/pkg/client/unversioned/restclient_test.go index 8a5968b313..912611f4ab 100644 --- a/pkg/client/unversioned/restclient_test.go +++ b/pkg/client/unversioned/restclient_test.go @@ -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)) } }