Skip to content

Commit

Permalink
chore: fix staticcheck errors (#7966)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf authored Aug 14, 2024
1 parent 07b3018 commit b61cbd4
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion controllers/apps/configuration/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/configuration/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion controllers/extensions/addon_controller_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/instanceset/instance_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/instanceset/instance_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/kb_agent/handlers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ const (
)

var (
ErrNotImplemented = fmt.Errorf(errMsgNotImplemented)
ErrNotImplemented = fmt.Errorf("%s", errMsgNotImplemented)
)
2 changes: 1 addition & 1 deletion pkg/lorry/client/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
24 changes: 12 additions & 12 deletions pkg/lorry/client/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions pkg/lorry/engines/models/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit b61cbd4

Please sign in to comment.