From 18cf165ac060ade95a71075c2ee9df02cc7bae2b Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Fri, 7 Feb 2025 09:54:44 -0700 Subject: [PATCH] *: fix non-constant format strings printf: non-constant format string in call to (*github.com/sirupsen/logrus.Entry).Warnf (govet) Signed-off-by: Steve Kuznetsov --- pkg/api/error.go | 8 +++++++- pkg/cluster/gatherlogs.go | 4 ++-- .../admin_openshiftcluster_etcdcertificaterenew.go | 4 ++-- .../checkers/clusterdnschecker/controller_test.go | 4 ++-- .../checkers/ingresscertificatechecker/controller_test.go | 4 ++-- .../controllers/checkers/internetchecker/checker.go | 2 +- .../checkers/serviceprincipalchecker/controller_test.go | 4 ++-- .../controllers/pullsecret/pullsecret_controller_test.go | 4 ++-- pkg/operator/controllers/subnets/subnets_controller.go | 2 +- test/util/kubeadminkubeconfig/kubetoken.go | 4 ++-- 10 files changed, 23 insertions(+), 17 deletions(-) diff --git a/pkg/api/error.go b/pkg/api/error.go index 3fd83b8f9a3..a688f453b1f 100644 --- a/pkg/api/error.go +++ b/pkg/api/error.go @@ -113,11 +113,17 @@ const ( // NewCloudError returns a new CloudError func NewCloudError(statusCode int, code, target, message string, a ...interface{}) *CloudError { + var msg string + if len(a) == 0 { + msg = fmt.Sprint(message) + } else { + msg = fmt.Sprintf(msg, a...) + } return &CloudError{ StatusCode: statusCode, CloudErrorBody: &CloudErrorBody{ Code: code, - Message: fmt.Sprintf(message, a...), + Message: msg, Target: target, }, } diff --git a/pkg/cluster/gatherlogs.go b/pkg/cluster/gatherlogs.go index ce15ff2ed7f..38677d21190 100644 --- a/pkg/cluster/gatherlogs.go +++ b/pkg/cluster/gatherlogs.go @@ -175,7 +175,7 @@ func (m *manager) logClusterOperators(ctx context.Context) (interface{}, error) errs = append(errs, err) continue } - m.log.Infof(string(json)) + m.log.Info(string(json)) } return strings.Join(lines, "\n"), errors.Join(errs...) @@ -217,7 +217,7 @@ func (m *manager) logIngressControllers(ctx context.Context) (interface{}, error errs = append(errs, err) continue } - m.log.Infof(string(json)) + m.log.Info(string(json)) } return strings.Join(lines, "\n"), errors.Join(errs...) diff --git a/pkg/frontend/admin_openshiftcluster_etcdcertificaterenew.go b/pkg/frontend/admin_openshiftcluster_etcdcertificaterenew.go index 39a37b06d3b..6e46855ae5d 100644 --- a/pkg/frontend/admin_openshiftcluster_etcdcertificaterenew.go +++ b/pkg/frontend/admin_openshiftcluster_etcdcertificaterenew.go @@ -448,13 +448,13 @@ func (e *etcdrenew) isEtcdRevised(ctx context.Context) (bool, error) { isAtRevision := true rawEtcd, err := e.k.KubeGet(ctx, "etcd.operator.openshift.io", "", "cluster") if err != nil { - e.log.Warnf(err.Error()) + e.log.Warn(err.Error()) return false, nil } etcd := &operatorv1.Etcd{} err = codec.NewDecoderBytes(rawEtcd, &codec.JsonHandle{}).Decode(etcd) if err != nil { - e.log.Warnf(err.Error()) + e.log.Warn(err.Error()) return false, nil } diff --git a/pkg/operator/controllers/checkers/clusterdnschecker/controller_test.go b/pkg/operator/controllers/checkers/clusterdnschecker/controller_test.go index 8a987ce8562..e10e5d28c62 100644 --- a/pkg/operator/controllers/checkers/clusterdnschecker/controller_test.go +++ b/pkg/operator/controllers/checkers/clusterdnschecker/controller_test.go @@ -137,11 +137,11 @@ func TestReconcile(t *testing.T) { } if condition.Status != tt.wantConditionStatus { - t.Errorf(string(condition.Status)) + t.Error(string(condition.Status)) } if condition.Message != tt.wantConditionMessage { - t.Errorf(condition.Message) + t.Error(condition.Message) } }) } diff --git a/pkg/operator/controllers/checkers/ingresscertificatechecker/controller_test.go b/pkg/operator/controllers/checkers/ingresscertificatechecker/controller_test.go index 9ca191c498c..fe005b2e297 100644 --- a/pkg/operator/controllers/checkers/ingresscertificatechecker/controller_test.go +++ b/pkg/operator/controllers/checkers/ingresscertificatechecker/controller_test.go @@ -116,11 +116,11 @@ func TestReconcile(t *testing.T) { } if condition.Status != tt.wantConditionStatus { - t.Errorf(string(condition.Status)) + t.Error(string(condition.Status)) } if condition.Message != tt.wantConditionMessage { - t.Errorf(condition.Message) + t.Error(condition.Message) } }) } diff --git a/pkg/operator/controllers/checkers/internetchecker/checker.go b/pkg/operator/controllers/checkers/internetchecker/checker.go index b7a7f391147..d2f747b8db5 100644 --- a/pkg/operator/controllers/checkers/internetchecker/checker.go +++ b/pkg/operator/controllers/checkers/internetchecker/checker.go @@ -66,7 +66,7 @@ func (r *checker) Check(URLs []string) error { } if len(errsAll) != 0 { // TODO: Consider replacing with multi error wrapping with Go 1.20: https://github.com/golang/go/issues/53435#issuecomment-1320343377 - return fmt.Errorf(strings.Join(errsAll, "\n")) + return fmt.Errorf("%s", strings.Join(errsAll, "\n")) } return nil diff --git a/pkg/operator/controllers/checkers/serviceprincipalchecker/controller_test.go b/pkg/operator/controllers/checkers/serviceprincipalchecker/controller_test.go index 365d9ceb3ce..377e23c2123 100644 --- a/pkg/operator/controllers/checkers/serviceprincipalchecker/controller_test.go +++ b/pkg/operator/controllers/checkers/serviceprincipalchecker/controller_test.go @@ -122,11 +122,11 @@ func TestReconcile(t *testing.T) { } if condition.Status != tt.wantConditionStatus { - t.Errorf(string(condition.Status)) + t.Error(string(condition.Status)) } if condition.Message != tt.wantConditionMessage { - t.Errorf(condition.Message) + t.Error(condition.Message) } }) } diff --git a/pkg/operator/controllers/pullsecret/pullsecret_controller_test.go b/pkg/operator/controllers/pullsecret/pullsecret_controller_test.go index 78679165e29..dbb23659bc4 100644 --- a/pkg/operator/controllers/pullsecret/pullsecret_controller_test.go +++ b/pkg/operator/controllers/pullsecret/pullsecret_controller_test.go @@ -807,8 +807,8 @@ func TestEnsureGlobalPullSecret(t *testing.T) { s, err := r.ensureGlobalPullSecret(ctx, tt.operatorPullSecret, tt.pullSecret) utilerror.AssertErrorMessage(t, err, tt.wantError) - if !reflect.DeepEqual(s, tt.wantSecret) { - t.Fatalf(cmp.Diff(s, tt.wantSecret)) + if diff := cmp.Diff(s, tt.wantSecret); diff != "" { + t.Fatalf("Unexpected pull secret (-want, +got): %s", diff) } }) } diff --git a/pkg/operator/controllers/subnets/subnets_controller.go b/pkg/operator/controllers/subnets/subnets_controller.go index 966df59f959..389cf51e77e 100644 --- a/pkg/operator/controllers/subnets/subnets_controller.go +++ b/pkg/operator/controllers/subnets/subnets_controller.go @@ -144,7 +144,7 @@ func (r *reconcileManager) reconcileSubnets(ctx context.Context) error { } if len(combinedErrors) > 0 { - return fmt.Errorf(strings.Join(combinedErrors, "\n")) + return fmt.Errorf("%s", strings.Join(combinedErrors, "\n")) } return nil diff --git a/test/util/kubeadminkubeconfig/kubetoken.go b/test/util/kubeadminkubeconfig/kubetoken.go index c3051864fa3..7386a4a4950 100644 --- a/test/util/kubeadminkubeconfig/kubetoken.go +++ b/test/util/kubeadminkubeconfig/kubetoken.go @@ -27,7 +27,7 @@ func parseTokenResponse(location string) (string, error) { } if v.Get("error") != "" { - return "", fmt.Errorf(v.Get("error_description")) + return "", fmt.Errorf("%s", v.Get("error_description")) } v, err = url.ParseQuery(locURL.Fragment) @@ -36,7 +36,7 @@ func parseTokenResponse(location string) (string, error) { } if v.Get("error") != "" { - return "", fmt.Errorf(v.Get("error_description")) + return "", fmt.Errorf("%s", v.Get("error_description")) } return v.Get("access_token"), nil