Permalink
Browse files

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

kubectl version should print just client information in the absence of kubeconfig
  • Loading branch information...
k8s-ci-robot committed Nov 7, 2018
2 parents 7e097cf + 4efb020 commit 1f56cd801e795fd063ec3e61fe4f6fa8841f4222
Showing with 6 additions and 2 deletions.
  1. +1 −0 pkg/kubectl/cmd/version/BUILD
  2. +5 −2 pkg/kubectl/cmd/version/version.go
@@ -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()

0 comments on commit 1f56cd8

Please sign in to comment.