mirror of https://github.com/k3s-io/k3s
Merge pull request #70713 from deads2k/kubectl-15-wait
kubectl version should print just client information in the absence of kubeconfigpull/58/head
commit
1f56cd801e
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue