From 6f7690e13919dcf6b9aeb6651a75dc88e11e8997 Mon Sep 17 00:00:00 2001 From: SataQiu Date: Mon, 29 Apr 2019 17:25:34 +0800 Subject: [PATCH] fix some golint failures of pkg/kubectl/cmd/attach pkg/kubectl/cmd/autoscale --- pkg/kubectl/cmd/attach/attach.go | 6 +++++- pkg/kubectl/cmd/autoscale/autoscale.go | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/attach/attach.go b/pkg/kubectl/cmd/attach/attach.go index 1b56761fb54..266fff2b355 100644 --- a/pkg/kubectl/cmd/attach/attach.go +++ b/pkg/kubectl/cmd/attach/attach.go @@ -61,7 +61,7 @@ const ( defaultPodLogsTimeout = 20 * time.Second ) -// AttachOptions declare the arguments accepted by the Exec command +// AttachOptions declare the arguments accepted by the Attach command type AttachOptions struct { exec.StreamOptions @@ -84,6 +84,7 @@ type AttachOptions struct { Config *restclient.Config } +// NewAttachOptions creates the options for attach func NewAttachOptions(streams genericclioptions.IOStreams) *AttachOptions { return &AttachOptions{ StreamOptions: exec.StreamOptions{ @@ -94,6 +95,7 @@ func NewAttachOptions(streams genericclioptions.IOStreams) *AttachOptions { } } +// NewCmdAttach returns the attach Cobra command func NewCmdAttach(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { o := NewAttachOptions(streams) cmd := &cobra.Command{ @@ -120,6 +122,7 @@ type RemoteAttach interface { Attach(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error } +// DefaultAttachFunc is the default AttachFunc used func DefaultAttachFunc(o *AttachOptions, containerToAttach *corev1.Container, raw bool, sizeQueue remotecommand.TerminalSizeQueue) func() error { return func() error { restClient, err := restclient.RESTClientFor(o.Config) @@ -146,6 +149,7 @@ func DefaultAttachFunc(o *AttachOptions, containerToAttach *corev1.Container, ra // DefaultRemoteAttach is the standard implementation of attaching type DefaultRemoteAttach struct{} +// Attach executes attach to a running container func (*DefaultRemoteAttach) Attach(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error { exec, err := remotecommand.NewSPDYExecutor(config, method, url) if err != nil { diff --git a/pkg/kubectl/cmd/autoscale/autoscale.go b/pkg/kubectl/cmd/autoscale/autoscale.go index 42d4d081a34..9b10bcfd9a3 100644 --- a/pkg/kubectl/cmd/autoscale/autoscale.go +++ b/pkg/kubectl/cmd/autoscale/autoscale.go @@ -53,6 +53,7 @@ var ( kubectl autoscale rc foo --max=5 --cpu-percent=80`)) ) +// AutoscaleOptions declare the arguments accepted by the Autoscale command type AutoscaleOptions struct { FilenameOptions *resource.FilenameOptions @@ -82,6 +83,7 @@ type AutoscaleOptions struct { genericclioptions.IOStreams } +// NewAutoscaleOptions creates the options for autoscale func NewAutoscaleOptions(ioStreams genericclioptions.IOStreams) *AutoscaleOptions { return &AutoscaleOptions{ PrintFlags: genericclioptions.NewPrintFlags("autoscaled").WithTypeSetter(scheme.Scheme), @@ -93,6 +95,7 @@ func NewAutoscaleOptions(ioStreams genericclioptions.IOStreams) *AutoscaleOption } } +// NewCmdAutoscale returns the autoscale Cobra command func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { o := NewAutoscaleOptions(ioStreams) @@ -128,6 +131,7 @@ func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) * return cmd } +// Complete verifies command line arguments and loads data from the command environment func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error { var err error o.dryRun = cmdutil.GetFlagBool(cmd, "dry-run") @@ -187,6 +191,7 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args return nil } +// Validate checks that the provided attach options are specified. func (o *AutoscaleOptions) Validate() error { if o.Max < 1 { return fmt.Errorf("--max=MAXPODS is required and must be at least 1, max: %d", o.Max) @@ -198,6 +203,7 @@ func (o *AutoscaleOptions) Validate() error { return nil } +// Run performs the execution func (o *AutoscaleOptions) Run() error { r := o.builder. Unstructured().