diff --git a/Dockerfiles/Dockerfile b/Dockerfiles/Dockerfile index 9fa7b5a22de..2782ee25a5b 100644 --- a/Dockerfiles/Dockerfile +++ b/Dockerfiles/Dockerfile @@ -1,3 +1,6 @@ +# Build the manager binary +ARG GOLANG_VERSION=1.22 + ################################################################################ FROM registry.access.redhat.com/ubi8/toolbox as manifests ARG USE_LOCAL=false @@ -12,7 +15,7 @@ RUN if [ "${USE_LOCAL}" != "true" ]; then \ fi ################################################################################ -FROM registry.access.redhat.com/ubi8/go-toolset:latest as builder +FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder ARG CGO_ENABLED=1 USER root WORKDIR /workspace diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index e43e7313b2f..a93f4cb675b 100644 --- a/components/kserve/kserve_config_handler.go +++ b/components/kserve/kserve_config_handler.go @@ -109,7 +109,6 @@ func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client return fmt.Errorf("failed to list pods: %w", err) } for _, pod := range podList.Items { - pod := pod if err := cli.Delete(ctx, &pod); err != nil { return fmt.Errorf("failed to delete pod %s: %w", pod.Name, err) } diff --git a/controllers/secretgenerator/secret.go b/controllers/secretgenerator/secret.go index dd9aa60c532..948f7021cdb 100644 --- a/controllers/secretgenerator/secret.go +++ b/controllers/secretgenerator/secret.go @@ -90,7 +90,7 @@ func generateSecretValue(secret *Secret) error { switch secret.Type { case "random": randomValue := make([]byte, secret.Complexity) - for i := 0; i < secret.Complexity; i++ { + for i := range secret.Complexity { num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letterRunes)))) if err != nil { return err diff --git a/controllers/secretgenerator/secret_test.go b/controllers/secretgenerator/secret_test.go index 2d6b5dfb842..5bfdfd2676e 100644 --- a/controllers/secretgenerator/secret_test.go +++ b/controllers/secretgenerator/secret_test.go @@ -92,7 +92,6 @@ func TestNewSecret(t *testing.T) { } for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { secret, err := secretgenerator.NewSecretFrom(tc.annotations) if err != nil { diff --git a/pkg/upgrade/uninstallation.go b/pkg/upgrade/uninstallation.go index 0618fd7be45..4701866285a 100644 --- a/pkg/upgrade/uninstallation.go +++ b/pkg/upgrade/uninstallation.go @@ -48,7 +48,6 @@ func OperatorUninstall(ctx context.Context, cli client.Client, platform cluster. } for _, namespace := range generatedNamespaces.Items { - namespace := namespace if namespace.Status.Phase == corev1.NamespaceActive { if err := cli.Delete(ctx, &namespace); err != nil { return fmt.Errorf("error deleting namespace %v: %w", namespace.Name, err) @@ -95,7 +94,6 @@ func removeDSCInitialization(ctx context.Context, cli client.Client) error { var multiErr *multierror.Error for _, dsciInstance := range instanceList.Items { - dsciInstance := dsciInstance if err := cli.Delete(ctx, &dsciInstance); !k8serr.IsNotFound(err) { multiErr = multierror.Append(multiErr, err) } diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 48c7fd17068..8486f843648 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -320,7 +320,6 @@ func deleteOneResource(ctx context.Context, c client.Client, res ResourceSpec) e } for _, item := range list.Items { - item := item v, ok, err := unstructured.NestedString(item.Object, res.Path...) if err != nil { return fmt.Errorf("failed to get field %v for %s %s/%s: %w", res.Path, res.Gvk.Kind, res.Namespace, item.GetName(), err) @@ -352,7 +351,7 @@ func deleteDeprecatedResources(ctx context.Context, cli client.Client, namespace multiErr = multierror.Append(multiErr, err) } items := reflect.ValueOf(resourceType).Elem().FieldByName("Items") - for i := 0; i < items.Len(); i++ { + for i := range items.Len() { item := items.Index(i).Addr().Interface().(client.Object) //nolint:errcheck,forcetypeassert for _, name := range resourceList { if name == item.GetName() { @@ -383,7 +382,6 @@ func deleteDeprecatedServiceMonitors(ctx context.Context, cli client.Client, nam } for _, servicemonitor := range servicemonitors.Items { - servicemonitor := servicemonitor for _, name := range resourceList { if name == servicemonitor.Name { log.Info("Attempting to delete " + servicemonitor.Name + " in namespace " + namespace) diff --git a/tests/e2e/creation_test.go b/tests/e2e/creation_test.go index 2a2abc3cd2b..1da9e5ce5df 100644 --- a/tests/e2e/creation_test.go +++ b/tests/e2e/creation_test.go @@ -290,7 +290,6 @@ func (tc *testContext) testAllComponentCreation(t *testing.T) error { //nolint:f } for _, c := range components { - c := c name := c.GetComponentName() t.Run("Validate "+name, func(t *testing.T) { t.Parallel() diff --git a/tests/e2e/deletion_test.go b/tests/e2e/deletion_test.go index bb7caa7ada2..20f0f5afcf7 100644 --- a/tests/e2e/deletion_test.go +++ b/tests/e2e/deletion_test.go @@ -95,7 +95,6 @@ func (tc *testContext) testAllApplicationDeletion(t *testing.T) error { //nolint } for _, c := range components { - c := c t.Run("Delete "+c.GetComponentName(), func(t *testing.T) { t.Parallel() err = tc.testComponentDeletion(c) diff --git a/tests/e2e/helper_test.go b/tests/e2e/helper_test.go index 62d9e92b24a..c12edd096ed 100644 --- a/tests/e2e/helper_test.go +++ b/tests/e2e/helper_test.go @@ -249,7 +249,7 @@ func getCSV(ctx context.Context, cli client.Client, name string, namespace strin } // do not use range Items to avoid pointer to the loop variable - for i := 0; i < len(csvList.Items); i++ { + for i := range len(csvList.Items) { csv := &csvList.Items[i] if isMatched(csv, name) { return csv, nil @@ -409,7 +409,6 @@ func ensureServicemeshOperators(t *testing.T, tc *testContext) error { //nolint: c := make(chan error) for _, op := range ops { - op := op // to avoid loop variable in the closures t.Logf("Ensuring %s is installed", op) go func(op string) { err := ensureOperator(tc, op, servicemeshNamespace) @@ -417,7 +416,7 @@ func ensureServicemeshOperators(t *testing.T, tc *testContext) error { //nolint: }(op) } - for i := 0; i < len(ops); i++ { + for range len(ops) { err := <-c errors = multierror.Append(errors, err) } diff --git a/tests/envtestutil/cleaner.go b/tests/envtestutil/cleaner.go index b858cbe3a65..3a81a8a59fa 100644 --- a/tests/envtestutil/cleaner.go +++ b/tests/envtestutil/cleaner.go @@ -43,7 +43,6 @@ func CreateCleaner(c client.Client, config *rest.Config, timeout, interval time. func (c *Cleaner) DeleteAll(ctx context.Context, objects ...client.Object) { for _, obj := range objects { - obj := obj Expect(client.IgnoreNotFound(c.client.Delete(ctx, obj))).Should(Succeed()) if ns, ok := obj.(*corev1.Namespace); ok {