From 10c6a5a1e3a2f89d1b070f1c0d1170053becb6c3 Mon Sep 17 00:00:00 2001 From: Ankit Mahajan Date: Thu, 9 Jul 2026 01:22:29 +0530 Subject: [PATCH] NO-JIRA: Fix staticcheck warnings in pkg/cli/admin/mustgather Address several staticcheck findings in the must-gather package: - Remove unnecessary fmt.Sprintf calls wrapping plain strings (S1039) - Eliminate unused make() allocation overwritten on next line (SA4006) - Use time.Since instead of time.Now().Sub (S1012) - Remove redundant return at end of function (S1023) Signed-off-by: Ankit Mahajan ankimaha@redhat.com Signed-off-by: Ankit Mahajan --- pkg/cli/admin/mustgather/mustgather.go | 10 +++------- pkg/cli/admin/mustgather/summary.go | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/cli/admin/mustgather/mustgather.go b/pkg/cli/admin/mustgather/mustgather.go index 38c52b270b..64af976948 100644 --- a/pkg/cli/admin/mustgather/mustgather.go +++ b/pkg/cli/admin/mustgather/mustgather.go @@ -237,7 +237,7 @@ func (o *MustGatherOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg } // TODO: this should be in Validate() method, but added here because of the call to o.completeImages() below if o.AllImages { - errStr := fmt.Sprintf("and --all-images are mutually exclusive: please specify one or the other") + errStr := "and --all-images are mutually exclusive: please specify one or the other" if len(o.Images) != 0 { return fmt.Errorf("--image %s", errStr) } @@ -333,10 +333,7 @@ func (o *MustGatherOptions) completeImages(ctx context.Context) error { } if o.AllImages { // find all csvs and clusteroperators with the annotation "operators.openshift.io/must-gather-image" - pluginImages := make(map[string]struct{}) - var err error - - pluginImages, err = o.annotatedCSVs(ctx) + pluginImages, err := o.annotatedCSVs(ctx) if err != nil { return err } @@ -1340,7 +1337,7 @@ func (o *MustGatherOptions) BackupGathering(ctx context.Context, errs []error) { fmt.Fprintf(o.ErrOut, "Falling back to `oc adm inspect %s` to collect basic cluster types.\n", typeTargets) streams := o.IOStreams - streams.Out = o.newPrefixWriter(streams.Out, fmt.Sprintf("[must-gather ] OUT"), false, true) + streams.Out = o.newPrefixWriter(streams.Out, "[must-gather ] OUT", false, true) destDir := path.Join(o.DestDir, fmt.Sprintf("inspect.local.%06d", rand.Int63())) if err := runInspect(ctx, streams, rest.CopyConfig(o.Config), destDir, []string{typeTargets}); err != nil { @@ -1352,7 +1349,6 @@ func (o *MustGatherOptions) BackupGathering(ctx context.Context, errs []error) { if err := runInspect(ctx, streams, rest.CopyConfig(o.Config), destDir, namedTargets); err != nil { fmt.Fprintf(o.ErrOut, "error completing cluster named resource inspection: %v\n", err) } - return } func runInspect(ctx context.Context, streams genericiooptions.IOStreams, config *rest.Config, destDir string, arguments []string) error { diff --git a/pkg/cli/admin/mustgather/summary.go b/pkg/cli/admin/mustgather/summary.go index 8ac749915e..6aa76e308b 100644 --- a/pkg/cli/admin/mustgather/summary.go +++ b/pkg/cli/admin/mustgather/summary.go @@ -162,7 +162,7 @@ func humanSummaryForClusterVersion(clusterVersion *configv1.ClusterVersion) stri lastChangeHumanDuration := "" if len(clusterVersion.Status.History) > 0 { - lastChangeHumanDuration = units.HumanDuration(time.Now().Sub(clusterVersion.Status.History[0].StartedTime.Time)) + lastChangeHumanDuration = units.HumanDuration(time.Since(clusterVersion.Status.History[0].StartedTime.Time)) } progressingConditionMessage := "" @@ -182,7 +182,7 @@ func humanSummaryForClusterVersion(clusterVersion *configv1.ClusterVersion) stri case isStable: return fmt.Sprintf("Stable at %q", clusterVersion.Status.History[0].Version) default: - return fmt.Sprintf("Unknown state") + return "Unknown state" } }