Skip to content

Commit f1967b0

Browse files
committed
Fix go vet issues
1 parent 1a7922b commit f1967b0

File tree

36 files changed

+94
-92
lines changed

36 files changed

+94
-92
lines changed

pkg/cli/admin/admin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package admin
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
75

86
"k8s.io/cli-runtime/pkg/genericiooptions"
@@ -57,7 +55,7 @@ func NewCommandAdmin(f kcmdutil.Factory, streams genericiooptions.IOStreams) *co
5755
cmds := &cobra.Command{
5856
Use: "adm",
5957
Short: "Tools for managing a cluster",
60-
Long: fmt.Sprintf(adminLong),
58+
Long: adminLong,
6159
Run: kcmdutil.DefaultSubCommandRun(streams.ErrOut),
6260
}
6361

pkg/cli/admin/mustgather/mustgather.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mustgather
33
import (
44
"bufio"
55
"context"
6+
"errors"
67
"fmt"
78
"io"
89
"math/rand"
@@ -21,7 +22,7 @@ import (
2122
kerrors "k8s.io/apimachinery/pkg/api/errors"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/runtime/schema"
24-
"k8s.io/apimachinery/pkg/util/errors"
25+
kutilerrors "k8s.io/apimachinery/pkg/util/errors"
2526
"k8s.io/apimachinery/pkg/util/wait"
2627
"k8s.io/cli-runtime/pkg/genericclioptions"
2728
"k8s.io/cli-runtime/pkg/genericiooptions"
@@ -483,7 +484,7 @@ func (o *MustGatherOptions) Run() error {
483484
line := fmt.Sprintf("unable to parse image reference %s: %v", image, err)
484485
o.log(line)
485486
// ensure the errors bubble up to BackupGathering method for display
486-
errs = []error{fmt.Errorf(line)}
487+
errs = []error{errors.New(line)}
487488
return err
488489
}
489490
if o.NodeSelector != "" {
@@ -564,7 +565,7 @@ func (o *MustGatherOptions) Run() error {
564565
errs = append(errs, err)
565566
}
566567

567-
return errors.NewAggregate(errs)
568+
return kutilerrors.NewAggregate(errs)
568569
}
569570

570571
// processNextWorkItem creates & processes the must-gather pod and returns error if any
@@ -708,7 +709,7 @@ func (o *MustGatherOptions) copyFilesFromPod(pod *corev1.Pod) error {
708709
err = rsyncOptions.RunRsync()
709710
errs = append(errs, err)
710711
}
711-
return errors.NewAggregate(errs)
712+
return kutilerrors.NewAggregate(errs)
712713
}
713714

714715
func (o *MustGatherOptions) getGatherContainerLogs(pod *corev1.Pod) error {
@@ -1070,7 +1071,7 @@ func (o *MustGatherOptions) BackupGathering(ctx context.Context, errs []error) {
10701071
}
10711072

10721073
fmt.Fprintf(o.ErrOut, "\n\n") // Space out the output
1073-
fmt.Fprintf(o.ErrOut, "Error running must-gather collection:\n %v\n\n", errors.NewAggregate(errs))
1074+
fmt.Fprintf(o.ErrOut, "Error running must-gather collection:\n %v\n\n", kutilerrors.NewAggregate(errs))
10741075
fmt.Fprintf(o.ErrOut, "Falling back to `oc adm inspect %s` to collect basic cluster types.\n", typeTargets)
10751076

10761077
streams := o.IOStreams

pkg/cli/admin/mustgather/summary.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// to one of those three spots. Doing so improves the self-diagnosis capabilities of our platform and lets *every*
2626
// client benefit.
2727
func (o *MustGatherOptions) PrintBasicClusterState(ctx context.Context) {
28-
fmt.Fprintf(o.RawOut, "When opening a support case, bugzilla, or issue please include the following summary data along with any other requested information:\n")
28+
fmt.Fprint(o.RawOut, "When opening a support case, bugzilla, or issue please include the following summary data along with any other requested information:\n")
2929

3030
clusterVersion, err := o.ConfigClient.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
3131
if err != nil {
@@ -44,11 +44,11 @@ func (o *MustGatherOptions) PrintBasicClusterState(ctx context.Context) {
4444
if err != nil {
4545
fmt.Fprintf(o.RawOut, "error getting cluster operators: %v\n", err)
4646
}
47-
fmt.Fprintf(o.RawOut, "ClusterOperators:\n")
48-
fmt.Fprintf(o.RawOut, humanSummaryForInterestingClusterOperators(clusterOperators)+"\n")
47+
fmt.Fprint(o.RawOut, "ClusterOperators:\n")
48+
fmt.Fprint(o.RawOut, humanSummaryForInterestingClusterOperators(clusterOperators)+"\n")
4949

5050
// TODO gather and display firing alerts
51-
fmt.Fprintf(o.RawOut, "\n\n")
51+
fmt.Fprint(o.RawOut, "\n\n")
5252
}
5353

5454
// longExistingOperators is a list of operators that should be present on every variant of every platform and have

pkg/cli/admin/ocpcertificates/ocp_certificates.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package ocpcertificates
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
75

86
"k8s.io/cli-runtime/pkg/genericiooptions"
@@ -25,7 +23,7 @@ func NewCommandOCPCertificates(f kcmdutil.Factory, streams genericiooptions.IOSt
2523
cmds := &cobra.Command{
2624
Use: "ocp-certificates",
2725
Short: "Tools for managing a cluster's certificates",
28-
Long: fmt.Sprintf(ocpCertificatesLong),
26+
Long: ocpCertificatesLong,
2927
Run: kcmdutil.DefaultSubCommandRun(streams.ErrOut),
3028
}
3129

pkg/cli/admin/prune/auth/bindings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func reapClusterBindings(removedSubject corev1.ObjectReference, c authv1client.A
3636
if _, err := c.ClusterRoleBindings().Update(context.TODO(), &updatedBinding, metav1.UpdateOptions{}); err != nil && !kerrors.IsNotFound(err) {
3737
errors = append(errors, err)
3838
} else {
39-
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
39+
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/%s updated\n", updatedBinding.Name)
4040
}
4141
}
4242
}
@@ -65,7 +65,7 @@ func reapNamespacedBindings(removedSubject corev1.ObjectReference, c authv1clien
6565
if _, err := c.RoleBindings(binding.Namespace).Update(context.TODO(), &updatedBinding, metav1.UpdateOptions{}); err != nil && !kerrors.IsNotFound(err) {
6666
errors = append(errors, err)
6767
} else {
68-
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/"+updatedBinding.Name+" updated\n")
68+
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/%s updated\n", updatedBinding.Name)
6969
}
7070
}
7171
}

pkg/cli/admin/prune/auth/cluster_role.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func reapForClusterRole(clusterBindingClient rbacv1client.ClusterRoleBindingsGet
2323
if err := clusterBindingClient.ClusterRoleBindings().Delete(context.TODO(), clusterBinding.Name, metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) {
2424
errors = append(errors, err)
2525
} else {
26-
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/"+clusterBinding.Name+" deleted\n")
26+
fmt.Fprintf(out, "clusterrolebinding.rbac.authorization.k8s.io/%s deleted\n", clusterBinding.Name)
2727
}
2828
}
2929
}
@@ -37,7 +37,7 @@ func reapForClusterRole(clusterBindingClient rbacv1client.ClusterRoleBindingsGet
3737
if err := bindingClient.RoleBindings(namespacedBinding.Namespace).Delete(context.TODO(), namespacedBinding.Name, metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) {
3838
errors = append(errors, err)
3939
} else {
40-
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/"+namespacedBinding.Name+" deleted\n")
40+
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/%s deleted\n", namespacedBinding.Name)
4141
}
4242
}
4343
}

pkg/cli/admin/prune/auth/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func reapForGroup(
4444
if _, err := securityClient.Update(context.TODO(), &updatedSCC, metav1.UpdateOptions{}); err != nil && !kerrors.IsNotFound(err) {
4545
errors = append(errors, err)
4646
} else {
47-
fmt.Fprintf(out, "securitycontextconstraints.security.openshift.io/"+updatedSCC.Name+" updated\n")
47+
fmt.Fprintf(out, "securitycontextconstraints.security.openshift.io/%s updated\n", updatedSCC.Name)
4848
}
4949
}
5050
}

pkg/cli/admin/prune/auth/role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func reapForRole(bindingClient rbacv1client.RoleBindingsGetter, namespace, name
2424
if err := bindingClient.RoleBindings(namespace).Delete(context.TODO(), binding.Name, metav1.DeleteOptions{PropagationPolicy: &foreground}); err != nil && !kerrors.IsNotFound(err) {
2525
errors = append(errors, err)
2626
} else {
27-
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/"+binding.Name+" deleted\n")
27+
fmt.Fprintf(out, "rolebinding.rbac.authorization.k8s.io/%s deleted\n", binding.Name)
2828
}
2929
}
3030
}

pkg/cli/admin/prune/auth/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func reapForUser(
4848
if _, err := securityClient.Update(context.TODO(), &updatedSCC, metav1.UpdateOptions{}); err != nil && !kerrors.IsNotFound(err) {
4949
errors = append(errors, err)
5050
} else {
51-
fmt.Fprintf(out, "securitycontextconstraints.security.openshift.io/"+updatedSCC.Name+" updated\n")
51+
fmt.Fprintf(out, "securitycontextconstraints.security.openshift.io/%s updated\n", updatedSCC.Name)
5252
}
5353
}
5454
}
@@ -71,7 +71,7 @@ func reapForUser(
7171
if _, err := userClient.Groups().Update(context.TODO(), &updatedGroup, metav1.UpdateOptions{}); err != nil && !kerrors.IsNotFound(err) {
7272
errors = append(errors, err)
7373
} else {
74-
fmt.Fprintf(out, "group.user.openshift.io/"+updatedGroup.Name+" updated\n")
74+
fmt.Fprintf(out, "group.user.openshift.io/%s updated\n", updatedGroup.Name)
7575
}
7676
}
7777
}
@@ -88,7 +88,7 @@ func reapForUser(
8888
if err := oauthClient.OAuthClientAuthorizations().Delete(context.TODO(), authorization.Name, metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) {
8989
errors = append(errors, err)
9090
} else {
91-
fmt.Fprintf(out, "oauthclientauthorization.oauth.openshift.io/"+authorization.Name+" updated\n")
91+
fmt.Fprintf(out, "oauthclientauthorization.oauth.openshift.io/%s updated\n", authorization.Name)
9292
}
9393
}
9494
}

pkg/cli/admin/prune/imageprune/prune.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package imageprune
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"net/http"
89
"net/url"
@@ -1368,7 +1369,7 @@ func deleteFromRegistry(registryClient *http.Client, url string) error {
13681369
// non-2xx/3xx response doesn't cause an error, so we need to check for it
13691370
// manually and return it to caller
13701371
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
1371-
return fmt.Errorf(resp.Status)
1372+
return errors.New(resp.Status)
13721373
}
13731374

13741375
if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusAccepted {

0 commit comments

Comments
 (0)