Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some golint failures of pkg/kubectl/cmd/attach pkg/kubectl/cmd/autoscale #77112

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/kubectl/cmd/attach/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/kubectl/cmd/autoscale/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -198,6 +203,7 @@ func (o *AutoscaleOptions) Validate() error {
return nil
}

// Run performs the execution
func (o *AutoscaleOptions) Run() error {
r := o.builder.
Unstructured().
Expand Down