From 1d3d1c663812e52b94409c62c267a3fbfb802f1c Mon Sep 17 00:00:00 2001 From: Gerard Ryan Date: Wed, 27 Nov 2024 14:06:42 +0000 Subject: [PATCH 1/2] chore: Update to Go 1.22 --- Dockerfiles/Dockerfile | 5 +---- Dockerfiles/toolbox.Dockerfile | 2 +- Makefile | 2 +- README.md | 2 +- go.mod | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Dockerfiles/Dockerfile b/Dockerfiles/Dockerfile index a74e73a1135..9fa7b5a22de 100644 --- a/Dockerfiles/Dockerfile +++ b/Dockerfiles/Dockerfile @@ -1,6 +1,3 @@ -# Build the manager binary -ARG GOLANG_VERSION=1.21 - ################################################################################ FROM registry.access.redhat.com/ubi8/toolbox as manifests ARG USE_LOCAL=false @@ -15,7 +12,7 @@ RUN if [ "${USE_LOCAL}" != "true" ]; then \ fi ################################################################################ -FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder +FROM registry.access.redhat.com/ubi8/go-toolset:latest as builder ARG CGO_ENABLED=1 USER root WORKDIR /workspace diff --git a/Dockerfiles/toolbox.Dockerfile b/Dockerfiles/toolbox.Dockerfile index 47d86713fdf..0af3f30c732 100644 --- a/Dockerfiles/toolbox.Dockerfile +++ b/Dockerfiles/toolbox.Dockerfile @@ -1,6 +1,6 @@ FROM registry.fedoraproject.org/fedora-toolbox:38 -ARG GOLANG_VERSION=1.21 +ARG GOLANG_VERSION=1.22.9 ARG OPERATOR_SDK_VERSION=1.31.0 ENV GOLANG_VERSION=$GOLANG_VERSION \ diff --git a/Makefile b/Makefile index b2a83540ed3..4b68cf8552c 100644 --- a/Makefile +++ b/Makefile @@ -348,7 +348,7 @@ catalog-build: opm ## Build a catalog image. catalog-push: ## Push a catalog image. $(MAKE) image-push IMG=$(CATALOG_IMG) -TOOLBOX_GOLANG_VERSION := 1.21 +TOOLBOX_GOLANG_VERSION := 1.22.9 # Generate a Toolbox container for locally testing changes easily .PHONY: toolbox diff --git a/README.md b/README.md index 576fdd79a18..81d5a01e628 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Additionally installing `Authorino operator` & `Service Mesh operator` enhances #### Pre-requisites -- Go version **go1.21** +- Go version **go1.22** - operator-sdk version can be updated to **v1.31.1** #### Download manifests diff --git a/go.mod b/go.mod index 9b86d8e92c2..7264ed4a2c6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/opendatahub-io/opendatahub-operator/v2 -go 1.21 +go 1.22 require ( github.com/blang/semver/v4 v4.0.0 From 07b1ad5ebbc19ac72b1424b86eaed15bd1795dec Mon Sep 17 00:00:00 2001 From: Gerard Ryan Date: Wed, 27 Nov 2024 23:34:03 +0000 Subject: [PATCH 2/2] chore: fix golangci-lint errors on 1.22 --- Dockerfiles/Dockerfile | 5 ++++- components/kserve/kserve_config_handler.go | 1 - controllers/secretgenerator/secret.go | 2 +- controllers/secretgenerator/secret_test.go | 1 - pkg/upgrade/uninstallation.go | 2 -- pkg/upgrade/upgrade.go | 4 +--- tests/e2e/creation_test.go | 1 - tests/e2e/deletion_test.go | 1 - tests/e2e/helper_test.go | 5 ++--- tests/envtestutil/cleaner.go | 1 - 10 files changed, 8 insertions(+), 15 deletions(-) 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 {