Fix Go vet errors for master golang
Co-authored-by: Rajalakshmi-Girish <rajalakshmi.girish1@ibm.com> Co-authored-by: Abhishek Kr Srivastav <Abhishek.kr.srivastav@ibm.com> Kubernetes-commit: d58b536147a6acfc6bfc6f66de2fe3af973ee88d
This commit is contained in:
parent
dd5171041f
commit
ec26cd8a9c
|
@ -206,7 +206,7 @@ func (o *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s
|
||||||
|
|
||||||
o.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd)
|
o.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmdutil.UsageErrorf(cmd, err.Error())
|
return cmdutil.UsageErrorf(cmd, "%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Builder = f.NewBuilder
|
o.Builder = f.NewBuilder
|
||||||
|
|
|
@ -988,6 +988,6 @@ func cmpFileData(t *testing.T, filePath, data string) {
|
||||||
type testWriter testing.T
|
type testWriter testing.T
|
||||||
|
|
||||||
func (t *testWriter) Write(p []byte) (n int, err error) {
|
func (t *testWriter) Write(p []byte) (n int, err error) {
|
||||||
t.Logf(string(p))
|
t.Log(string(p))
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package create
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -399,12 +400,12 @@ func parsePorts(portString string) (int32, intstr.IntOrString, error) {
|
||||||
var targetPort intstr.IntOrString
|
var targetPort intstr.IntOrString
|
||||||
if portNum, err := strconv.Atoi(portStringSlice[1]); err != nil {
|
if portNum, err := strconv.Atoi(portStringSlice[1]); err != nil {
|
||||||
if errs := validation.IsValidPortName(portStringSlice[1]); len(errs) != 0 {
|
if errs := validation.IsValidPortName(portStringSlice[1]); len(errs) != 0 {
|
||||||
return 0, intstr.FromInt32(0), fmt.Errorf(strings.Join(errs, ","))
|
return 0, intstr.FromInt32(0), errors.New(strings.Join(errs, ","))
|
||||||
}
|
}
|
||||||
targetPort = intstr.FromString(portStringSlice[1])
|
targetPort = intstr.FromString(portStringSlice[1])
|
||||||
} else {
|
} else {
|
||||||
if errs := validation.IsValidPortNum(portNum); len(errs) != 0 {
|
if errs := validation.IsValidPortNum(portNum); len(errs) != 0 {
|
||||||
return 0, intstr.FromInt32(0), fmt.Errorf(strings.Join(errs, ","))
|
return 0, intstr.FromInt32(0), errors.New(strings.Join(errs, ","))
|
||||||
}
|
}
|
||||||
targetPort = intstr.FromInt32(int32(portNum))
|
targetPort = intstr.FromInt32(int32(portNum))
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,7 +531,7 @@ func (o *DeleteOptions) confirmation(infos []*resource.Info) bool {
|
||||||
|
|
||||||
fmt.Fprintf(o.Out, "%s/%s\n", kindString, info.Name)
|
fmt.Fprintf(o.Out, "%s/%s\n", kindString, info.Name)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(o.Out, i18n.T("Do you want to continue?")+" (y/n): ")
|
fmt.Fprint(o.Out, i18n.T("Do you want to continue?")+" (y/n): ")
|
||||||
var input string
|
var input string
|
||||||
_, err := fmt.Fscan(o.In, &input)
|
_, err := fmt.Fscan(o.In, &input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -161,7 +161,7 @@ func NewCmdDiff(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
|
||||||
// command it means changes were found.
|
// command it means changes were found.
|
||||||
// Thus, it should return status code greater than 1.
|
// Thus, it should return status code greater than 1.
|
||||||
cmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
|
cmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
|
||||||
cmdutil.CheckDiffErr(cmdutil.UsageErrorf(cmd, err.Error()))
|
cmdutil.CheckDiffErr(cmdutil.UsageErrorf(cmd, "%s", err.Error()))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ func (o *DrainCmdOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if len(args) == 0 && !cmd.Flags().Changed("selector") {
|
if len(args) == 0 && !cmd.Flags().Changed("selector") {
|
||||||
return cmdutil.UsageErrorf(cmd, fmt.Sprintf("USAGE: %s [flags]", cmd.Use))
|
return cmdutil.UsageErrorf(cmd, "USAGE: %s [flags]", cmd.Use)
|
||||||
}
|
}
|
||||||
if len(args) > 0 && len(o.drainer.Selector) > 0 {
|
if len(args) > 0 && len(o.drainer.Selector) > 0 {
|
||||||
return cmdutil.UsageErrorf(cmd, "error: cannot specify both a node name and a --selector option")
|
return cmdutil.UsageErrorf(cmd, "error: cannot specify both a node name and a --selector option")
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
|
||||||
|
|
||||||
p.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd)
|
p.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmdutil.UsageErrorf(cmd, err.Error())
|
return cmdutil.UsageErrorf(cmd, "%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Builder = f.NewBuilder
|
p.Builder = f.NewBuilder
|
||||||
|
|
|
@ -19,6 +19,7 @@ package get
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -161,7 +162,7 @@ func (s *CustomColumnsPrinter) PrintObj(obj runtime.Object, out io.Writer) error
|
||||||
// we need an actual value in order to retrieve the package path for an object.
|
// we need an actual value in order to retrieve the package path for an object.
|
||||||
// using reflect.Indirect indiscriminately is valid here, as all runtime.Objects are supposed to be pointers.
|
// using reflect.Indirect indiscriminately is valid here, as all runtime.Objects are supposed to be pointers.
|
||||||
if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) {
|
if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) {
|
||||||
return fmt.Errorf(printers.InternalObjectPrinterErr)
|
return errors.New(printers.InternalObjectPrinterErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := out.(*tabwriter.Writer); !found {
|
if _, found := out.(*tabwriter.Writer); !found {
|
||||||
|
@ -210,7 +211,7 @@ func (s *CustomColumnsPrinter) printOneObject(obj runtime.Object, parsers []*jso
|
||||||
switch u := obj.(type) {
|
switch u := obj.(type) {
|
||||||
case *metav1.WatchEvent:
|
case *metav1.WatchEvent:
|
||||||
if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(u.Object.Object)).Type().PkgPath()) {
|
if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(u.Object.Object)).Type().PkgPath()) {
|
||||||
return fmt.Errorf(printers.InternalObjectPrinterErr)
|
return errors.New(printers.InternalObjectPrinterErr)
|
||||||
}
|
}
|
||||||
unstructuredObject, err := runtime.DefaultUnstructuredConverter.ToUnstructured(u.Object.Object)
|
unstructuredObject, err := runtime.DefaultUnstructuredConverter.ToUnstructured(u.Object.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -280,7 +280,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
|
||||||
usageString = fmt.Sprintf("%s\nUse \"%s explain <resource>\" for a detailed description of that resource (e.g. %[2]s explain pods).", usageString, fullCmdName)
|
usageString = fmt.Sprintf("%s\nUse \"%s explain <resource>\" for a detailed description of that resource (e.g. %[2]s explain pods).", usageString, fullCmdName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmdutil.UsageErrorf(cmd, usageString)
|
return cmdutil.UsageErrorf(cmd, "%s", usageString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ func (o *PortForwardOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg
|
||||||
|
|
||||||
getPodTimeout, err := cmdutil.GetPodRunningTimeoutFlag(cmd)
|
getPodTimeout, err := cmdutil.GetPodRunningTimeoutFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmdutil.UsageErrorf(cmd, err.Error())
|
return cmdutil.UsageErrorf(cmd, "%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceName := args[0]
|
resourceName := args[0]
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.taintsToAdd, o.taintsToRemove, err = parseTaints(taintArgs); err != nil {
|
if o.taintsToAdd, o.taintsToRemove, err = parseTaints(taintArgs); err != nil {
|
||||||
return cmdutil.UsageErrorf(cmd, err.Error())
|
return cmdutil.UsageErrorf(cmd, "%s", err.Error())
|
||||||
}
|
}
|
||||||
o.builder = f.NewBuilder().
|
o.builder = f.NewBuilder().
|
||||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||||
|
|
|
@ -243,7 +243,7 @@ func statusCausesToAggrError(scs []metav1.StatusCause) utilerrors.Aggregate {
|
||||||
// commands.
|
// commands.
|
||||||
func StandardErrorMessage(err error) (string, bool) {
|
func StandardErrorMessage(err error) (string, bool) {
|
||||||
if debugErr, ok := err.(debugError); ok {
|
if debugErr, ok := err.(debugError); ok {
|
||||||
klog.V(4).Infof(debugErr.DebugError())
|
klog.V(4).Info(debugErr.DebugError())
|
||||||
}
|
}
|
||||||
status, isStatus := err.(apierrors.APIStatus)
|
status, isStatus := err.(apierrors.APIStatus)
|
||||||
switch {
|
switch {
|
||||||
|
|
|
@ -3364,8 +3364,8 @@ Events: <none>
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if out != test.output {
|
if out != test.output {
|
||||||
t.Logf(out)
|
t.Log(out)
|
||||||
t.Logf(test.output)
|
t.Log(test.output)
|
||||||
t.Errorf("expected: \n%q\n but got output: \n%q\n", test.output, out)
|
t.Errorf("expected: \n%q\n but got output: \n%q\n", test.output, out)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -5018,7 +5018,7 @@ Parameters:
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if out != expectedOut {
|
if out != expectedOut {
|
||||||
t.Logf(out)
|
t.Log(out)
|
||||||
t.Errorf("expected : %q\n but got output:\n %q", test.output, out)
|
t.Errorf("expected : %q\n but got output:\n %q", test.output, out)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -5998,7 +5998,7 @@ Events: <none>` + "\n",
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if out != tc.output {
|
if out != tc.output {
|
||||||
t.Logf(out)
|
t.Log(out)
|
||||||
t.Errorf("expected :\n%s\nbut got output:\n%s", tc.output, out)
|
t.Errorf("expected :\n%s\nbut got output:\n%s", tc.output, out)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (p *HelpFlagPrinter) PrintHelpFlag(flag *flag.Flag) {
|
||||||
}
|
}
|
||||||
appendTabStr := strings.ReplaceAll(wrappedStr, "\n", "\n\t")
|
appendTabStr := strings.ReplaceAll(wrappedStr, "\n", "\n\t")
|
||||||
|
|
||||||
fmt.Fprintf(p.out, appendTabStr+"\n\n")
|
fmt.Fprint(p.out, appendTabStr+"\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeFlag will output the help flag based
|
// writeFlag will output the help flag based
|
||||||
|
|
Loading…
Reference in New Issue