From fdd5357d78b98a52c7fc6dc9fefe2dc94a1270f7 Mon Sep 17 00:00:00 2001 From: Kacper Rzetelski Date: Tue, 26 Mar 2024 23:04:30 +0100 Subject: [PATCH 1/2] Update go version to 1.22 --- .github/workflows/releases.yaml | 2 +- Dockerfile | 2 +- Makefile | 2 +- go.mod | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/releases.yaml b/.github/workflows/releases.yaml index 01e9144d6ad..da605fd64e4 100644 --- a/.github/workflows/releases.yaml +++ b/.github/workflows/releases.yaml @@ -18,7 +18,7 @@ on: required: true env: - go_version: '1.21' + go_version: '1.22' defaults: run: diff --git a/Dockerfile b/Dockerfile index 56d43242791..701f2278c10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/scylladb/scylla-operator-images:golang-1.21 AS builder +FROM quay.io/scylladb/scylla-operator-images:golang-1.22 AS builder WORKDIR /go/src/github.com/scylladb/scylla-operator COPY . . RUN make build --warn-undefined-variables diff --git a/Makefile b/Makefile index f7725147998..21b1b243242 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ IMAGE_TAG ?= latest IMAGE_REF ?= docker.io/scylladb/scylla-operator:$(IMAGE_TAG) MAKE_REQUIRED_MIN_VERSION:=4.2 # for SHELLSTATUS -GO_REQUIRED_MIN_VERSION ?=1.21 +GO_REQUIRED_MIN_VERSION ?=1.22 GIT_TAG ?=$(shell git describe --long --tags --abbrev=7 --match 'v[0-9]*')$(if $(filter $(.SHELLSTATUS),0),,$(error git describe failed)) GIT_TAG_SHORT ?=$(shell git describe --tags --abbrev=7 --match 'v[0-9]*')$(if $(filter $(.SHELLSTATUS),0),,$(error git describe failed)) diff --git a/go.mod b/go.mod index b4c5c310b58..28204870737 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/scylladb/scylla-operator -go 1.21.8 +go 1.22.1 require ( cloud.google.com/go/compute/metadata v0.2.3 From 60b8dc78340641bda51c46f2dfad044b2bf5fb80 Mon Sep 17 00:00:00 2001 From: Kacper Rzetelski Date: Tue, 26 Mar 2024 23:25:07 +0100 Subject: [PATCH 2/2] Accommodate Go 1.22's loopvar fix and ranging over integers --- .../validation/cluster_validation_test.go | 4 +--- .../validation/nodeconfig_validation_test.go | 6 ++---- pkg/assets/template.go | 2 +- pkg/auth/auth_test.go | 4 +--- pkg/cmd/generateapireference/run_test.go | 1 - pkg/cmd/operator/gather_test.go | 1 - pkg/cmd/operator/mustgather_test.go | 1 - pkg/cmd/operator/webhooks_test.go | 3 +-- pkg/cmd/releasenotes/helpers_test.go | 3 +-- pkg/cmd/releasenotes/render_test.go | 3 +-- pkg/controller/manager/controller.go | 2 +- pkg/controller/manager/sync_test.go | 9 +++------ pkg/controller/manager/types_old_test.go | 4 ---- pkg/controller/nodeconfig/controller.go | 2 +- pkg/controller/nodeconfigpod/controller.go | 2 +- pkg/controller/nodetune/tune_test.go | 6 ++---- pkg/controller/orphanedpv/controller.go | 2 +- pkg/controller/scyllacluster/controller.go | 2 +- pkg/controller/scyllacluster/resource_test.go | 7 ++----- .../scylladbmonitoring/controller.go | 2 +- .../scyllaoperatorconfig/controller.go | 2 +- pkg/controllerhelpers/apps_test.go | 3 +-- pkg/controllerhelpers/scylla_test.go | 12 ++++-------- pkg/crypto/certcreators_test.go | 2 -- pkg/disks/block_test.go | 3 +-- pkg/disks/fs_test.go | 3 +-- pkg/disks/loop_test.go | 6 ++---- pkg/disks/raid_test.go | 6 ++---- pkg/gather/collect/collect_test.go | 1 - pkg/gather/collect/printer_test.go | 1 - pkg/kubecrypto/certs_test.go | 1 - pkg/naming/names_test.go | 4 +--- pkg/resourceapply/apps_test.go | 6 ++---- pkg/resourceapply/core_test.go | 18 ++++++------------ pkg/resourceapply/discovery_test.go | 3 +-- pkg/resourceapply/helpers_test.go | 5 ++--- pkg/resourceapply/networking_test.go | 3 +-- pkg/resourceapply/policy_test.go | 3 +-- pkg/resourceapply/rbac_test.go | 9 +++------ pkg/sidecar/config/config_test.go | 4 +--- pkg/sidecar/identity/member_test.go | 3 +-- pkg/util/algorithms/math_test.go | 4 +--- pkg/util/blkutils/lsblk_test.go | 12 ++++-------- pkg/util/cpuset/mask_test.go | 6 ++---- pkg/util/duration/duration_string.go | 2 +- pkg/util/losetup/losetup_test.go | 3 +-- pkg/util/parallel/parallel.go | 4 ++-- .../e2e/set/nodeconfig/nodeconfig_disksetup.go | 2 +- .../e2e/set/scyllacluster/scyllacluster_tls.go | 1 - test/e2e/utils/datainserter.go | 2 +- 50 files changed, 65 insertions(+), 135 deletions(-) diff --git a/pkg/api/scylla/validation/cluster_validation_test.go b/pkg/api/scylla/validation/cluster_validation_test.go index 06daa293860..a6e60724f77 100644 --- a/pkg/api/scylla/validation/cluster_validation_test.go +++ b/pkg/api/scylla/validation/cluster_validation_test.go @@ -437,9 +437,7 @@ func TestValidateScyllaCluster(t *testing.T) { }, } - for i := range tests { - test := tests[i] - + for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/api/scylla/validation/nodeconfig_validation_test.go b/pkg/api/scylla/validation/nodeconfig_validation_test.go index 30916d57477..612a663b7fe 100644 --- a/pkg/api/scylla/validation/nodeconfig_validation_test.go +++ b/pkg/api/scylla/validation/nodeconfig_validation_test.go @@ -121,8 +121,7 @@ func TestValidateNodeConfig(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -269,8 +268,7 @@ func TestValidateNodeConfigUpdate(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/assets/template.go b/pkg/assets/template.go index d009f555ba2..092e3bc304d 100644 --- a/pkg/assets/template.go +++ b/pkg/assets/template.go @@ -47,7 +47,7 @@ func IndentNext(spaceCount int, s string) string { func Repeat(s string, count int) string { var sb strings.Builder sb.Grow(len(s) * count) - for i := 0; i < count; i++ { + for range count { sb.WriteString(s) } return sb.String() diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go index 1a8d064495d..8a66668fd3a 100644 --- a/pkg/auth/auth_test.go +++ b/pkg/auth/auth_test.go @@ -46,9 +46,7 @@ func TestParseBearerAuth(t *testing.T) { }, } - for i := range table { - test := table[i] - + for _, test := range table { t.Run(test.Name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/generateapireference/run_test.go b/pkg/cmd/generateapireference/run_test.go index 3f129496c41..3e3ae3164a1 100644 --- a/pkg/cmd/generateapireference/run_test.go +++ b/pkg/cmd/generateapireference/run_test.go @@ -123,7 +123,6 @@ func TestIndexNestedProps(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/operator/gather_test.go b/pkg/cmd/operator/gather_test.go index 5655ce23cd9..370040d55ef 100644 --- a/pkg/cmd/operator/gather_test.go +++ b/pkg/cmd/operator/gather_test.go @@ -135,7 +135,6 @@ metadata: } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/operator/mustgather_test.go b/pkg/cmd/operator/mustgather_test.go index 821bf5ba42b..68058093f3e 100644 --- a/pkg/cmd/operator/mustgather_test.go +++ b/pkg/cmd/operator/mustgather_test.go @@ -321,7 +321,6 @@ status: {} } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/operator/webhooks_test.go b/pkg/cmd/operator/webhooks_test.go index 94b659ebd27..c39c555b199 100644 --- a/pkg/cmd/operator/webhooks_test.go +++ b/pkg/cmd/operator/webhooks_test.go @@ -76,8 +76,7 @@ func TestWebhookOptionsRun(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.Name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/releasenotes/helpers_test.go b/pkg/cmd/releasenotes/helpers_test.go index 54bf1ac620d..9903d0b15f8 100644 --- a/pkg/cmd/releasenotes/helpers_test.go +++ b/pkg/cmd/releasenotes/helpers_test.go @@ -36,8 +36,7 @@ func TestParsePullRequestNumber(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.Name, func(t *testing.T) { t.Parallel() diff --git a/pkg/cmd/releasenotes/render_test.go b/pkg/cmd/releasenotes/render_test.go index e1bad776a8c..7011059f249 100644 --- a/pkg/cmd/releasenotes/render_test.go +++ b/pkg/cmd/releasenotes/render_test.go @@ -33,8 +33,7 @@ func TestCleanupPRTitle(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.Name, func(t *testing.T) { t.Parallel() diff --git a/pkg/controller/manager/controller.go b/pkg/controller/manager/controller.go index 0b5d017eee4..dc0ee9f33a6 100644 --- a/pkg/controller/manager/controller.go +++ b/pkg/controller/manager/controller.go @@ -181,7 +181,7 @@ func (c *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/controller/manager/sync_test.go b/pkg/controller/manager/sync_test.go index 0dd0977f337..8bfce57d63e 100644 --- a/pkg/controller/manager/sync_test.go +++ b/pkg/controller/manager/sync_test.go @@ -420,8 +420,7 @@ func TestManagerSynchronization(t *testing.T) { }, } - for i := range tcs { - test := tcs[i] + for _, test := range tcs { t.Run(test.Name, func(t *testing.T) { ctx := context.Background() cluster := &scyllav1.ScyllaCluster{ @@ -496,8 +495,7 @@ func TestBackupTaskChanged(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.name, func(t *testing.T) { t.Parallel() @@ -536,8 +534,7 @@ func TestRepairTaskChanged(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/controller/manager/types_old_test.go b/pkg/controller/manager/types_old_test.go index 8e8f1e92922..a4612f0222b 100644 --- a/pkg/controller/manager/types_old_test.go +++ b/pkg/controller/manager/types_old_test.go @@ -125,7 +125,6 @@ func TestRepairTask_ToManager(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -209,7 +208,6 @@ func TestRepairTask_FromManager(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -303,7 +301,6 @@ func TestBackupTask_ToManager(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -395,7 +392,6 @@ func TestBackupTask_FromManager(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/controller/nodeconfig/controller.go b/pkg/controller/nodeconfig/controller.go index d731372699c..0ced0b8b7eb 100644 --- a/pkg/controller/nodeconfig/controller.go +++ b/pkg/controller/nodeconfig/controller.go @@ -370,7 +370,7 @@ func (ncc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/controller/nodeconfigpod/controller.go b/pkg/controller/nodeconfigpod/controller.go index 63c008ad609..48e3f217434 100644 --- a/pkg/controller/nodeconfigpod/controller.go +++ b/pkg/controller/nodeconfigpod/controller.go @@ -318,7 +318,7 @@ func (ncpc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/controller/nodetune/tune_test.go b/pkg/controller/nodetune/tune_test.go index 608d252938b..e4e7a492329 100644 --- a/pkg/controller/nodetune/tune_test.go +++ b/pkg/controller/nodetune/tune_test.go @@ -43,8 +43,7 @@ func TestStripContainerID(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.name, func(t *testing.T) { t.Parallel() @@ -185,8 +184,7 @@ func TestGetIRQCPUs(t *testing.T) { expectedCpuSet: "0-5", }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/controller/orphanedpv/controller.go b/pkg/controller/orphanedpv/controller.go index 9548156e0c8..409d3d52e5f 100644 --- a/pkg/controller/orphanedpv/controller.go +++ b/pkg/controller/orphanedpv/controller.go @@ -177,7 +177,7 @@ func (opc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { opc.wg.Add(1) go func() { defer opc.wg.Done() diff --git a/pkg/controller/scyllacluster/controller.go b/pkg/controller/scyllacluster/controller.go index 6605769eaac..b84c1b4de8b 100644 --- a/pkg/controller/scyllacluster/controller.go +++ b/pkg/controller/scyllacluster/controller.go @@ -290,7 +290,7 @@ func (scc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/controller/scyllacluster/resource_test.go b/pkg/controller/scyllacluster/resource_test.go index cde27274f53..5bf9cea1f93 100644 --- a/pkg/controller/scyllacluster/resource_test.go +++ b/pkg/controller/scyllacluster/resource_test.go @@ -1475,7 +1475,6 @@ func TestStatefulSetForRack(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -2008,8 +2007,7 @@ func TestMakeIngresses(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -2648,8 +2646,7 @@ func TestMakeJobs(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/controller/scylladbmonitoring/controller.go b/pkg/controller/scylladbmonitoring/controller.go index f055a06a730..0eb3a1697eb 100644 --- a/pkg/controller/scylladbmonitoring/controller.go +++ b/pkg/controller/scylladbmonitoring/controller.go @@ -543,7 +543,7 @@ func (smc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { wg.Add(1) go func() { defer wg.Done() diff --git a/pkg/controller/scyllaoperatorconfig/controller.go b/pkg/controller/scyllaoperatorconfig/controller.go index 431b297a113..38113ab8b46 100644 --- a/pkg/controller/scyllaoperatorconfig/controller.go +++ b/pkg/controller/scyllaoperatorconfig/controller.go @@ -177,7 +177,7 @@ func (opc *Controller) Run(ctx context.Context, workers int) { return } - for i := 0; i < workers; i++ { + for range workers { opc.wg.Add(1) go func() { defer opc.wg.Done() diff --git a/pkg/controllerhelpers/apps_test.go b/pkg/controllerhelpers/apps_test.go index e557a6244e3..e40d074a22d 100644 --- a/pkg/controllerhelpers/apps_test.go +++ b/pkg/controllerhelpers/apps_test.go @@ -260,8 +260,7 @@ func TestIsStatefulSetRolledOut(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() got, gotErr := IsStatefulSetRolledOut(tc.sts) diff --git a/pkg/controllerhelpers/scylla_test.go b/pkg/controllerhelpers/scylla_test.go index d96ed4a78af..704210b5d92 100644 --- a/pkg/controllerhelpers/scylla_test.go +++ b/pkg/controllerhelpers/scylla_test.go @@ -306,8 +306,7 @@ func TestFindNodeConfigCondition(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -391,8 +390,7 @@ func TestGetScyllaHost(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -567,8 +565,7 @@ func TestGetScyllaNodeBroadcastAddress(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -756,8 +753,7 @@ func TestGetRequiredScyllaHosts(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/crypto/certcreators_test.go b/pkg/crypto/certcreators_test.go index e52bb2a47e2..64a4d1af5e3 100644 --- a/pkg/crypto/certcreators_test.go +++ b/pkg/crypto/certcreators_test.go @@ -76,8 +76,6 @@ func TestX509CertCreator_MakeCertificate(t *testing.T) { }, } for _, tc := range tt { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/disks/block_test.go b/pkg/disks/block_test.go index 89860ad43f7..0a7ab9e04ce 100644 --- a/pkg/disks/block_test.go +++ b/pkg/disks/block_test.go @@ -78,8 +78,7 @@ func TestGetBlockSize(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/disks/fs_test.go b/pkg/disks/fs_test.go index 8ec1e71b929..1c129805bd0 100644 --- a/pkg/disks/fs_test.go +++ b/pkg/disks/fs_test.go @@ -83,8 +83,7 @@ func TestMakeFS(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/disks/loop_test.go b/pkg/disks/loop_test.go index abb26199f5a..f7deb25fbef 100644 --- a/pkg/disks/loop_test.go +++ b/pkg/disks/loop_test.go @@ -233,8 +233,7 @@ func TestApplyLoopDevice(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -538,8 +537,7 @@ func TestDeleteLoopDevice(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/disks/raid_test.go b/pkg/disks/raid_test.go index 9e6aa9899a5..33aa59a5a2b 100644 --- a/pkg/disks/raid_test.go +++ b/pkg/disks/raid_test.go @@ -301,8 +301,7 @@ func TestMakeRAID0(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -498,8 +497,7 @@ func TestGetRAIDDeviceWithName(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/gather/collect/collect_test.go b/pkg/gather/collect/collect_test.go index 181cc12f3c7..e6c543cef17 100644 --- a/pkg/gather/collect/collect_test.go +++ b/pkg/gather/collect/collect_test.go @@ -528,7 +528,6 @@ metadata: } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/gather/collect/printer_test.go b/pkg/gather/collect/printer_test.go index 3695c5bffb8..baf1744c8c8 100644 --- a/pkg/gather/collect/printer_test.go +++ b/pkg/gather/collect/printer_test.go @@ -54,7 +54,6 @@ status: {} }, } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/kubecrypto/certs_test.go b/pkg/kubecrypto/certs_test.go index 2bc32c654d1..88a1d1f0f12 100644 --- a/pkg/kubecrypto/certs_test.go +++ b/pkg/kubecrypto/certs_test.go @@ -723,7 +723,6 @@ func Test_makeCertificate(t *testing.T) { }, } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/naming/names_test.go b/pkg/naming/names_test.go index dda0b87fa83..85de5587b86 100644 --- a/pkg/naming/names_test.go +++ b/pkg/naming/names_test.go @@ -48,9 +48,7 @@ func Test_ImageToVersion(t *testing.T) { }, } - for i := range tcs { - tc := tcs[i] - + for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/resourceapply/apps_test.go b/pkg/resourceapply/apps_test.go index a4c107fd3e7..2e96b0fedca 100644 --- a/pkg/resourceapply/apps_test.go +++ b/pkg/resourceapply/apps_test.go @@ -592,7 +592,6 @@ func TestApplyStatefulSet(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -605,7 +604,7 @@ func TestApplyStatefulSet(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -1093,7 +1092,6 @@ func TestApplyDaemonSet(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -1106,7 +1104,7 @@ func TestApplyDaemonSet(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/resourceapply/core_test.go b/pkg/resourceapply/core_test.go index 565c1739a2d..afe4df8f90e 100644 --- a/pkg/resourceapply/core_test.go +++ b/pkg/resourceapply/core_test.go @@ -468,7 +468,6 @@ func TestApplyService(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -481,7 +480,7 @@ func TestApplyService(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -1004,7 +1003,6 @@ func TestApplySecret(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -1017,7 +1015,7 @@ func TestApplySecret(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -1551,7 +1549,6 @@ func TestApplyServiceAccount(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -1564,7 +1561,7 @@ func TestApplyServiceAccount(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -2038,7 +2035,6 @@ func TestApplyConfigMap(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -2051,7 +2047,7 @@ func TestApplyConfigMap(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -2488,7 +2484,6 @@ func TestApplyNamespace(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -2501,7 +2496,7 @@ func TestApplyNamespace(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -2976,7 +2971,6 @@ func TestApplyEndpoints(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -2989,7 +2983,7 @@ func TestApplyEndpoints(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/resourceapply/discovery_test.go b/pkg/resourceapply/discovery_test.go index 3c37ff650e2..a65bfefa28e 100644 --- a/pkg/resourceapply/discovery_test.go +++ b/pkg/resourceapply/discovery_test.go @@ -409,7 +409,6 @@ func TestApplyEndpointSlice(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -422,7 +421,7 @@ func TestApplyEndpointSlice(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/resourceapply/helpers_test.go b/pkg/resourceapply/helpers_test.go index 421c0bcb5f5..6f4d83136b9 100644 --- a/pkg/resourceapply/helpers_test.go +++ b/pkg/resourceapply/helpers_test.go @@ -48,8 +48,7 @@ func TestDeepHashObject(t *testing.T) { return map[string]interface{}{"Hello": map[string]interface{}{"Yumiko": &A{1, "1"}}} }}, } - for i := range tests { - test := tests[i] + for _, test := range tests { t.Run(test.Name, func(t *testing.T) { t.Parallel() @@ -57,7 +56,7 @@ func TestDeepHashObject(t *testing.T) { hashes := make(map[string]struct{}, 1) hashes[hashObjectsOrDie(f())] = struct{}{} - for i := 0; i < iterations; i++ { + for range iterations { hash := hashObjectsOrDie(f()) _, collision := hashes[hash] if !collision { diff --git a/pkg/resourceapply/networking_test.go b/pkg/resourceapply/networking_test.go index e1897dfd0f8..982b9c1fb3e 100644 --- a/pkg/resourceapply/networking_test.go +++ b/pkg/resourceapply/networking_test.go @@ -396,7 +396,6 @@ func TestApplyIngress(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -409,7 +408,7 @@ func TestApplyIngress(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/resourceapply/policy_test.go b/pkg/resourceapply/policy_test.go index f386398dbf6..16682687b76 100644 --- a/pkg/resourceapply/policy_test.go +++ b/pkg/resourceapply/policy_test.go @@ -464,7 +464,6 @@ func TestApplyPodDisruptionBudget(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -477,7 +476,7 @@ func TestApplyPodDisruptionBudget(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/resourceapply/rbac_test.go b/pkg/resourceapply/rbac_test.go index 2d3fa87c9c9..ec42a340290 100644 --- a/pkg/resourceapply/rbac_test.go +++ b/pkg/resourceapply/rbac_test.go @@ -411,7 +411,6 @@ func TestApplyClusterRole(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -424,7 +423,7 @@ func TestApplyClusterRole(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -907,7 +906,6 @@ func TestApplyClusterRoleBinding(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -920,7 +918,7 @@ func TestApplyClusterRoleBinding(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() @@ -1470,7 +1468,6 @@ func TestApplyRoleBinding(t *testing.T) { } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -1483,7 +1480,7 @@ func TestApplyRoleBinding(t *testing.T) { if tc.expectedErr != nil { iterations = 1 } - for i := 0; i < iterations; i++ { + for i := range iterations { t.Run("", func(t *testing.T) { ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second) defer ctxCancel() diff --git a/pkg/sidecar/config/config_test.go b/pkg/sidecar/config/config_test.go index ea27f364636..7791e512f12 100644 --- a/pkg/sidecar/config/config_test.go +++ b/pkg/sidecar/config/config_test.go @@ -171,7 +171,6 @@ key: } for _, tc := range tt { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -310,8 +309,7 @@ func TestScyllaArguments(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.Name, func(t *testing.T) { t.Parallel() diff --git a/pkg/sidecar/identity/member_test.go b/pkg/sidecar/identity/member_test.go index 75d6696a417..771177d2631 100644 --- a/pkg/sidecar/identity/member_test.go +++ b/pkg/sidecar/identity/member_test.go @@ -391,8 +391,7 @@ func TestMember_GetSeeds(t *testing.T) { }, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/util/algorithms/math_test.go b/pkg/util/algorithms/math_test.go index 263889262a4..5461b9e1c42 100644 --- a/pkg/util/algorithms/math_test.go +++ b/pkg/util/algorithms/math_test.go @@ -42,9 +42,7 @@ func TestMax(t *testing.T) { expectedMax: 9, }, } - for i := range tt { - tc := tt[i] - + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/util/blkutils/lsblk_test.go b/pkg/util/blkutils/lsblk_test.go index 98fe16eae92..0429a984789 100644 --- a/pkg/util/blkutils/lsblk_test.go +++ b/pkg/util/blkutils/lsblk_test.go @@ -64,8 +64,7 @@ func TestGetPartitionUUID(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -137,8 +136,7 @@ func TestIsBlockDevice(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -215,8 +213,7 @@ func TestGetBlockDevice(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -309,8 +306,7 @@ func TestListBlockDevices(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/util/cpuset/mask_test.go b/pkg/util/cpuset/mask_test.go index 0469a994d05..5024c62365d 100644 --- a/pkg/util/cpuset/mask_test.go +++ b/pkg/util/cpuset/mask_test.go @@ -22,8 +22,7 @@ func TestMask(t *testing.T) { {Mask: []uint32{0x000e3862}, Expected: "1,5-6,11-13,17-19"}, {Mask: []uint32{0x00000001, 0x00000001, 0x00010117}, Expected: "0-2,4,8,16,32,64"}, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.Expected, func(t *testing.T) { mask := ParseMaskFormat(test.Mask).String() if mask != test.Expected { @@ -67,8 +66,7 @@ func TestFormatMask(t *testing.T) { {CPUs: []int{1, 5, 6, 11, 12, 13, 17, 18, 19}, Expected: "0x000e3862"}, {CPUs: []int{0, 1, 2, 4, 8, 16, 32, 64}, Expected: "0x00000001,0x00000001,0x00010117"}, } - for i := range ts { - test := ts[i] + for _, test := range ts { t.Run(test.Expected, func(t *testing.T) { cpuset := NewCPUSet(test.CPUs...) mask := cpuset.FormatMask() diff --git a/pkg/util/duration/duration_string.go b/pkg/util/duration/duration_string.go index ded50076174..9dec99effad 100644 --- a/pkg/util/duration/duration_string.go +++ b/pkg/util/duration/duration_string.go @@ -119,7 +119,7 @@ func fmtFrac(buf []byte, v uint64, prec int) (nw int, nv uint64) { // Omit trailing zeros up to and including decimal point. w := len(buf) print := false - for i := 0; i < prec; i++ { + for range prec { digit := v % 10 print = print || digit != 0 if print { diff --git a/pkg/util/losetup/losetup_test.go b/pkg/util/losetup/losetup_test.go index 5bdc89c4730..9d8bf1cacc1 100644 --- a/pkg/util/losetup/losetup_test.go +++ b/pkg/util/losetup/losetup_test.go @@ -88,8 +88,7 @@ func TestListLoopDevices(t *testing.T) { }, } - for i := range tt { - tc := tt[i] + for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/util/parallel/parallel.go b/pkg/util/parallel/parallel.go index ebcd028e1a5..90624e8cdf7 100644 --- a/pkg/util/parallel/parallel.go +++ b/pkg/util/parallel/parallel.go @@ -10,14 +10,14 @@ func ForEach(length int, f func(i int) error) error { errCh := make(chan error, length) defer close(errCh) - for i := 0; i < length; i++ { + for i := range length { go func(i int) { errCh <- f(i) }(i) } errs := make([]error, 0, length) - for i := 0; i < length; i++ { + for range length { errs = append(errs, <-errCh) } diff --git a/test/e2e/set/nodeconfig/nodeconfig_disksetup.go b/test/e2e/set/nodeconfig/nodeconfig_disksetup.go index 25df7c0e8ef..70fd298583a 100644 --- a/test/e2e/set/nodeconfig/nodeconfig_disksetup.go +++ b/test/e2e/set/nodeconfig/nodeconfig_disksetup.go @@ -158,7 +158,7 @@ var _ = g.Describe("Node Setup", framework.Serial, func() { mountOptions := []string{"prjquota"} loopDeviceNames := make([]string, 0, numberOfDevices) - for i := 0; i < numberOfDevices; i++ { + for i := range numberOfDevices { loopDeviceNames = append(loopDeviceNames, fmt.Sprintf("disk-%d", i)) } diff --git a/test/e2e/set/scyllacluster/scyllacluster_tls.go b/test/e2e/set/scyllacluster/scyllacluster_tls.go index fbc097aea32..97d687d04b7 100644 --- a/test/e2e/set/scyllacluster/scyllacluster_tls.go +++ b/test/e2e/set/scyllacluster/scyllacluster_tls.go @@ -101,7 +101,6 @@ var _ = g.Describe("ScyllaCluster", func() { replicas: 1, }, } { - tc := tc func() { framework.By("Scaling the ScyllaCluster to %d replicas setting domains to %q", tc.replicas, tc.domains) sc.ManagedFields = nil diff --git a/test/e2e/utils/datainserter.go b/test/e2e/utils/datainserter.go index 3751187e819..90384efb069 100644 --- a/test/e2e/utils/datainserter.go +++ b/test/e2e/utils/datainserter.go @@ -54,7 +54,7 @@ func NewMultiDCDataInserter(dcHosts map[string][]string, options ...DataInserter PartKey: []string{"id"}, }) data := make([]*TestData, 0, nRows) - for i := 0; i < nRows; i++ { + for i := range nRows { data = append(data, &TestData{Id: i, Data: utilrand.String(32)}) }