From e85914fc0d2875ded8cdefe8d019b37f481a9001 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 26 Apr 2024 10:49:26 +0200 Subject: [PATCH] build: address 'intrange' linter warning golangci-lint warns about this: for loop can be changed to use an integer range (Go 1.22+) (intrange) Signed-off-by: Niels de Vos --- e2e/cephfs.go | 20 ++++++++++---------- e2e/nfs.go | 20 ++++++++++---------- e2e/rbd.go | 14 +++++++------- e2e/rbd_helper.go | 8 ++++---- e2e/utils.go | 18 +++++++++--------- internal/health-checker/filechecker_test.go | 2 +- internal/health-checker/statchecker_test.go | 4 ++-- internal/rbd/rbd_attach.go | 2 +- internal/rbd/rbd_util_test.go | 2 +- internal/util/reftracker/reftracker_test.go | 2 +- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index a0779fd26..97f953b10 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -874,7 +874,7 @@ var _ = Describe(cephfsType, func() { } app.Namespace = f.UniqueName // create PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err = createPVCAndApp(name, f, pvc, app, deployTimeout) if err != nil { @@ -889,7 +889,7 @@ var _ = Describe(cephfsType, func() { validateSubvolumeCount(f, totalCount, fileSystemName, subvolumegroup) validateOmapCount(f, totalCount, cephfsType, metadataPool, volumesType) // delete PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err = deletePVCAndApp(name, f, pvc, app) if err != nil { @@ -1452,7 +1452,7 @@ var _ = Describe(cephfsType, func() { snap.Namespace = f.UniqueName snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name // create snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createSnapshot(&s, deployTimeout) @@ -1488,7 +1488,7 @@ var _ = Describe(cephfsType, func() { // create multiple PVC from same snapshot wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout) @@ -1520,7 +1520,7 @@ var _ = Describe(cephfsType, func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1548,7 +1548,7 @@ var _ = Describe(cephfsType, func() { // create clones from different snapshots and bind it to an // app wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1581,7 +1581,7 @@ var _ = Describe(cephfsType, func() { wg.Add(totalCount) // delete snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = deleteSnapshot(&s, deployTimeout) @@ -1605,7 +1605,7 @@ var _ = Describe(cephfsType, func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -2308,7 +2308,7 @@ var _ = Describe(cephfsType, func() { appClone.Namespace = f.UniqueName wg.Add(totalCount) // create clone and bind it to an app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout) @@ -2340,7 +2340,7 @@ var _ = Describe(cephfsType, func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name diff --git a/e2e/nfs.go b/e2e/nfs.go index afc86ed6e..d185f8c98 100644 --- a/e2e/nfs.go +++ b/e2e/nfs.go @@ -528,7 +528,7 @@ var _ = Describe("nfs", func() { } app.Namespace = f.UniqueName // create PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err = createPVCAndApp(name, f, pvc, app, deployTimeout) if err != nil { @@ -542,7 +542,7 @@ var _ = Describe("nfs", func() { validateSubvolumeCount(f, totalCount, fileSystemName, defaultSubvolumegroup) // delete PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err = deletePVCAndApp(name, f, pvc, app) if err != nil { @@ -699,7 +699,7 @@ var _ = Describe("nfs", func() { snap.Namespace = f.UniqueName snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name // create snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createSnapshot(&s, deployTimeout) @@ -736,7 +736,7 @@ var _ = Describe("nfs", func() { // create multiple PVC from same snapshot wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout) @@ -790,7 +790,7 @@ var _ = Describe("nfs", func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -817,7 +817,7 @@ var _ = Describe("nfs", func() { validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType) // create clones from different snapshots and bind it to an app wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -872,7 +872,7 @@ var _ = Describe("nfs", func() { wg.Add(totalCount) // delete snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = deleteSnapshot(&s, deployTimeout) @@ -896,7 +896,7 @@ var _ = Describe("nfs", func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -980,7 +980,7 @@ var _ = Describe("nfs", func() { appClone.Labels = label wg.Add(totalCount) // create clone and bind it to an app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout) @@ -1036,7 +1036,7 @@ var _ = Describe("nfs", func() { wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name diff --git a/e2e/rbd.go b/e2e/rbd.go index 171015697..394ff3240 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -2721,7 +2721,7 @@ var _ = Describe("RBD", func() { } app.Namespace = f.UniqueName // create PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err := createPVCAndApp(name, f, pvc, app, deployTimeout) if err != nil { @@ -2733,7 +2733,7 @@ var _ = Describe("RBD", func() { validateRBDImageCount(f, totalCount, defaultRBDPool) validateOmapCount(f, totalCount, rbdType, defaultRBDPool, volumesType) // delete PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) err := deletePVCAndApp(name, f, pvc, app) if err != nil { @@ -3316,7 +3316,7 @@ var _ = Describe("RBD", func() { appClone.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcClone.Name // create PVC and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) label := map[string]string{ "app": name, @@ -3329,7 +3329,7 @@ var _ = Describe("RBD", func() { } } - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) opt := metav1.ListOptions{ LabelSelector: "app=" + name, @@ -3348,7 +3348,7 @@ var _ = Describe("RBD", func() { } // delete app - for i := 0; i < totalCount; i++ { + for i := range totalCount { name := fmt.Sprintf("%s%d", f.UniqueName, i) appClone.Name = name err = deletePod(appClone.Name, appClone.Namespace, f.ClientSet, deployTimeout) @@ -3552,7 +3552,7 @@ var _ = Describe("RBD", func() { // validate created backend rbd images validateRBDImageCount(f, 1, defaultRBDPool) validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - for i := 0; i < snapChainDepth; i++ { + for i := range snapChainDepth { var pvcClone, smartClonePVC *v1.PersistentVolumeClaim snap := getSnapshot(snapshotPath) snap.Name = fmt.Sprintf("%s-%d", snap.Name, i) @@ -3722,7 +3722,7 @@ var _ = Describe("RBD", func() { validateRBDImageCount(f, 1, defaultRBDPool) validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - for i := 0; i < cloneChainDepth; i++ { + for i := range cloneChainDepth { var pvcClone *v1.PersistentVolumeClaim pvcClone, err = loadPVC(pvcSmartClonePath) if err != nil { diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 8d86a3ce1..dd247b8cb 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -377,7 +377,7 @@ func validateCloneInDifferentPool(f *framework.Framework, snapshotPool, cloneSc, snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name // create snapshot wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createSnapshot(&s, deployTimeout) @@ -416,7 +416,7 @@ func validateCloneInDifferentPool(f *framework.Framework, snapshotPool, cloneSc, pvcClone.Spec.DataSource.Name = fmt.Sprintf("%s%d", f.UniqueName, 0) // create multiple PVCs from same snapshot wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout) @@ -440,7 +440,7 @@ func validateCloneInDifferentPool(f *framework.Framework, snapshotPool, cloneSc, } wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -464,7 +464,7 @@ func validateCloneInDifferentPool(f *framework.Framework, snapshotPool, cloneSc, wg.Add(totalCount) // delete snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = deleteSnapshot(&s, deployTimeout) diff --git a/e2e/utils.go b/e2e/utils.go index ce0f89d21..e316363f8 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -927,7 +927,7 @@ func validatePVCClone( appClone.Namespace = f.UniqueName wg.Add(totalCount) // create clone and bind it to an app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) label := make(map[string]string) @@ -1020,7 +1020,7 @@ func validatePVCClone( validateRBDImageCount(f, totalCloneCount, defaultRBDPool) wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1131,7 +1131,7 @@ func validatePVCSnapshot( wg.Add(totalCount) // create snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) wgErrs[n] = createSnapshot(&s, deployTimeout) @@ -1189,7 +1189,7 @@ func validatePVCSnapshot( // create multiple PVC from same snapshot wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) label := make(map[string]string) @@ -1267,7 +1267,7 @@ func validatePVCSnapshot( validateRBDImageCount(f, totalCloneCount, defaultRBDPool) wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1294,7 +1294,7 @@ func validatePVCSnapshot( // create clones from different snapshots and bind it to an // app wg.Add(totalCount) - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1334,7 +1334,7 @@ func validatePVCSnapshot( validateRBDImageCount(f, totalSnapCount, defaultRBDPool) wg.Add(totalCount) // delete snapshot - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, s snapapi.VolumeSnapshot) { s.Name = fmt.Sprintf("%s%d", f.UniqueName, n) content := &snapapi.VolumeSnapshotContent{} @@ -1388,7 +1388,7 @@ func validatePVCSnapshot( validateRBDImageCount(f, totalCount, defaultRBDPool) wg.Add(totalCount) // delete clone and app - for i := 0; i < totalCount; i++ { + for i := range totalCount { go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) { name := fmt.Sprintf("%s%d", f.UniqueName, n) p.Spec.DataSource.Name = name @@ -1814,7 +1814,7 @@ func checkExports(f *framework.Framework, clusterID, clientString string) bool { } found := false - for i := 0; i < len(*exportList); i++ { + for i := range len(*exportList) { export := (*exportList)[i] for _, client := range export.Clients { for _, address := range client.Addresses { diff --git a/internal/health-checker/filechecker_test.go b/internal/health-checker/filechecker_test.go index 3c67c5b84..39a2f27ec 100644 --- a/internal/health-checker/filechecker_test.go +++ b/internal/health-checker/filechecker_test.go @@ -41,7 +41,7 @@ func TestFileChecker(t *testing.T) { t.Error("checker failed to start") } - for i := 0; i < 10; i++ { + for range 10 { // check health, should be healthy healthy, msg := checker.isHealthy() if !healthy || msg != nil { diff --git a/internal/health-checker/statchecker_test.go b/internal/health-checker/statchecker_test.go index 4ea247803..5c43c3541 100644 --- a/internal/health-checker/statchecker_test.go +++ b/internal/health-checker/statchecker_test.go @@ -41,11 +41,11 @@ func TestStatChecker(t *testing.T) { t.Error("checker failed to start") } - for i := 0; i < 10; i++ { + for i := range 10 { // check health, should be healthy healthy, msg := checker.isHealthy() if !healthy || msg != nil { - t.Error("volume is unhealthy") + t.Errorf("volume is unhealthy after %d tries", i+1) } time.Sleep(time.Second) diff --git a/internal/rbd/rbd_attach.go b/internal/rbd/rbd_attach.go index 36ba2d77b..a9e1ba434 100644 --- a/internal/rbd/rbd_attach.go +++ b/internal/rbd/rbd_attach.go @@ -210,7 +210,7 @@ func findDeviceMappingImage(ctx context.Context, pool, namespace, image string, // Stat a path, if it doesn't exist, retry maxRetries times. func waitForPath(ctx context.Context, pool, namespace, image string, maxRetries int, useNbdDriver bool) (string, bool) { - for i := 0; i < maxRetries; i++ { + for i := range maxRetries { if i != 0 { time.Sleep(time.Second) } diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index 45dc1ce1a..905e97707 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -249,7 +249,7 @@ func TestStrategicActionOnLogFile(t *testing.T) { tmpDir := t.TempDir() var logFile [3]string - for i := 0; i < 3; i++ { + for i := range 3 { f, err := os.CreateTemp(tmpDir, "rbd-*.log") if err != nil { t.Errorf("creating tempfile failed: %v", err) diff --git a/internal/util/reftracker/reftracker_test.go b/internal/util/reftracker/reftracker_test.go index 66e4e7ffd..ffd66b0c0 100644 --- a/internal/util/reftracker/reftracker_test.go +++ b/internal/util/reftracker/reftracker_test.go @@ -244,7 +244,7 @@ func TestRTRemove(t *testing.T) { "ref3": reftype.Normal, } - for i := 0; i < 2; i++ { + for range 2 { created, err := Add(ioctx, rtName, refsToAdd) require.NoError(ts, err) require.True(ts, created)