From b61cbd48fcb624c77fe0bcdf755d575faf501349 Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 14 Aug 2024 11:53:02 +0800 Subject: [PATCH] chore: fix staticcheck errors (#7966) --- controllers/apps/configuration/config_util.go | 2 +- .../configuration/configuration_controller.go | 2 +- .../extensions/addon_controller_stages.go | 2 +- pkg/controller/instanceset/instance_util.go | 2 +- .../instanceset/instance_util_test.go | 4 ++-- pkg/kb_agent/handlers/errors.go | 2 +- pkg/lorry/client/httpclient.go | 2 +- pkg/lorry/client/httpclient_test.go | 24 +++++++++---------- pkg/lorry/engines/models/errors.go | 14 +++++------ 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/controllers/apps/configuration/config_util.go b/controllers/apps/configuration/config_util.go index 43c072ae41f..3ead690645f 100644 --- a/controllers/apps/configuration/config_util.go +++ b/controllers/apps/configuration/config_util.go @@ -337,7 +337,7 @@ func validateConfigTemplate(cli client.Client, ctx intctrlutil.RequestCtx, confi if !validateConfigConstraintStatus(configConstraint.Status) { errMsg := fmt.Sprintf("Configuration template CR[%s] status not ready! current status: %s", configConstraint.Name, configConstraint.Status.Phase) logger.V(1).Info(errMsg) - return false, fmt.Errorf(errMsg) + return false, fmt.Errorf("%s", errMsg) } } return true, nil diff --git a/controllers/apps/configuration/configuration_controller.go b/controllers/apps/configuration/configuration_controller.go index 42615c6e9a9..5ad037c0aaf 100644 --- a/controllers/apps/configuration/configuration_controller.go +++ b/controllers/apps/configuration/configuration_controller.go @@ -127,7 +127,7 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques func (r *ConfigurationReconciler) failWithInvalidComponent(configuration *appsv1alpha1.Configuration, reqCtx intctrlutil.RequestCtx) (ctrl.Result, error) { msg := fmt.Sprintf("not found cluster component or cluster definition component: [%s]", configuration.Spec.ComponentName) - reqCtx.Log.Error(fmt.Errorf(msg), "") + reqCtx.Log.Error(fmt.Errorf("%s", msg), "") patch := client.MergeFrom(configuration.DeepCopy()) configuration.Status.Message = msg if err := r.Client.Status().Patch(reqCtx.Ctx, configuration, patch); err != nil { diff --git a/controllers/extensions/addon_controller_stages.go b/controllers/extensions/addon_controller_stages.go index cddd44674d4..f41bd32fff7 100644 --- a/controllers/extensions/addon_controller_stages.go +++ b/controllers/extensions/addon_controller_stages.go @@ -1148,7 +1148,7 @@ func getKubeBlocksDeploy(ctx context.Context, r *AddonReconciler) (*v1.Deploymen client.MatchingLabelsSelector{Selector: labelSelector}); err != nil { return nil, err } - if deploys.Items == nil || len(deploys.Items) == 0 { + if len(deploys.Items) == 0 { return nil, fmt.Errorf("there is no KubeBlocks deployment, please check your cluster") } if len(deploys.Items) > 1 { diff --git a/pkg/controller/instanceset/instance_util.go b/pkg/controller/instanceset/instance_util.go index e3b53508a49..919f28daefb 100644 --- a/pkg/controller/instanceset/instance_util.go +++ b/pkg/controller/instanceset/instance_util.go @@ -313,7 +313,7 @@ func GenerateInstanceNamesWithOrdinalList(parentName, templateName string, if int32(len(instanceNameList)) != replicas { errorMessage := fmt.Sprintf("for template '%s', expected %d instance names but generated %d: [%s]", templateName, replicas, len(instanceNameList), strings.Join(instanceNameList, ", ")) - return instanceNameList, fmt.Errorf(errorMessage) + return instanceNameList, fmt.Errorf("%s", errorMessage) } return instanceNameList, nil } diff --git a/pkg/controller/instanceset/instance_util_test.go b/pkg/controller/instanceset/instance_util_test.go index fbd2e5bfcd2..df3756e2a7a 100644 --- a/pkg/controller/instanceset/instance_util_test.go +++ b/pkg/controller/instanceset/instance_util_test.go @@ -620,8 +620,8 @@ var _ = Describe("instance util test", func() { offlineInstances := []string{"foo-bar-1", "foo-0", "foo-bar-3"} instanceNameList, err := GenerateAllInstanceNames(parentName, 5, templates, offlineInstances, defaultTemplateOrdinals) errInstanceNameListExpected := []string{"foo-bar-0", "foo-bar-2"} - errExpected := fmt.Errorf(fmt.Sprintf("for template '%s', expected %d instance names but generated %d: [%s]", - templateBar.Name, *templateBar.Replicas, len(errInstanceNameListExpected), strings.Join(errInstanceNameListExpected, ", "))) + errExpected := fmt.Errorf("for template '%s', expected %d instance names but generated %d: [%s]", + templateBar.Name, *templateBar.Replicas, len(errInstanceNameListExpected), strings.Join(errInstanceNameListExpected, ", ")) Expect(instanceNameList).Should(BeNil()) Expect(err).Should(Equal(errExpected)) }) diff --git a/pkg/kb_agent/handlers/errors.go b/pkg/kb_agent/handlers/errors.go index 00c20e1d5e4..c1f6ef84ae9 100644 --- a/pkg/kb_agent/handlers/errors.go +++ b/pkg/kb_agent/handlers/errors.go @@ -26,5 +26,5 @@ const ( ) var ( - ErrNotImplemented = fmt.Errorf(errMsgNotImplemented) + ErrNotImplemented = fmt.Errorf("%s", errMsgNotImplemented) ) diff --git a/pkg/lorry/client/httpclient.go b/pkg/lorry/client/httpclient.go index be09c7d914e..3fc8e13c733 100644 --- a/pkg/lorry/client/httpclient.go +++ b/pkg/lorry/client/httpclient.go @@ -174,7 +174,7 @@ func (cli *HTTPClient) Request(ctx context.Context, operation, method string, re if err != nil { return nil, err } - return nil, fmt.Errorf(string(msg)) + return nil, fmt.Errorf("%s", string(msg)) } } diff --git a/pkg/lorry/client/httpclient_test.go b/pkg/lorry/client/httpclient_test.go index bd566af1638..c1a4d1f91dd 100644 --- a/pkg/lorry/client/httpclient_test.go +++ b/pkg/lorry/client/httpclient_test.go @@ -165,7 +165,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().GetReplicaRole(gomock.Any(), gomock.Any()).Return(string(""), fmt.Errorf(msg)) + mockDBManager.EXPECT().GetReplicaRole(gomock.Any(), gomock.Any()).Return(string(""), fmt.Errorf("%s", msg)) mockDCSStore.EXPECT().GetClusterFromCache().Return(&dcs.Cluster{}) role, err := lorryClient.GetRole(context.TODO()) Expect(err).Should(HaveOccurred()) @@ -197,7 +197,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().ListSystemAccounts(gomock.Any()).Return(nil, fmt.Errorf(msg)) + mockDBManager.EXPECT().ListSystemAccounts(gomock.Any()).Return(nil, fmt.Errorf("%s", msg)) accounts, err := lorryClient.ListSystemAccounts(context.TODO()) Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -221,7 +221,7 @@ var _ = Describe("Lorry HTTP Client", func() { It("not implemented", func() { mockDBManager.EXPECT().DescribeUser(gomock.Any(), gomock.Any()).Return(nil, nil) - mockDBManager.EXPECT().CreateUser(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().CreateUser(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.CreateUser(context.TODO(), "user-test", "password-test", "", "") Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -242,7 +242,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().DeleteUser(gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().DeleteUser(gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.DeleteUser(context.TODO(), "user-test") Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -269,7 +269,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().DescribeUser(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf(msg)) + mockDBManager.EXPECT().DescribeUser(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("%s", msg)) _, err := lorryClient.DescribeUser(context.TODO(), "user-test") Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -290,7 +290,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().GrantUserRole(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().GrantUserRole(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.GrantUserRole(context.TODO(), "user-test", "readwrite") Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -311,7 +311,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().RevokeUserRole(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().RevokeUserRole(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.RevokeUserRole(context.TODO(), "user-test", "readwrite") Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -341,7 +341,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().ListUsers(gomock.Any()).Return(nil, fmt.Errorf(msg)) + mockDBManager.EXPECT().ListUsers(gomock.Any()).Return(nil, fmt.Errorf("%s", msg)) users, err := lorryClient.ListUsers(context.TODO()) Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -383,7 +383,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().JoinCurrentMemberToCluster(gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().JoinCurrentMemberToCluster(gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) mockDCSStore.EXPECT().GetCluster().Return(cluster, nil) err := lorryClient.JoinMember(context.TODO()) Expect(err).Should(HaveOccurred()) @@ -470,7 +470,7 @@ var _ = Describe("Lorry HTTP Client", func() { It("not implemented", func() { mockDBManager.EXPECT().GetCurrentMemberName().Return(podName).Times(2) - mockDBManager.EXPECT().LeaveMemberFromCluster(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().LeaveMemberFromCluster(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) mockDCSStore.EXPECT().GetCluster().Return(cluster, nil) mockDCSStore.EXPECT().UpdateHaConfig().Return(nil) err := lorryClient.LeaveMember(context.TODO()) @@ -624,7 +624,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().Lock(gomock.Any(), gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().Lock(gomock.Any(), gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.Lock(context.TODO()) Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) @@ -681,7 +681,7 @@ var _ = Describe("Lorry HTTP Client", func() { }) It("not implemented", func() { - mockDBManager.EXPECT().Unlock(gomock.Any()).Return(fmt.Errorf(msg)) + mockDBManager.EXPECT().Unlock(gomock.Any()).Return(fmt.Errorf("%s", msg)) err := lorryClient.Unlock(context.TODO()) Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring(msg)) diff --git a/pkg/lorry/engines/models/errors.go b/pkg/lorry/engines/models/errors.go index 47d7f4e1538..fc4fbe10ba2 100644 --- a/pkg/lorry/engines/models/errors.go +++ b/pkg/lorry/engines/models/errors.go @@ -32,11 +32,11 @@ const ( ) var ( - ErrNoSQL = fmt.Errorf(errMsgNoSQL) - ErrNoUserName = fmt.Errorf(errMsgNoUserName) - ErrNoPassword = fmt.Errorf(errMsgNoPassword) - ErrNoRoleName = fmt.Errorf(errMsgNoRoleName) - ErrInvalidRoleName = fmt.Errorf(errMsgInvalidRoleName) - ErrNoSuchUser = fmt.Errorf(errMsgNoSuchUser) - ErrNotImplemented = fmt.Errorf(errMsgNotImplemented) + ErrNoSQL = fmt.Errorf("%s", errMsgNoSQL) + ErrNoUserName = fmt.Errorf("%s", errMsgNoUserName) + ErrNoPassword = fmt.Errorf("%s", errMsgNoPassword) + ErrNoRoleName = fmt.Errorf("%s", errMsgNoRoleName) + ErrInvalidRoleName = fmt.Errorf("%s", errMsgInvalidRoleName) + ErrNoSuchUser = fmt.Errorf("%s", errMsgNoSuchUser) + ErrNotImplemented = fmt.Errorf("%s", errMsgNotImplemented) )