Skip to content

Commit

Permalink
build: address 'intrange' linter warning
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Apr 29, 2024
1 parent 0e7b06e commit e85914f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
20 changes: 10 additions & 10 deletions e2e/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions e2e/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions e2e/rbd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/health-checker/filechecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/health-checker/statchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/rbd/rbd_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit e85914f

Please sign in to comment.