Merge pull request #70713 from deads2k/kubectl-15-wait

kubectl version should print just client information in the absence of kubeconfig
pull/58/head
k8s-ci-robot 2018-11-07 09:06:18 -08:00 committed by GitHub
commit 1f56cd801e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -13,6 +13,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/version:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
"//staging/src/k8s.io/client-go/discovery:go_default_library",
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
],

View File

@ -27,6 +27,7 @@ import (
apimachineryversion "k8s.io/apimachinery/pkg/version"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/discovery"
"k8s.io/client-go/tools/clientcmd"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/templates"
@ -83,7 +84,9 @@ func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *co
func (o *VersionOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
var err error
o.discoveryClient, err = f.ToDiscoveryClient()
if err != nil {
// if we had an empty rest.Config, continue and just print out client information.
// if we had an error other than being unable to build a rest.Config, fail.
if err != nil && !clientcmd.IsEmptyConfig(err) {
return err
}
return nil
@ -107,7 +110,7 @@ func (o *VersionOptions) Run() error {
clientVersion := version.Get()
versionInfo.ClientVersion = &clientVersion
if !o.ClientOnly {
if !o.ClientOnly && o.discoveryClient != nil {
// Always request fresh data from the server
o.discoveryClient.Invalidate()
serverVersion, serverErr = o.discoveryClient.ServerVersion()