Fix kubectl version --client=true

Getting the client version fails if the kubeconfig is invalid:

 $ kubectl version --client=true
 Error in configuration:
 * unable to read client-cert .../client.crt: no such file or directory
 * unable to read client-key .../client.key: no such file or directory
 * unable to read certificate-authority .../ca.crt: no such file or directory

Update to match behaviour on v1.10.13 and earlier:

 $ kubectl version --client=true
 Client Version: version.Info{Major:"1", ...}
k3s-v1.15.3
Stuart McLaren 2019-04-16 18:29:22 +01:00
parent 440d086268
commit d4ee919fb5
1 changed files with 3 additions and 0 deletions

View File

@ -88,6 +88,9 @@ func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *co
// Complete completes all the required options // Complete completes all the required options
func (o *Options) Complete(f cmdutil.Factory, cmd *cobra.Command) error { func (o *Options) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
var err error var err error
if o.ClientOnly {
return nil
}
o.discoveryClient, err = f.ToDiscoveryClient() o.discoveryClient, err = f.ToDiscoveryClient()
// if we had an empty rest.Config, continue and just print out client information. // 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 we had an error other than being unable to build a rest.Config, fail.