Skip to content
Permalink
Browse files

kubectl: kubectl version better error message

  • Loading branch information...
prksu committed Jan 9, 2019
1 parent e6413d2 commit da0f10c4e62e984602c706b8fd9ac524d42d4e88
Showing with 14 additions and 1 deletion.
  1. +3 −0 pkg/kubectl/cmd/util/helpers.go
  2. +11 −1 staging/src/k8s.io/client-go/discovery/discovery_client.go
@@ -40,6 +40,7 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions/resource"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/scale"
@@ -155,6 +156,8 @@ func checkErr(err error, handleErr func(string, int)) {
default:
handleErr(fmt.Sprintf("the server doesn't have a resource type %q", err.PartialResource.Resource), DefaultErrorExitCode)
}
case *discovery.ErrParseServerVersionFailed:
handleErr(fmt.Sprintf("error retrieving server version: %s", err.Error()), DefaultErrorExitCode)
case utilerrors.Aggregate:
handleErr(MultipleErrors(``, err.Errors()), DefaultErrorExitCode)
case utilexec.ExitError:
@@ -372,6 +372,16 @@ func ServerPreferredNamespacedResources(d DiscoveryInterface) ([]*metav1.APIReso
}), all), err
}

// ErrParseServerVersionFailed is returned by ServerVersion function when failed parses the server's version.
type ErrParseServerVersionFailed struct {
//Err is returned by the ServerVersion function
Err error
}

func (e *ErrParseServerVersionFailed) Error() string {
return fmt.Sprintf("unable to parse the server version: %s", e.Err.Error())
}

// ServerVersion retrieves and parses the server's version (git version).
func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
body, err := d.restClient.Get().AbsPath("/version").Do().Raw()
@@ -381,7 +391,7 @@ func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
var info version.Info
err = json.Unmarshal(body, &info)
if err != nil {
return nil, fmt.Errorf("got '%s': %v", string(body), err)
return nil, &ErrParseServerVersionFailed{Err: err}
}
return &info, nil
}

0 comments on commit da0f10c

Please sign in to comment.
You can’t perform that action at this time.