From 0417d23a4c0b4f1cc141d9294a90faeab0790695 Mon Sep 17 00:00:00 2001 From: ds-ms Date: Thu, 24 Jan 2019 12:25:08 +0530 Subject: [PATCH] Fix linting issues in pkg/kubectl/cmd/version Signed-off-by: ds-ms --- hack/.golint_failures | 1 - pkg/kubectl/cmd/version/version.go | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/hack/.golint_failures b/hack/.golint_failures index 2614b3fcb1..86db7de86a 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -171,7 +171,6 @@ pkg/kubectl/cmd/testing pkg/kubectl/cmd/top pkg/kubectl/cmd/util pkg/kubectl/cmd/util/openapi -pkg/kubectl/cmd/version pkg/kubectl/cmd/wait pkg/kubectl/describe/versioned pkg/kubectl/generate diff --git a/pkg/kubectl/cmd/version/version.go b/pkg/kubectl/cmd/version/version.go index 1d249e213d..62712660d8 100644 --- a/pkg/kubectl/cmd/version/version.go +++ b/pkg/kubectl/cmd/version/version.go @@ -34,6 +34,7 @@ import ( "k8s.io/kubernetes/pkg/version" ) +// Version is a struct for version information type Version struct { ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"` ServerVersion *apimachineryversion.Info `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"` @@ -45,7 +46,8 @@ var ( kubectl version`)) ) -type VersionOptions struct { +// Options is a struct to support version command +type Options struct { ClientOnly bool Short bool Output string @@ -55,15 +57,17 @@ type VersionOptions struct { genericclioptions.IOStreams } -func NewVersionOptions(ioStreams genericclioptions.IOStreams) *VersionOptions { - return &VersionOptions{ +// NewOptions returns initialized Options +func NewOptions(ioStreams genericclioptions.IOStreams) *Options { + return &Options{ IOStreams: ioStreams, } } +// NewCmdVersion returns a cobra command for fetching versions func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { - o := NewVersionOptions(ioStreams) + o := NewOptions(ioStreams) cmd := &cobra.Command{ Use: "version", Short: i18n.T("Print the client and server version information"), @@ -81,7 +85,8 @@ func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *co return cmd } -func (o *VersionOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { +// Complete completes all the required options +func (o *Options) Complete(f cmdutil.Factory, cmd *cobra.Command) error { var err error o.discoveryClient, err = f.ToDiscoveryClient() // if we had an empty rest.Config, continue and just print out client information. @@ -92,7 +97,8 @@ func (o *VersionOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { return nil } -func (o *VersionOptions) Validate() error { +// Validate validates the provided options +func (o *Options) Validate() error { if o.Output != "" && o.Output != "yaml" && o.Output != "json" { return errors.New(`--output must be 'yaml' or 'json'`) } @@ -100,7 +106,8 @@ func (o *VersionOptions) Validate() error { return nil } -func (o *VersionOptions) Run() error { +// Run executes version command +func (o *Options) Run() error { var ( serverVersion *apimachineryversion.Info serverErr error