update StatusDetails to handle Groups
This commit is contained in:
@@ -93,30 +93,32 @@ 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(kind, name string) error {
|
||||
func NewNotFound(qualifiedResource unversioned.GroupResource, name string) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusNotFound,
|
||||
Reason: unversioned.StatusReasonNotFound,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: name,
|
||||
},
|
||||
Message: fmt.Sprintf("%s %q not found", kind, name),
|
||||
Message: fmt.Sprintf("%s %q not found", qualifiedResource.String(), name),
|
||||
}}
|
||||
}
|
||||
|
||||
// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
|
||||
func NewAlreadyExists(kind, name string) error {
|
||||
func NewAlreadyExists(qualifiedResource unversioned.GroupResource, name string) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
Reason: unversioned.StatusReasonAlreadyExists,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: name,
|
||||
},
|
||||
Message: fmt.Sprintf("%s %q already exists", kind, name),
|
||||
Message: fmt.Sprintf("%s %q already exists", qualifiedResource.String(), name),
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -136,30 +138,32 @@ func NewUnauthorized(reason string) error {
|
||||
}
|
||||
|
||||
// NewForbidden returns an error indicating the requested action was forbidden
|
||||
func NewForbidden(kind, name string, err error) error {
|
||||
func NewForbidden(qualifiedResource unversioned.GroupResource, name string, err error) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusForbidden,
|
||||
Reason: unversioned.StatusReasonForbidden,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: name,
|
||||
},
|
||||
Message: fmt.Sprintf("%s %q is forbidden: %v", kind, name, err),
|
||||
Message: fmt.Sprintf("%s %q is forbidden: %v", qualifiedResource.String(), name, err),
|
||||
}}
|
||||
}
|
||||
|
||||
// NewConflict returns an error indicating the item can't be updated as provided.
|
||||
func NewConflict(kind, name string, err error) error {
|
||||
func NewConflict(qualifiedResource unversioned.GroupResource, name string, err error) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusConflict,
|
||||
Reason: unversioned.StatusReasonConflict,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: name,
|
||||
},
|
||||
Message: fmt.Sprintf("%s %q cannot be updated: %v", kind, name, err),
|
||||
Message: fmt.Sprintf("%s %q cannot be updated: %v", qualifiedResource.String(), name, err),
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -174,7 +178,7 @@ func NewGone(message string) error {
|
||||
}
|
||||
|
||||
// NewInvalid returns an error indicating the item is invalid and cannot be processed.
|
||||
func NewInvalid(kind, name string, errs field.ErrorList) error {
|
||||
func NewInvalid(qualifiedKind unversioned.GroupKind, name string, errs field.ErrorList) error {
|
||||
causes := make([]unversioned.StatusCause, 0, len(errs))
|
||||
for i := range errs {
|
||||
err := errs[i]
|
||||
@@ -189,11 +193,12 @@ func NewInvalid(kind, name string, errs field.ErrorList) error {
|
||||
Code: StatusUnprocessableEntity, // RFC 4918: StatusUnprocessableEntity
|
||||
Reason: unversioned.StatusReasonInvalid,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Group: qualifiedKind.Group,
|
||||
Kind: qualifiedKind.Kind,
|
||||
Name: name,
|
||||
Causes: causes,
|
||||
},
|
||||
Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errs.ToAggregate()),
|
||||
Message: fmt.Sprintf("%s %q is invalid: %v", qualifiedKind.String(), name, errs.ToAggregate()),
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -218,34 +223,42 @@ func NewServiceUnavailable(reason string) error {
|
||||
}
|
||||
|
||||
// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
|
||||
func NewMethodNotSupported(kind, action string) error {
|
||||
func NewMethodNotSupported(qualifiedResource unversioned.GroupResource, action string) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusMethodNotAllowed,
|
||||
Reason: unversioned.StatusReasonMethodNotAllowed,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
},
|
||||
Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, kind),
|
||||
Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, qualifiedResource.String()),
|
||||
}}
|
||||
}
|
||||
|
||||
// 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(kind, operation string, retryAfterSeconds int) error {
|
||||
func NewServerTimeout(qualifiedResource unversioned.GroupResource, operation string, retryAfterSeconds int) error {
|
||||
return &StatusError{unversioned.Status{
|
||||
Status: unversioned.StatusFailure,
|
||||
Code: http.StatusInternalServerError,
|
||||
Reason: unversioned.StatusReasonServerTimeout,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: operation,
|
||||
RetryAfterSeconds: int32(retryAfterSeconds),
|
||||
},
|
||||
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, kind),
|
||||
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, qualifiedResource.String()),
|
||||
}}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
return &StatusError{unversioned.Status{
|
||||
@@ -274,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, kind, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
|
||||
func NewGenericServerResponse(code int, verb string, qualifiedResource unversioned.GroupResource, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
|
||||
reason := unversioned.StatusReasonUnknown
|
||||
message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
|
||||
switch code {
|
||||
@@ -316,10 +329,10 @@ func NewGenericServerResponse(code int, verb, kind, name, serverMessage string,
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case len(kind) > 0 && len(name) > 0:
|
||||
message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), kind, name)
|
||||
case len(kind) > 0:
|
||||
message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), kind)
|
||||
case !qualifiedResource.IsEmpty() && len(name) > 0:
|
||||
message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), qualifiedResource.String(), name)
|
||||
case !qualifiedResource.IsEmpty():
|
||||
message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), qualifiedResource.String())
|
||||
}
|
||||
var causes []unversioned.StatusCause
|
||||
if isUnexpectedResponse {
|
||||
@@ -337,8 +350,9 @@ func NewGenericServerResponse(code int, verb, kind, name, serverMessage string,
|
||||
Code: int32(code),
|
||||
Reason: reason,
|
||||
Details: &unversioned.StatusDetails{
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
Group: qualifiedResource.Group,
|
||||
Kind: qualifiedResource.Resource,
|
||||
Name: name,
|
||||
|
||||
Causes: causes,
|
||||
RetryAfterSeconds: int32(retryAfterSeconds),
|
||||
|
||||
Reference in New Issue
Block a user