Skip to content

Commit 90311ae

Browse files
authored
🐛 Add for new linters to fix old syntax (kubernetes-sigs#10699)
* add new linters Signed-off-by: sivchari <[email protected]> * apply for copyloopvar Signed-off-by: sivchari <[email protected]> * apply for intrange Signed-off-by: sivchari <[email protected]> * upgrade golangci-lint Signed-off-by: sivchari <[email protected]> * fix: intrange Signed-off-by: sivchari <[email protected]> * apply for gosec Signed-off-by: sivchari <[email protected]> * re-apply for copyloopvar Signed-off-by: sivchari <[email protected]> * re-apply for intrange Signed-off-by: sivchari <[email protected]> * delete exportloopref Signed-off-by: sivchari <[email protected]> * re-fix lint errors Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]>
1 parent 5b4fc70 commit 90311ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+52
-87
lines changed

.github/workflows/pr-golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ jobs:
3030
- name: golangci-lint
3131
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # tag=v6.0.1
3232
with:
33-
version: v1.57.2
33+
version: v1.59.0
3434
args: --out-format=colored-line-number
3535
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ linters:
1919
- bidichk
2020
- bodyclose
2121
- containedctx
22+
- copyloopvar
2223
- dogsled
2324
- dupword
2425
- durationcheck
2526
- errcheck
2627
- errchkjson
27-
- exportloopref
2828
- gci
2929
- ginkgolinter
3030
- goconst
@@ -38,6 +38,7 @@ linters:
3838
- govet
3939
- importas
4040
- ineffassign
41+
- intrange
4142
- loggercheck
4243
- misspell
4344
- nakedret

bootstrap/kubeadm/internal/cloudinit/controlplane_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func TestTemplateYAMLIndent(t *testing.T) {
4444
}
4545

4646
for _, tc := range testcases {
47-
tc := tc
4847
t.Run(tc.name, func(t *testing.T) {
4948
g := NewWithT(t)
5049

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestKubeadmConfigReconciler_MachineToBootstrapMapFuncReturn(t *testing.T) {
5858
objs := []client.Object{cluster}
5959
machineObjs := []client.Object{}
6060
var expectedConfigName string
61-
for i := 0; i < 3; i++ {
61+
for i := range 3 {
6262
configName := fmt.Sprintf("my-config-%d", i)
6363
m := builder.Machine(metav1.NamespaceDefault, fmt.Sprintf("my-machine-%d", i)).
6464
WithVersion("v1.19.1").
@@ -80,7 +80,7 @@ func TestKubeadmConfigReconciler_MachineToBootstrapMapFuncReturn(t *testing.T) {
8080
Client: fakeClient,
8181
SecretCachingClient: fakeClient,
8282
}
83-
for i := 0; i < 3; i++ {
83+
for i := range 3 {
8484
o := machineObjs[i]
8585
configs := reconciler.MachineToBootstrapMapFunc(ctx, o)
8686
if i == 1 {
@@ -675,7 +675,6 @@ func TestReconcileIfJoinCertificatesAvailableConditioninNodesAndControlPlaneIsRe
675675
}
676676

677677
for _, rt := range useCases {
678-
rt := rt // pin!
679678
t.Run(rt.name, func(t *testing.T) {
680679
g := NewWithT(t)
681680

@@ -753,7 +752,6 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
753752
}
754753

755754
for _, rt := range useCases {
756-
rt := rt // pin!
757755
t.Run(rt.name, func(t *testing.T) {
758756
g := NewWithT(t)
759757

@@ -1819,7 +1817,7 @@ func TestKubeadmConfigReconciler_ClusterToKubeadmConfigs(t *testing.T) {
18191817
cluster := builder.Cluster(metav1.NamespaceDefault, "my-cluster").Build()
18201818
objs := []client.Object{cluster}
18211819
expectedNames := []string{}
1822-
for i := 0; i < 3; i++ {
1820+
for i := range 3 {
18231821
configName := fmt.Sprintf("my-config-%d", i)
18241822
m := builder.Machine(metav1.NamespaceDefault, fmt.Sprintf("my-machine-%d", i)).
18251823
WithVersion("v1.19.1").

bootstrap/kubeadm/internal/ignition/clc/clc_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ func TestRender(t *testing.T) {
561561
}
562562

563563
for _, tt := range tc {
564-
tt := tt
565-
566564
t.Run(tt.desc, func(t *testing.T) {
567565
t.Parallel()
568566

bootstrap/kubeadm/internal/ignition/ignition_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ func Test_NewNode(t *testing.T) {
4242
}
4343

4444
for name, input := range cases {
45-
input := input
46-
4745
t.Run(name, func(t *testing.T) {
4846
t.Parallel()
4947

@@ -160,8 +158,6 @@ func Test_NewJoinControlPlane(t *testing.T) {
160158
}
161159

162160
for name, input := range cases {
163-
input := input
164-
165161
t.Run(name, func(t *testing.T) {
166162
t.Parallel()
167163

@@ -278,8 +274,6 @@ func Test_NewInitControlPlane(t *testing.T) {
278274
}
279275

280276
for name, input := range cases {
281-
input := input
282-
283277
t.Run(name, func(t *testing.T) {
284278
t.Parallel()
285279

bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func TestControlPlaneInitMutex_Lock(t *testing.T) {
9999
}
100100

101101
for _, tc := range tests {
102-
tc := tc
103102
t.Run(tc.name, func(t *testing.T) {
104103
gs := NewWithT(t)
105104

@@ -259,7 +258,6 @@ func TestControlPlaneInitMutex_UnLock(t *testing.T) {
259258
}
260259

261260
for _, tc := range tests {
262-
tc := tc
263261
t.Run(tc.name, func(t *testing.T) {
264262
gs := NewWithT(t)
265263

bootstrap/kubeadm/internal/webhooks/kubeadmconfigtemplate_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ func TestKubeadmConfigTemplateValidation(t *testing.T) {
8383
}
8484

8585
for name, tt := range cases {
86-
tt := tt
87-
8886
webhook := &KubeadmConfigTemplate{}
8987

9088
t.Run(name, func(t *testing.T) {

cmd/clusterctl/client/cluster/components.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ func (p *providerComponents) ValidateNoObjectsExist(ctx context.Context, provide
287287
// Filter the resources according to the delete options
288288
crsHavingObjects := []string{}
289289
for _, crd := range customResources.Items {
290-
crd := crd
291290
storageVersion, err := storageVersionForCRD(&crd)
292291
if err != nil {
293292
return err

cmd/clusterctl/client/cluster/mover.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (o *objectMover) move(ctx context.Context, graph *objectGraph, toProxy Prox
361361

362362
// Create all objects group by group, ensuring all the ownerReferences are re-created.
363363
log.Info("Creating objects in the target cluster")
364-
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
364+
for groupIndex := range len(moveSequence.groups) {
365365
if err := o.createGroup(ctx, moveSequence.getGroup(groupIndex), toProxy, mutators...); err != nil {
366366
return err
367367
}
@@ -419,7 +419,7 @@ func (o *objectMover) toDirectory(ctx context.Context, graph *objectGraph, direc
419419

420420
// Save all objects group by group
421421
log.Info(fmt.Sprintf("Saving files to %s", directory))
422-
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
422+
for groupIndex := range len(moveSequence.groups) {
423423
if err := o.backupGroup(ctx, moveSequence.getGroup(groupIndex), directory); err != nil {
424424
return err
425425
}
@@ -459,7 +459,7 @@ func (o *objectMover) fromDirectory(ctx context.Context, graph *objectGraph, toP
459459

460460
// Create all objects group by group, ensuring all the ownerReferences are re-created.
461461
log.Info("Restoring objects into the target cluster")
462-
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
462+
for groupIndex := range len(moveSequence.groups) {
463463
if err := o.restoreGroup(ctx, moveSequence.getGroup(groupIndex), toProxy); err != nil {
464464
return err
465465
}

0 commit comments

Comments
 (0)