Commit 4efb0208 authored by David Eads's avatar David Eads

kubectl version should print just client information in the absence of kubeconfig

parent 8dcdec0a
......@@ -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",
],
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment