mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Allow StatusErrors to be modified after creation
This commit is contained in:
parent
f204a9f399
commit
e5fbf86157
@ -93,7 +93,7 @@ func FromObject(obj runtime.Object) error {
|
||||
}
|
||||
|
||||
// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
|
||||
func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error {
|
||||
func NewNotFound(qualifiedResource unversioned.GroupResource, name string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusNotFound,
|
||||
@ -108,7 +108,7 @@ func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error
|
||||
}
|
||||
|
||||
// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
|
||||
func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string) error {
|
||||
func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
@ -124,7 +124,7 @@ func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string)
|
||||
|
||||
// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
|
||||
// action.
|
||||
func NewUnauthorized(reason string) error {
|
||||
func NewUnauthorized(reason string) *StatusError {
|
||||
message := reason
|
||||
if len(message) == 0 {
|
||||
message = "not authorized"
|
||||
@ -138,7 +138,7 @@ func NewUnauthorized(reason string) error {
|
||||
}
|
||||
|
||||
// NewForbidden returns an error indicating the requested action was forbidden
|
||||
func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err error) error {
|
||||
func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err error) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusForbidden,
|
||||
@ -153,7 +153,7 @@ func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err
|
||||
}
|
||||
|
||||
// NewConflict returns an error indicating the item can't be updated as provided.
|
||||
func NewConflict(qualifiedResource unversioned.GroupResource, name string, err error) error {
|
||||
func NewConflict(qualifiedResource unversioned.GroupResource, name string, err error) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
@ -168,7 +168,7 @@ func NewConflict(qualifiedResource unversioned.GroupResource, name string, err e
|
||||
}
|
||||
|
||||
// NewGone returns an error indicating the item no longer available at the server and no forwarding address is known.
|
||||
func NewGone(message string) error {
|
||||
func NewGone(message string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusGone,
|
||||
@ -178,7 +178,7 @@ func NewGone(message string) error {
|
||||
}
|
||||
|
||||
// NewInvalid returns an error indicating the item is invalid and cannot be processed.
|
||||
func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.ErrorList) error {
|
||||
func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.ErrorList) *StatusError {
|
||||
causes := make([]unversioned.StatusCause, 0, len(errs))
|
||||
for i := range errs {
|
||||
err := errs[i]
|
||||
@ -203,7 +203,7 @@ func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.Err
|
||||
}
|
||||
|
||||
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
|
||||
func NewBadRequest(reason string) error {
|
||||
func NewBadRequest(reason string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusBadRequest,
|
||||
@ -213,7 +213,7 @@ func NewBadRequest(reason string) error {
|
||||
}
|
||||
|
||||
// NewServiceUnavailable creates an error that indicates that the requested service is unavailable.
|
||||
func NewServiceUnavailable(reason string) error {
|
||||
func NewServiceUnavailable(reason string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusServiceUnavailable,
|
||||
@ -223,7 +223,7 @@ func NewServiceUnavailable(reason string) error {
|
||||
}
|
||||
|
||||
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
|
||||
func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action string) error {
|
||||
func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action string) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusMethodNotAllowed,
|
||||
@ -238,7 +238,7 @@ func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action s
|
||||
|
||||
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
|
||||
// transient error, and the client should try again.
|
||||
func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation string, retryAfterSeconds int) error {
|
||||
func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation string, retryAfterSeconds int) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusInternalServerError,
|
||||
@ -255,12 +255,12 @@ func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation str
|
||||
|
||||
// NewServerTimeoutForKind should not exist. Server timeouts happen when accessing resources, the Kind is just what we
|
||||
// happened to be looking at when the request failed. This delegates to keep code sane, but we should work towards removing this.
|
||||
func NewServerTimeoutForKind(qualifiedKind unversioned.GroupKind, operation string, retryAfterSeconds int) error {
|
||||
func NewServerTimeoutForKind(qualifiedKind unversioned.GroupKind, operation string, retryAfterSeconds int) *StatusError {
|
||||
return NewServerTimeout(unversioned.GroupResource{Group: qualifiedKind.Group, Resource: qualifiedKind.Kind}, operation, retryAfterSeconds)
|
||||
}
|
||||
|
||||
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
|
||||
func NewInternalError(err error) error {
|
||||
func NewInternalError(err error) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusInternalServerError,
|
||||
@ -274,7 +274,7 @@ func NewInternalError(err error) error {
|
||||
|
||||
// NewTimeoutError returns an error indicating that a timeout occurred before the request
|
||||
// could be completed. Clients may retry, but the operation may still complete.
|
||||
func NewTimeoutError(message string, retryAfterSeconds int) error {
|
||||
func NewTimeoutError(message string, retryAfterSeconds int) *StatusError {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: StatusServerTimeout,
|
||||
@ -287,7 +287,7 @@ func NewTimeoutError(message string, retryAfterSeconds int) error {
|
||||
}
|
||||
|
||||
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
|
||||
func NewGenericServerResponse(code int, verb string, qualifiedResource unversioned.GroupResource, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
|
||||
func NewGenericServerResponse(code int, verb string, qualifiedResource unversioned.GroupResource, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) *StatusError {
|
||||
reason := unversioned.StatusReasonUnknown
|
||||
message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
|
||||
switch code {
|
||||
|
@ -152,7 +152,7 @@ func TestNewInvalid(t *testing.T) {
|
||||
vErr, expected := testCase.Err, testCase.Details
|
||||
expected.Causes[0].Message = vErr.ErrorBody()
|
||||
err := NewInvalid(api.Kind("Kind"), "name", field.ErrorList{vErr})
|
||||
status := err.(*StatusError).ErrStatus
|
||||
status := err.ErrStatus
|
||||
if status.Code != 422 || status.Reason != unversioned.StatusReasonInvalid {
|
||||
t.Errorf("%d: unexpected status: %#v", i, status)
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ func TestErrors(t *testing.T) {
|
||||
o.Add(&api.List{
|
||||
Items: []runtime.Object{
|
||||
// This first call to List will return this error
|
||||
&(errors.NewNotFound(api.Resource("ServiceList"), "").(*errors.StatusError).ErrStatus),
|
||||
&(errors.NewNotFound(api.Resource("ServiceList"), "").ErrStatus),
|
||||
// The second call to List will return this error
|
||||
&(errors.NewForbidden(api.Resource("ServiceList"), "", nil).(*errors.StatusError).ErrStatus),
|
||||
&(errors.NewForbidden(api.Resource("ServiceList"), "", nil).ErrStatus),
|
||||
},
|
||||
})
|
||||
client := &Fake{}
|
||||
|
@ -192,7 +192,7 @@ func TestDeleteAllNotFound(t *testing.T) {
|
||||
|
||||
// Add an item to the list which will result in a 404 on delete
|
||||
svc.Items = append(svc.Items, api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").(*errors.StatusError).ErrStatus
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
|
||||
|
||||
tf.Printer = &testPrinter{}
|
||||
tf.Client = &fake.RESTClient{
|
||||
@ -234,7 +234,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
|
||||
|
||||
// Add an item to the list which will result in a 404 on delete
|
||||
svc.Items = append(svc.Items, api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").(*errors.StatusError).ErrStatus
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
|
||||
|
||||
tf.Printer = &testPrinter{}
|
||||
tf.Client = &fake.RESTClient{
|
||||
|
@ -239,7 +239,7 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
defer tooOldWatcher.Stop()
|
||||
// Ensure we get a "Gone" error
|
||||
expectedGoneError := errors.NewGone("").(*errors.StatusError).ErrStatus
|
||||
expectedGoneError := errors.NewGone("").ErrStatus
|
||||
verifyWatchEvent(t, tooOldWatcher, watch.Error, &expectedGoneError)
|
||||
|
||||
initialWatcher, err := cacher.Watch(context.TODO(), "pods/ns/foo", fooCreated.ResourceVersion, storage.Everything)
|
||||
|
Loading…
Reference in New Issue
Block a user