From ec26cd8a9cc6945a9f8a618dd65ff7787b8cac1e Mon Sep 17 00:00:00 2001 From: Abhishek Kr Srivastav Date: Thu, 12 Sep 2024 18:15:22 +0530 Subject: [PATCH] Fix Go vet errors for master golang Co-authored-by: Rajalakshmi-Girish Co-authored-by: Abhishek Kr Srivastav Kubernetes-commit: d58b536147a6acfc6bfc6f66de2fe3af973ee88d --- pkg/cmd/attach/attach.go | 2 +- pkg/cmd/cp/cp_test.go | 2 +- pkg/cmd/create/create_service.go | 5 +++-- pkg/cmd/delete/delete.go | 2 +- pkg/cmd/diff/diff.go | 2 +- pkg/cmd/drain/drain.go | 2 +- pkg/cmd/exec/exec.go | 2 +- pkg/cmd/get/customcolumn.go | 5 +++-- pkg/cmd/get/get.go | 2 +- pkg/cmd/portforward/portforward.go | 2 +- pkg/cmd/taint/taint.go | 2 +- pkg/cmd/util/helpers.go | 2 +- pkg/describe/describe_test.go | 8 ++++---- pkg/util/templates/help_flags_printer.go | 2 +- 14 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pkg/cmd/attach/attach.go b/pkg/cmd/attach/attach.go index b38760a1..73b3cea7 100644 --- a/pkg/cmd/attach/attach.go +++ b/pkg/cmd/attach/attach.go @@ -206,7 +206,7 @@ func (o *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s o.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd) if err != nil { - return cmdutil.UsageErrorf(cmd, err.Error()) + return cmdutil.UsageErrorf(cmd, "%s", err.Error()) } o.Builder = f.NewBuilder diff --git a/pkg/cmd/cp/cp_test.go b/pkg/cmd/cp/cp_test.go index 734f9562..b0038d0f 100644 --- a/pkg/cmd/cp/cp_test.go +++ b/pkg/cmd/cp/cp_test.go @@ -988,6 +988,6 @@ func cmpFileData(t *testing.T, filePath, data string) { type testWriter testing.T func (t *testWriter) Write(p []byte) (n int, err error) { - t.Logf(string(p)) + t.Log(string(p)) return len(p), nil } diff --git a/pkg/cmd/create/create_service.go b/pkg/cmd/create/create_service.go index 54b164b3..6a28942e 100644 --- a/pkg/cmd/create/create_service.go +++ b/pkg/cmd/create/create_service.go @@ -18,6 +18,7 @@ package create import ( "context" + "errors" "fmt" "strconv" "strings" @@ -399,12 +400,12 @@ func parsePorts(portString string) (int32, intstr.IntOrString, error) { var targetPort intstr.IntOrString if portNum, err := strconv.Atoi(portStringSlice[1]); err != nil { 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]) } else { 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)) } diff --git a/pkg/cmd/delete/delete.go b/pkg/cmd/delete/delete.go index 12df2ff4..2792ccd4 100644 --- a/pkg/cmd/delete/delete.go +++ b/pkg/cmd/delete/delete.go @@ -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, 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 _, err := fmt.Fscan(o.In, &input) if err != nil { diff --git a/pkg/cmd/diff/diff.go b/pkg/cmd/diff/diff.go index 2afa6b17..b82e493c 100644 --- a/pkg/cmd/diff/diff.go +++ b/pkg/cmd/diff/diff.go @@ -161,7 +161,7 @@ func NewCmdDiff(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co // command it means changes were found. // Thus, it should return status code greater than 1. 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 }) diff --git a/pkg/cmd/drain/drain.go b/pkg/cmd/drain/drain.go index d8bc03ac..13c2dc4a 100644 --- a/pkg/cmd/drain/drain.go +++ b/pkg/cmd/drain/drain.go @@ -245,7 +245,7 @@ func (o *DrainCmdOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ var err error 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 { return cmdutil.UsageErrorf(cmd, "error: cannot specify both a node name and a --selector option") diff --git a/pkg/cmd/exec/exec.go b/pkg/cmd/exec/exec.go index a6ec2f43..fea3a328 100644 --- a/pkg/cmd/exec/exec.go +++ b/pkg/cmd/exec/exec.go @@ -225,7 +225,7 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s p.GetPodTimeout, err = cmdutil.GetPodRunningTimeoutFlag(cmd) if err != nil { - return cmdutil.UsageErrorf(cmd, err.Error()) + return cmdutil.UsageErrorf(cmd, "%s", err.Error()) } p.Builder = f.NewBuilder diff --git a/pkg/cmd/get/customcolumn.go b/pkg/cmd/get/customcolumn.go index 38024cfa..b9943495 100644 --- a/pkg/cmd/get/customcolumn.go +++ b/pkg/cmd/get/customcolumn.go @@ -19,6 +19,7 @@ package get import ( "bufio" "bytes" + "errors" "fmt" "io" "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. // 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()) { - return fmt.Errorf(printers.InternalObjectPrinterErr) + return errors.New(printers.InternalObjectPrinterErr) } if _, found := out.(*tabwriter.Writer); !found { @@ -210,7 +211,7 @@ func (s *CustomColumnsPrinter) printOneObject(obj runtime.Object, parsers []*jso switch u := obj.(type) { case *metav1.WatchEvent: 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) if err != nil { diff --git a/pkg/cmd/get/get.go b/pkg/cmd/get/get.go index f1658699..07979333 100644 --- a/pkg/cmd/get/get.go +++ b/pkg/cmd/get/get.go @@ -280,7 +280,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri usageString = fmt.Sprintf("%s\nUse \"%s explain \" 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) } } diff --git a/pkg/cmd/portforward/portforward.go b/pkg/cmd/portforward/portforward.go index 027bffd4..b1eeb919 100644 --- a/pkg/cmd/portforward/portforward.go +++ b/pkg/cmd/portforward/portforward.go @@ -323,7 +323,7 @@ func (o *PortForwardOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg getPodTimeout, err := cmdutil.GetPodRunningTimeoutFlag(cmd) if err != nil { - return cmdutil.UsageErrorf(cmd, err.Error()) + return cmdutil.UsageErrorf(cmd, "%s", err.Error()) } resourceName := args[0] diff --git a/pkg/cmd/taint/taint.go b/pkg/cmd/taint/taint.go index bca70fe3..f185926e 100644 --- a/pkg/cmd/taint/taint.go +++ b/pkg/cmd/taint/taint.go @@ -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 { - return cmdutil.UsageErrorf(cmd, err.Error()) + return cmdutil.UsageErrorf(cmd, "%s", err.Error()) } o.builder = f.NewBuilder(). WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...). diff --git a/pkg/cmd/util/helpers.go b/pkg/cmd/util/helpers.go index 2218b9f5..64a2b307 100644 --- a/pkg/cmd/util/helpers.go +++ b/pkg/cmd/util/helpers.go @@ -243,7 +243,7 @@ func statusCausesToAggrError(scs []metav1.StatusCause) utilerrors.Aggregate { // commands. func StandardErrorMessage(err error) (string, bool) { if debugErr, ok := err.(debugError); ok { - klog.V(4).Infof(debugErr.DebugError()) + klog.V(4).Info(debugErr.DebugError()) } status, isStatus := err.(apierrors.APIStatus) switch { diff --git a/pkg/describe/describe_test.go b/pkg/describe/describe_test.go index 9c7e5b6f..a181661a 100644 --- a/pkg/describe/describe_test.go +++ b/pkg/describe/describe_test.go @@ -3364,8 +3364,8 @@ Events: t.Errorf("unexpected error: %v", err) } if out != test.output { - t.Logf(out) - t.Logf(test.output) + t.Log(out) + t.Log(test.output) 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) } if out != expectedOut { - t.Logf(out) + t.Log(out) t.Errorf("expected : %q\n but got output:\n %q", test.output, out) } }) @@ -5998,7 +5998,7 @@ Events: ` + "\n", t.Errorf("unexpected error: %v", err) } if out != tc.output { - t.Logf(out) + t.Log(out) t.Errorf("expected :\n%s\nbut got output:\n%s", tc.output, out) } }) diff --git a/pkg/util/templates/help_flags_printer.go b/pkg/util/templates/help_flags_printer.go index fdfdf08e..b7e1bf00 100644 --- a/pkg/util/templates/help_flags_printer.go +++ b/pkg/util/templates/help_flags_printer.go @@ -62,7 +62,7 @@ func (p *HelpFlagPrinter) PrintHelpFlag(flag *flag.Flag) { } 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