Merge pull request #89913 from zhouya0/fix_kubectl_version_should_print_version_info

Fix kubectl version should print version info without config file

Kubernetes-commit: db999c96343c10e83d72ff4bb82e775f09edf0a6
This commit is contained in:
Kubernetes Publisher 2020-04-15 09:24:03 -07:00
commit 4529075edf
4 changed files with 29 additions and 11 deletions

4
Godeps/Godeps.json generated
View File

@ -348,11 +348,11 @@
}, },
{ {
"ImportPath": "k8s.io/api", "ImportPath": "k8s.io/api",
"Rev": "5778e4f3d00d" "Rev": "2433a9db3db3"
}, },
{ {
"ImportPath": "k8s.io/apimachinery", "ImportPath": "k8s.io/apimachinery",
"Rev": "e002472249f8" "Rev": "06deae5c9c2c"
}, },
{ {
"ImportPath": "k8s.io/gengo", "ImportPath": "k8s.io/gengo",

8
go.mod
View File

@ -28,8 +28,8 @@ require (
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 golang.org/x/time v0.0.0-20191024005414-555d28b269f0
google.golang.org/appengine v1.5.0 // indirect google.golang.org/appengine v1.5.0 // indirect
k8s.io/api v0.0.0-20200410021914-5778e4f3d00d k8s.io/api v0.0.0-20200414061335-2433a9db3db3
k8s.io/apimachinery v0.0.0-20200410061239-e002472249f8 k8s.io/apimachinery v0.0.0-20200413181316-06deae5c9c2c
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
sigs.k8s.io/yaml v1.2.0 sigs.k8s.io/yaml v1.2.0
@ -38,6 +38,6 @@ require (
replace ( replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13 golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => k8s.io/api v0.0.0-20200410021914-5778e4f3d00d k8s.io/api => k8s.io/api v0.0.0-20200414061335-2433a9db3db3
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200410061239-e002472249f8 k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200413181316-06deae5c9c2c
) )

4
go.sum
View File

@ -189,8 +189,8 @@ gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20200410021914-5778e4f3d00d/go.mod h1:kNZHsfUjF+wX4CfMBMSHs4FliofoB7PN0ILSMBbxyYc= k8s.io/api v0.0.0-20200414061335-2433a9db3db3/go.mod h1:S9B4jsMc6M3MS++oeNW7L3ZGLfPUaKMbO/PUWQcC+gU=
k8s.io/apimachinery v0.0.0-20200410061239-e002472249f8/go.mod h1:imoz42hIYwpLTRWXU8pdJ9IE8DbxUsnU9lyVN8Y1SNo= k8s.io/apimachinery v0.0.0-20200413181316-06deae5c9c2c/go.mod h1:imoz42hIYwpLTRWXU8pdJ9IE8DbxUsnU9lyVN8Y1SNo=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=

View File

@ -30,11 +30,24 @@ import (
var ( var (
ErrNoContext = errors.New("no context chosen") ErrNoContext = errors.New("no context chosen")
ErrEmptyConfig = errors.New("no configuration has been provided, try setting KUBERNETES_MASTER environment variable") ErrEmptyConfig = NewEmptyConfigError("no configuration has been provided, try setting KUBERNETES_MASTER environment variable")
// message is for consistency with old behavior // message is for consistency with old behavior
ErrEmptyCluster = errors.New("cluster has no server defined") ErrEmptyCluster = errors.New("cluster has no server defined")
) )
// NewEmptyConfigError returns an error wrapping the given message which IsEmptyConfig() will recognize as an empty config error
func NewEmptyConfigError(message string) error {
return &errEmptyConfig{message}
}
type errEmptyConfig struct {
message string
}
func (e *errEmptyConfig) Error() string {
return e.message
}
type errContextNotFound struct { type errContextNotFound struct {
ContextName string ContextName string
} }
@ -60,9 +73,14 @@ func IsContextNotFound(err error) bool {
func IsEmptyConfig(err error) bool { func IsEmptyConfig(err error) bool {
switch t := err.(type) { switch t := err.(type) {
case errConfigurationInvalid: case errConfigurationInvalid:
return len(t) == 1 && t[0] == ErrEmptyConfig if len(t) != 1 {
return false
} }
return err == ErrEmptyConfig _, ok := t[0].(*errEmptyConfig)
return ok
}
_, ok := err.(*errEmptyConfig)
return ok
} }
// errConfigurationInvalid is a set of errors indicating the configuration is invalid. // errConfigurationInvalid is a set of errors indicating the configuration is invalid.