Skip to content

Commit ea2d967

Browse files
committed
Fix lint errors: errcheck, modernize/rangeint, modernize/any
Signed-off-by: shunki-fujita <shunki-fujita@cybozu.co.jp>
1 parent 1972569 commit ea2d967

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

clustering/manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ var _ = Describe("manager", func() {
11501150
}).Should(Succeed())
11511151

11521152
// Verify ALTER USER RETAIN was called on all 3 instances for all users.
1153-
for i := 0; i < 3; i++ {
1153+
for i := range 3 {
11541154
users := of.getRotatedUsers(cluster.PodHostname(i))
11551155
Expect(users).To(HaveLen(len(constants.MocoUsers)),
11561156
"instance %d should have rotated all users", i)
@@ -1222,14 +1222,14 @@ var _ = Describe("manager", func() {
12221222
}).Should(Succeed())
12231223

12241224
// Verify DISCARD OLD PASSWORD was called on all 3 instances for all users.
1225-
for i := 0; i < 3; i++ {
1225+
for i := range 3 {
12261226
users := of.getDiscardedUsers(cluster.PodHostname(i))
12271227
Expect(users).To(HaveLen(len(constants.MocoUsers)),
12281228
"instance %d should have discarded all users", i)
12291229
}
12301230

12311231
// Verify auth plugin migration was called (users had mysql_native_password, target is caching_sha2_password).
1232-
for i := 0; i < 3; i++ {
1232+
for i := range 3 {
12331233
users := of.getMigratedUsers(cluster.PodHostname(i))
12341234
Expect(users).To(HaveLen(len(constants.MocoUsers)),
12351235
"instance %d should have migrated all users", i)

clustering/password_rotation.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ func (p *managerProcess) handleRotatingPhase(ctx context.Context, ss *StatusSet,
8383
// rotateInstanceUsers provides idempotency).
8484
retainStarted := string(sourceSecret.Data[password.RetainStartedKey]) == cr.Status.RotationID
8585
if !retainStarted {
86-
for idx := 0; idx < replicas; idx++ {
86+
for idx := range replicas {
8787
op, err := p.dbf.New(ctx, cluster, currentPasswd, idx)
8888
if err != nil {
8989
return false, err
9090
}
9191
dualFound, dualUser, checkErr := checkInstanceDualPasswords(ctx, op, idx)
92-
op.Close()
92+
_ = op.Close()
9393
if checkErr != nil {
9494
return false, checkErr
9595
}
@@ -118,18 +118,18 @@ func (p *managerProcess) handleRotatingPhase(ctx context.Context, ss *StatusSet,
118118
}
119119
primaryIndex := cluster.Status.CurrentPrimaryIndex
120120

121-
for idx := 0; idx < replicas; idx++ {
121+
for idx := range replicas {
122122
isReplica := idx != primaryIndex
123123
op, err := p.dbf.New(ctx, cluster, currentPasswd, idx)
124124
if err != nil {
125125
return false, err
126126
}
127127

128128
if err := rotateInstanceUsers(ctx, op, pendingMap, idx, isReplica); err != nil {
129-
op.Close()
129+
_ = op.Close()
130130
return false, err
131131
}
132-
op.Close()
132+
_ = op.Close()
133133
log.Info("completed ALTER USER RETAIN for instance", "instance", idx, "rotationID", cr.Status.RotationID)
134134
}
135135

@@ -206,7 +206,7 @@ func (p *managerProcess) handleDiscardingPhase(ctx context.Context, ss *StatusSe
206206
if err != nil {
207207
return "", err
208208
}
209-
defer op.Close()
209+
defer func() { _ = op.Close() }()
210210
return op.GetAuthPlugin(ctx)
211211
}()
212212
if err != nil {
@@ -215,18 +215,18 @@ func (p *managerProcess) handleDiscardingPhase(ctx context.Context, ss *StatusSe
215215
log.Info("determined target auth plugin for migration", "authPlugin", authPlugin, "rotationID", cr.Status.RotationID)
216216

217217
// Execute DISCARD OLD PASSWORD + auth plugin migration on all instances.
218-
for idx := 0; idx < replicas; idx++ {
218+
for idx := range replicas {
219219
isReplica := idx != primaryIndex
220220
op, err := p.dbf.New(ctx, cluster, pendingPasswd, idx)
221221
if err != nil {
222222
return false, err
223223
}
224224

225225
if err := discardInstanceUsers(ctx, op, pendingMap, idx, isReplica, authPlugin); err != nil {
226-
op.Close()
226+
_ = op.Close()
227227
return false, err
228228
}
229-
op.Close()
229+
_ = op.Close()
230230
log.Info("applied DISCARD OLD PASSWORD and auth plugin migration for instance", "instance", idx, "rotationID", cr.Status.RotationID)
231231
}
232232

cmd/kubectl-moco/cmd/credential.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func credentialRotate(ctx context.Context, clusterName string) error {
150150
}
151151

152152
newGen := cr.Spec.RotationGeneration + 1
153-
patch, err := json.Marshal(map[string]interface{}{
154-
"spec": map[string]interface{}{
153+
patch, err := json.Marshal(map[string]any{
154+
"spec": map[string]any{
155155
"rotationGeneration": newGen,
156156
"discardOldPassword": false,
157157
},
@@ -179,8 +179,8 @@ func credentialDiscard(ctx context.Context, clusterName string) error {
179179
return fmt.Errorf("cannot discard: phase must be Rotated, currently %q", cr.Status.Phase)
180180
}
181181

182-
patch, err := json.Marshal(map[string]interface{}{
183-
"spec": map[string]interface{}{
182+
patch, err := json.Marshal(map[string]any{
183+
"spec": map[string]any{
184184
"discardOldPassword": true,
185185
},
186186
})

pkg/dbop/password.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func validateMocoUser(user string) error {
4444
func closeDirtyConn(ctx context.Context, conn *sql.Conn) {
4545
if _, err := conn.ExecContext(ctx, "SET sql_log_bin=1"); err != nil {
4646
// Mark the connection as bad so the pool discards it.
47-
_ = conn.Raw(func(driverConn interface{}) error {
47+
_ = conn.Raw(func(driverConn any) error {
4848
return driver.ErrBadConn
4949
})
5050
}
51-
conn.Close()
51+
_ = conn.Close()
5252
}
5353

5454
// GetAuthPlugin returns the default authentication plugin for the first factor

0 commit comments

Comments
 (0)