Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove APIStatus from the client #17991

Merged
merged 1 commit into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type StatusError struct {
ErrStatus unversioned.Status
}

// APIStatus is exposed by errors that can be converted to an api.Status object
// for finer grained details.
type APIStatus interface {
Status() unversioned.Status
}

var _ error = &StatusError{}

// Error implements the Error interface.
Expand Down Expand Up @@ -394,7 +400,7 @@ func IsServerTimeout(err error) bool {
// and may be the result of another HTTP actor.
func IsUnexpectedServerError(err error) bool {
switch t := err.(type) {
case *StatusError:
case APIStatus:
if d := t.Status().Details; d != nil {
for _, cause := range d.Causes {
if cause.Type == unversioned.CauseTypeUnexpectedServerResponse {
Expand All @@ -416,7 +422,7 @@ func IsUnexpectedObjectError(err error) bool {
// suggested seconds to wait, or false if the error does not imply a wait.
func SuggestsClientDelay(err error) (int, bool) {
switch t := err.(type) {
case *StatusError:
case APIStatus:
if t.Status().Details != nil {
switch t.Status().Reason {
case unversioned.StatusReasonServerTimeout, unversioned.StatusReasonTimeout:
Expand All @@ -429,8 +435,8 @@ func SuggestsClientDelay(err error) (int, bool) {

func reasonForError(err error) unversioned.StatusReason {
switch t := err.(type) {
case *StatusError:
return t.ErrStatus.Reason
case APIStatus:
return t.Status().Reason
}
return unversioned.StatusReasonUnknown
}
6 changes: 0 additions & 6 deletions pkg/client/unversioned/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ type VersionInterface interface {
ServerAPIVersions() (*unversioned.APIVersions, error)
}

// APIStatus is exposed by errors that can be converted to an api.Status object
// for finer grained details.
type APIStatus interface {
Status() unversioned.Status
}

// Client is the implementation of a Kubernetes client.
type Client struct {
*RESTClient
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func (r *Request) Stream() (io.ReadCloser, error) {
if runtimeObject, err := r.codec.Decode(bodyBytes); err == nil {
statusError := errors.FromObject(runtimeObject)

if _, ok := statusError.(APIStatus); ok {
if _, ok := statusError.(errors.APIStatus); ok {
return nil, statusError
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestTransformResponse(t *testing.T) {
if hasErr != test.Error {
t.Errorf("%d: unexpected error: %t %v", i, test.Error, err)
} else if hasErr && test.Response.StatusCode > 399 {
status, ok := err.(APIStatus)
status, ok := err.(apierrors.APIStatus)
if !ok {
t.Errorf("%d: response should have been transformable into APIStatus: %v", i, err)
continue
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/unversioned/restclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"
"testing"

"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/util"
Expand Down Expand Up @@ -92,7 +93,7 @@ func TestDoRequestFailed(t *testing.T) {
if err == nil || body != nil {
t.Errorf("unexpected non-error: %#v", body)
}
ss, ok := err.(APIStatus)
ss, ok := err.(errors.APIStatus)
if !ok {
t.Errorf("unexpected error type %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubectl/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/editor"
Expand Down Expand Up @@ -370,7 +369,7 @@ func (r *editResults) addError(err error, info *resource.Info) string {
reason := editReason{
head: fmt.Sprintf("%s %s was not valid", info.Mapping.Kind, info.Name),
}
if err, ok := err.(client.APIStatus); ok {
if err, ok := err.(errors.APIStatus); ok {
if details := err.Status().Details; details != nil {
for _, cause := range details.Causes {
reason.other = append(reason.other, cause.Message)
Expand Down
5 changes: 2 additions & 3 deletions pkg/kubectl/cmd/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/resource"
Expand All @@ -57,7 +56,7 @@ type debugError interface {
// souce is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource.
func AddSourceToErr(verb string, source string, err error) error {
if source != "" {
if statusError, ok := err.(*errors.StatusError); ok {
if statusError, ok := err.(errors.APIStatus); ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is still inconsistent with line 108 of this file, but it was like that before.

status := statusError.Status()
status.Message = fmt.Sprintf("error when %s %q: %v", verb, source, status.Message)
return &errors.StatusError{ErrStatus: status}
Expand Down Expand Up @@ -145,7 +144,7 @@ func StandardErrorMessage(err error) (string, bool) {
if debugErr, ok := err.(debugError); ok {
glog.V(4).Infof(debugErr.DebugError())
}
_, isStatus := err.(client.APIStatus)
_, isStatus := err.(errors.APIStatus)
switch {
case isStatus:
return fmt.Sprintf("Error from server: %s", err.Error()), true
Expand Down