diff --git a/pkg/api/errors/errors.go b/pkg/api/errors/errors.go index 6507ed8082c..403beecf502 100644 --- a/pkg/api/errors/errors.go +++ b/pkg/api/errors/errors.go @@ -30,11 +30,11 @@ const ( StatusUnprocessableEntity = 422 StatusTooManyRequests = 429 // HTTP recommendations are for servers to define 5xx error codes - // for scenarios not covered by behavior. In this case, TryAgainLater + // for scenarios not covered by behavior. In this case, ServerTimeout // is an indication that a transient server error has occured and the // client *should* retry, with an optional Retry-After header to specify // the back off window. - StatusTryAgainLater = 504 + StatusServerTimeout = 504 ) // StatusError is an error intended for consumption by a REST API server; it can also be @@ -180,13 +180,13 @@ func NewMethodNotSupported(kind, action string) error { }} } -// NewTryAgainLater returns an error indicating the requested action could not be completed due to a +// NewServerTimeout returns an error indicating the requested action could not be completed due to a // transient error, and the client should try again. -func NewTryAgainLater(kind, operation string) error { +func NewServerTimeout(kind, operation string) error { return &StatusError{api.Status{ Status: api.StatusFailure, Code: http.StatusInternalServerError, - Reason: api.StatusReasonTryAgainLater, + Reason: api.StatusReasonServerTimeout, Details: &api.StatusDetails{ Kind: kind, ID: operation, @@ -213,7 +213,7 @@ func NewInternalError(err error) error { func NewTimeoutError(message string) error { return &StatusError{api.Status{ Status: api.StatusFailure, - Code: StatusTryAgainLater, + Code: StatusServerTimeout, Reason: api.StatusReasonTimeout, Message: fmt.Sprintf("Timeout: %s", message), }} @@ -256,10 +256,10 @@ func IsForbidden(err error) bool { return reasonForError(err) == api.StatusReasonForbidden } -// IsTryAgainLater determines if err is an error which indicates that the request needs to be retried +// IsServerTimeout determines if err is an error which indicates that the request needs to be retried // by the client. -func IsTryAgainLater(err error) bool { - return reasonForError(err) == api.StatusReasonTryAgainLater +func IsServerTimeout(err error) bool { + return reasonForError(err) == api.StatusReasonServerTimeout } func reasonForError(err error) api.StatusReason { diff --git a/pkg/api/errors/errors_test.go b/pkg/api/errors/errors_test.go index a46583e25eb..ae57f38818c 100644 --- a/pkg/api/errors/errors_test.go +++ b/pkg/api/errors/errors_test.go @@ -46,8 +46,8 @@ func TestErrorNew(t *testing.T) { if IsForbidden(err) { t.Errorf("expected to not be %s", api.StatusReasonForbidden) } - if IsTryAgainLater(err) { - t.Errorf("expected to not be %s", api.StatusReasonTryAgainLater) + if IsServerTimeout(err) { + t.Errorf("expected to not be %s", api.StatusReasonServerTimeout) } if IsMethodNotSupported(err) { t.Errorf("expected to not be %s", api.StatusReasonMethodNotAllowed) @@ -68,8 +68,8 @@ func TestErrorNew(t *testing.T) { if !IsForbidden(NewForbidden("test", "2", errors.New("reason"))) { t.Errorf("expected to be %s", api.StatusReasonForbidden) } - if !IsTryAgainLater(NewTryAgainLater("test", "reason")) { - t.Errorf("expected to be %s", api.StatusReasonTryAgainLater) + if !IsServerTimeout(NewServerTimeout("test", "reason")) { + t.Errorf("expected to be %s", api.StatusReasonServerTimeout) } if !IsMethodNotSupported(NewMethodNotSupported("foo", "delete")) { t.Errorf("expected to be %s", api.StatusReasonMethodNotAllowed) diff --git a/pkg/api/rest/create.go b/pkg/api/rest/create.go index 36b931b95c5..c74c9a60d5f 100644 --- a/pkg/api/rest/create.go +++ b/pkg/api/rest/create.go @@ -83,7 +83,7 @@ func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime return err } - return errors.NewTryAgainLater(kind, "POST") + return errors.NewServerTimeout(kind, "POST") } // objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error. diff --git a/pkg/api/rest/create_test.go b/pkg/api/rest/create_test.go index c8ad1490225..695f8cd746a 100644 --- a/pkg/api/rest/create_test.go +++ b/pkg/api/rest/create_test.go @@ -35,7 +35,7 @@ func TestCheckGeneratedNameError(t *testing.T) { } expect = errors.NewAlreadyExists("foo", "bar") - if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsTryAgainLater(err) { + if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsServerTimeout(err) { t.Errorf("expected try again later error: %v", err) } } diff --git a/pkg/api/rest/resttest/resttest.go b/pkg/api/rest/resttest/resttest.go index a5bceff4fd6..1b83ef5cd8a 100644 --- a/pkg/api/rest/resttest/resttest.go +++ b/pkg/api/rest/resttest/resttest.go @@ -66,7 +66,7 @@ func copyOrDie(obj runtime.Object) runtime.Object { func (t *Tester) TestCreate(valid runtime.Object, invalid ...runtime.Object) { t.TestCreateHasMetadata(copyOrDie(valid)) t.TestCreateGeneratesName(copyOrDie(valid)) - t.TestCreateGeneratesNameReturnsTryAgain(copyOrDie(valid)) + t.TestCreateGeneratesNameReturnsServerTimeout(copyOrDie(valid)) if t.clusterScope { t.TestCreateRejectsNamespace(copyOrDie(valid)) } else { @@ -140,7 +140,7 @@ func (t *Tester) TestCreateGeneratesName(valid runtime.Object) { } } -func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) { +func (t *Tester) TestCreateGeneratesNameReturnsServerTimeout(valid runtime.Object) { objectMeta, err := api.ObjectMetaFor(valid) if err != nil { t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid) @@ -149,7 +149,7 @@ func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) { objectMeta.GenerateName = "test-" t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() { _, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid) - if err == nil || !errors.IsTryAgainLater(err) { + if err == nil || !errors.IsServerTimeout(err) { t.Fatalf("Unexpected error: %v", err) } }) diff --git a/pkg/api/types.go b/pkg/api/types.go index e841d4b8301..f70d8796f3a 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -91,7 +91,7 @@ type ObjectMeta struct { // // If this field is specified, and Name is not present, the server will NOT return a 409 if the // generated name exists - instead, it will either return 201 Created or 500 with Reason - // TryAgainLater indicating a unique name could not be found in the time allotted, and the client + // ServerTimeout indicating a unique name could not be found in the time allotted, and the client // should retry (optionally after the time indicated in the Retry-After header). GenerateName string `json:"generateName,omitempty"` @@ -999,7 +999,7 @@ const ( // Status code 422 StatusReasonInvalid StatusReason = "Invalid" - // StatusReasonTryAgainLater means the server can be reached and understood the request, + // StatusReasonServerTimeout means the server can be reached and understood the request, // but cannot complete the action in a reasonable time. The client should retry the request. // This is may be due to temporary server load or a transient communication issue with // another server. Status code 500 is used because the HTTP spec provides no suitable @@ -1008,7 +1008,7 @@ const ( // "kind" string - the kind attribute of the resource being acted on. // "id" string - the operation that is being attempted. // Status code 500 - StatusReasonTryAgainLater StatusReason = "TryAgainLater" + StatusReasonServerTimeout StatusReason = "ServerTimeout" // StatusReasonTimeout means that the request could not be completed within the given time. // Clients can get this response only when they specified a timeout param in the request. diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index ab6a5651200..330792043db 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -343,7 +343,7 @@ type TypeMeta struct { // // If this field is specified, and Name is not present, the server will NOT return a 409 if the // generated name exists - instead, it will either return 201 Created or 500 with Reason - // TryAgainLater indicating a unique name could not be found in the time allotted, and the client + // ServerTimeout indicating a unique name could not be found in the time allotted, and the client // should retry (optionally after the time indicated in the Retry-After header). GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"` @@ -804,7 +804,7 @@ const ( // Status code 409 StatusReasonConflict StatusReason = "Conflict" - // StatusReasonTryAgainLater means the server can be reached and understood the request, + // StatusReasonServerTimeout means the server can be reached and understood the request, // but cannot complete the action in a reasonable time. The client should retry the request. // This is may be due to temporary server load or a transient communication issue with // another server. Status code 500 is used because the HTTP spec provides no suitable @@ -813,7 +813,7 @@ const ( // "kind" string - the kind attribute of the resource being acted on. // "id" string - the operation that is being attempted. // Status code 500 - StatusReasonTryAgainLater StatusReason = "TryAgainLater" + StatusReasonServerTimeout StatusReason = "ServerTimeout" ) // StatusCause provides more information about an api.Status failure, including diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 25ac7b3ac52..402ac59f89e 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -307,7 +307,7 @@ type TypeMeta struct { // // If this field is specified, and Name is not present, the server will NOT return a 409 if the // generated name exists - instead, it will either return 201 Created or 500 with Reason - // TryAgainLater indicating a unique name could not be found in the time allotted, and the client + // ServerTimeout indicating a unique name could not be found in the time allotted, and the client // should retry (optionally after the time indicated in the Retry-After header). GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"` @@ -778,7 +778,7 @@ const ( // Status code 422 StatusReasonInvalid StatusReason = "Invalid" - // StatusReasonTryAgainLater means the server can be reached and understood the request, + // StatusReasonServerTimeout means the server can be reached and understood the request, // but cannot complete the action in a reasonable time. The client should retry the request. // This is may be due to temporary server load or a transient communication issue with // another server. Status code 500 is used because the HTTP spec provides no suitable @@ -787,7 +787,7 @@ const ( // "kind" string - the kind attribute of the resource being acted on. // "id" string - the operation that is being attempted. // Status code 500 - StatusReasonTryAgainLater StatusReason = "TryAgainLater" + StatusReasonServerTimeout StatusReason = "ServerTimeout" ) // StatusCause provides more information about an api.Status failure, including diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 844e20d121a..9bd302272f5 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -91,7 +91,7 @@ type ObjectMeta struct { // // If this field is specified, and Name is not present, the server will NOT return a 409 if the // generated name exists - instead, it will either return 201 Created or 500 with Reason - // TryAgainLater indicating a unique name could not be found in the time allotted, and the client + // ServerTimeout indicating a unique name could not be found in the time allotted, and the client // should retry (optionally after the time indicated in the Retry-After header). GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"` @@ -1003,7 +1003,7 @@ const ( // Status code 422 StatusReasonInvalid StatusReason = "Invalid" - // StatusReasonTryAgainLater means the server can be reached and understood the request, + // StatusReasonServerTimeout means the server can be reached and understood the request, // but cannot complete the action in a reasonable time. The client should retry the request. // This is may be due to temporary server load or a transient communication issue with // another server. Status code 500 is used because the HTTP spec provides no suitable @@ -1012,7 +1012,7 @@ const ( // "kind" string - the kind attribute of the resource being acted on. // "id" string - the operation that is being attempted. // Status code 500 - StatusReasonTryAgainLater StatusReason = "TryAgainLater" + StatusReasonServerTimeout StatusReason = "ServerTimeout" ) // StatusCause provides more information about an api.Status failure, including diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index 55be37e4f30..097ec005f4a 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -1147,7 +1147,7 @@ func TestCreateTimeout(t *testing.T) { simple := &Simple{Other: "foo"} data, _ := codec.Encode(simple) - itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusTryAgainLater) + itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusServerTimeout) if itemOut.Status != api.StatusFailure || itemOut.Reason != api.StatusReasonTimeout { t.Errorf("Unexpected status %#v", itemOut) }