Merge pull request #84807 from clarklee92/ModifyTheStatusCode

Modify the status code number to HTTP status semantics

Kubernetes-commit: 43b102a83cc1d2b97a6a59f1c14967a840df2c35
This commit is contained in:
Kubernetes Publisher
2019-11-06 12:20:46 -08:00
6 changed files with 43 additions and 43 deletions

8
Godeps/Godeps.json generated
View File

@@ -248,7 +248,7 @@
},
{
"ImportPath": "github.com/spf13/pflag",
"Rev": "v1.0.3"
"Rev": "v1.0.5"
},
{
"ImportPath": "github.com/stretchr/objx",
@@ -328,7 +328,7 @@
},
{
"ImportPath": "gopkg.in/inf.v0",
"Rev": "v0.9.0"
"Rev": "v0.9.1"
},
{
"ImportPath": "gopkg.in/tomb.v1",
@@ -344,11 +344,11 @@
},
{
"ImportPath": "k8s.io/api",
"Rev": "ccca0f5a3d9c"
"Rev": "43b1ad33cf6f"
},
{
"ImportPath": "k8s.io/apimachinery",
"Rev": "e1faffd14b0f"
"Rev": "9c5262af35ca"
},
{
"ImportPath": "k8s.io/gengo",

12
go.mod
View File

@@ -21,15 +21,15 @@ require (
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7
github.com/imdario/mergo v0.3.5
github.com/peterbourgon/diskv v2.0.1+incompatible
github.com/spf13/pflag v1.0.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
google.golang.org/appengine v1.5.0 // indirect
k8s.io/api v0.0.0-20191106113314-ccca0f5a3d9c
k8s.io/apimachinery v0.0.0-20191106113314-e1faffd14b0f
k8s.io/api v0.0.0-20191107110442-43b1ad33cf6f
k8s.io/apimachinery v0.0.0-20191107082716-9c5262af35ca
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d
sigs.k8s.io/yaml v1.1.0
@@ -44,6 +44,6 @@ replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190209173611-3b5209105503
golang.org/x/text => golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db
golang.org/x/time => golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
k8s.io/api => k8s.io/api v0.0.0-20191106113314-ccca0f5a3d9c
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191106113314-e1faffd14b0f
k8s.io/api => k8s.io/api v0.0.0-20191107110442-43b1ad33cf6f
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191107082716-9c5262af35ca
)

12
go.sum
View File

@@ -118,8 +118,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
@@ -162,8 +162,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
@@ -174,8 +174,8 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20191106113314-ccca0f5a3d9c/go.mod h1:G5tvI6ifMdaCxrt7IxNqBlivTSMnkdyJ7eZyXtIOl3M=
k8s.io/apimachinery v0.0.0-20191106113314-e1faffd14b0f/go.mod h1:gA1T9z4LIup7PIegBwxkF2UYXUNVKhOAPvQWWnAc34k=
k8s.io/api v0.0.0-20191107110442-43b1ad33cf6f/go.mod h1:/24HivhMZ6CLcfc0Nk41go4k5jb5bBTAP+9UA293OCw=
k8s.io/apimachinery v0.0.0-20191107082716-9c5262af35ca/go.mod h1:DJOb3m0kw91A0YaUsaoYChi4d7xVF84HLiuRCxGsV04=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=

View File

@@ -476,25 +476,25 @@ func Test_cmdTokenSource_roundTrip(t *testing.T) {
}{
{
"Unauthorized",
http.Response{StatusCode: 401},
http.Response{StatusCode: http.StatusUnauthorized},
make(map[string]string),
make(map[string]string),
},
{
"Unauthorized, nonempty defaultCache",
http.Response{StatusCode: 401},
http.Response{StatusCode: http.StatusUnauthorized},
cmdCache,
cmdCache,
},
{
"Authorized",
http.Response{StatusCode: 200},
http.Response{StatusCode: http.StatusOK},
make(map[string]string),
simpleCacheUpdated,
},
{
"Authorized, nonempty defaultCache",
http.Response{StatusCode: 200},
http.Response{StatusCode: http.StatusOK},
cmdCache,
cmdCacheUpdated,
},

View File

@@ -515,17 +515,17 @@ func TestTransformResponse(t *testing.T) {
Error bool
ErrFn func(err error) bool
}{
{Response: &http.Response{StatusCode: 200}, Data: []byte{}},
{Response: &http.Response{StatusCode: 201}, Data: []byte{}, Created: true},
{Response: &http.Response{StatusCode: http.StatusOK}, Data: []byte{}},
{Response: &http.Response{StatusCode: http.StatusCreated}, Data: []byte{}, Created: true},
{Response: &http.Response{StatusCode: 199}, Error: true},
{Response: &http.Response{StatusCode: 500}, Error: true},
{Response: &http.Response{StatusCode: 422}, Error: true},
{Response: &http.Response{StatusCode: 409}, Error: true},
{Response: &http.Response{StatusCode: 404}, Error: true},
{Response: &http.Response{StatusCode: 401}, Error: true},
{Response: &http.Response{StatusCode: http.StatusInternalServerError}, Error: true},
{Response: &http.Response{StatusCode: http.StatusUnprocessableEntity}, Error: true},
{Response: &http.Response{StatusCode: http.StatusConflict}, Error: true},
{Response: &http.Response{StatusCode: http.StatusNotFound}, Error: true},
{Response: &http.Response{StatusCode: http.StatusUnauthorized}, Error: true},
{
Response: &http.Response{
StatusCode: 401,
StatusCode: http.StatusUnauthorized,
Header: http.Header{"Content-Type": []string{"application/json"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -536,7 +536,7 @@ func TestTransformResponse(t *testing.T) {
},
{
Response: &http.Response{
StatusCode: 401,
StatusCode: http.StatusUnauthorized,
Header: http.Header{"Content-Type": []string{"text/any"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -545,9 +545,9 @@ func TestTransformResponse(t *testing.T) {
return strings.Contains(err.Error(), "server has asked for the client to provide") && apierrors.IsUnauthorized(err)
},
},
{Response: &http.Response{StatusCode: 403}, Error: true},
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
{Response: &http.Response{StatusCode: http.StatusForbidden}, Error: true},
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
}
for i, test := range testCases {
r := NewRequest(nil, "", uri, "", defaultContentConfig(), defaultSerializers(t), nil, nil, 0)
@@ -615,7 +615,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
{
ContentType: "application/json",
Response: &http.Response{
StatusCode: 401,
StatusCode: http.StatusUnauthorized,
Header: http.Header{"Content-Type": []string{"application/json"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -627,7 +627,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
{
ContentType: "application/json",
Response: &http.Response{
StatusCode: 401,
StatusCode: http.StatusUnauthorized,
Header: http.Header{"Content-Type": []string{"application/protobuf"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -644,7 +644,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
{
ContentType: "application/json",
Response: &http.Response{
StatusCode: 500,
StatusCode: http.StatusInternalServerError,
Header: http.Header{"Content-Type": []string{"application/,others"}},
},
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
@@ -657,7 +657,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
{
// no negotiation when no content type specified
Response: &http.Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Header: http.Header{"Content-Type": []string{"text/any"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -667,7 +667,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
// no negotiation when no response content type specified
ContentType: "text/any",
Response: &http.Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
@@ -676,7 +676,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
// unrecognized content type is not handled
ContentType: "application/json",
Response: &http.Response{
StatusCode: 404,
StatusCode: http.StatusNotFound,
Header: http.Header{"Content-Type": []string{"application/unrecognized"}},
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
},
@@ -1178,7 +1178,7 @@ func (f *fakeUpgradeRoundTripper) RoundTrip(req *http.Request) (*http.Response,
b := []byte{}
body := ioutil.NopCloser(bytes.NewReader(b))
resp := &http.Response{
StatusCode: 101,
StatusCode: http.StatusSwitchingProtocols,
Body: body,
}
return resp, nil
@@ -1367,7 +1367,7 @@ func TestConnectionResetByPeerIsRetried(t *testing.T) {
count++
if count >= 3 {
return &http.Response{
StatusCode: 200,
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
}, nil
}

View File

@@ -180,7 +180,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
if err != nil {
return nil, err
}
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
case "PUT":
decoder := codecs.UniversalDeserializer()
body, err := ioutil.ReadAll(req.Body)
@@ -198,7 +198,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
if err != nil {
return nil, err
}
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
case "PATCH":
body, err := ioutil.ReadAll(req.Body)
if err != nil {
@@ -229,7 +229,7 @@ func fakeScaleClient(t *testing.T) (ScalesGetter, []schema.GroupResource) {
default:
return nil, fmt.Errorf("invalid patch type")
}
return &http.Response{StatusCode: 200, Header: defaultHeaders(), Body: bytesBody(res)}, nil
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeaders(), Body: bytesBody(res)}, nil
default:
return nil, fmt.Errorf("unexpected request for URL %q with method %q", req.URL.String(), req.Method)
}