From dbe0d670b23786203045d4479273619b51148aad Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Wed, 13 Dec 2023 15:38:57 +0100 Subject: [PATCH 1/2] Bump Go to 1.21.5 --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 2 +- Makefile | 2 +- Tiltfile | 6 +++--- hack/ensure-go.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index dc8c2f1ae2b6..64ad95822737 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -30,5 +30,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # tag=v3.6.0 with: - version: v1.53.3 + version: v1.55.2 working-directory: ${{matrix.working-directory}} diff --git a/.golangci.yml b/.golangci.yml index 6af1f0ddce21..7249ade91bcf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ run: timeout: 10m - go: "1.20" + go: "1.21" build-tags: - tools - e2e diff --git a/Makefile b/Makefile index e77065b74a4a..92c0390ed554 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ SHELL:=/usr/bin/env bash # # Go. # -GO_VERSION ?= 1.20.12 +GO_VERSION ?= 1.21.5 GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION) # Use GOPROXY environment variable if set diff --git a/Tiltfile b/Tiltfile index 8426af5b37f6..c33221860be5 100644 --- a/Tiltfile +++ b/Tiltfile @@ -184,9 +184,9 @@ def load_provider_tiltfiles(): tilt_helper_dockerfile_header = """ # Tilt image -FROM golang:1.20.12 as tilt-helper +FROM golang:1.21.5 as tilt-helper # Install delve. Note this should be kept in step with the Go release minor version. -RUN go install github.com/go-delve/delve/cmd/dlv@v1.20 +RUN go install github.com/go-delve/delve/cmd/dlv@v1.21 # Support live reloading with Tilt RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com/tilt-dev/rerun-process-wrapper/master/restart.sh && \ wget --output-document /start.sh --quiet https://raw.githubusercontent.com/tilt-dev/rerun-process-wrapper/master/start.sh && \ @@ -195,7 +195,7 @@ RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com """ tilt_dockerfile_header = """ -FROM golang:1.20.12 as tilt +FROM golang:1.21.5 as tilt WORKDIR / COPY --from=tilt-helper /process.txt . COPY --from=tilt-helper /start.sh . diff --git a/hack/ensure-go.sh b/hack/ensure-go.sh index d19b6cd596c5..96f0567f86c5 100755 --- a/hack/ensure-go.sh +++ b/hack/ensure-go.sh @@ -38,7 +38,7 @@ EOF local go_version IFS=" " read -ra go_version <<< "$(go version)" local minimum_go_version - minimum_go_version=go1.20 + minimum_go_version=go1.21 if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then cat < Date: Wed, 14 Feb 2024 19:40:29 +0100 Subject: [PATCH 2/2] Fix linter findings --- .golangci.yml | 9 ++++++++- cmd/clusterctl/client/move.go | 4 ++-- exp/runtime/hooks/api/v1alpha1/discovery_types.go | 2 +- exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go | 2 +- .../machinedeployment/machinedeployment_controller.go | 4 ++-- internal/topology/check/compatibility.go | 3 ++- internal/webhooks/cluster.go | 3 ++- test/framework/machinedeployment_helpers.go | 3 ++- .../controllers/inmemorymachine_controller_test.go | 2 +- test/infrastructure/inmemory/internal/server/mux_test.go | 2 +- util/version/version.go | 4 ++-- 11 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7249ade91bcf..3672e3744152 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -211,7 +211,8 @@ linters-settings: # - name: bool-literal-in-expr - name: constant-logical-expr - + goconst: + ignore-tests: true issues: max-same-issues: 0 max-issues-per-linter: 0 @@ -323,3 +324,9 @@ issues: - gocritic text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop" path: _test\.go + # Note: We only found issues with memory aliasing after backporting Go 1.21 and a new golangci-lint version. + # Let's not waste time fixing memory aliasing in unit tests on this branch. + - linters: + - gosec + text: "G601: Implicit memory aliasing in for loop" + path: _test\.go diff --git a/cmd/clusterctl/client/move.go b/cmd/clusterctl/client/move.go index 38617143237c..e2bf322501b8 100644 --- a/cmd/clusterctl/client/move.go +++ b/cmd/clusterctl/client/move.go @@ -69,9 +69,9 @@ func (c *clusterctlClient) Move(options MoveOptions) error { return c.toDirectory(options) } else if options.FromDirectory != "" { return c.fromDirectory(options) - } else { - return c.move(options) } + + return c.move(options) } func (c *clusterctlClient) move(options MoveOptions) error { diff --git a/exp/runtime/hooks/api/v1alpha1/discovery_types.go b/exp/runtime/hooks/api/v1alpha1/discovery_types.go index 840dd2986061..276833ec15d0 100644 --- a/exp/runtime/hooks/api/v1alpha1/discovery_types.go +++ b/exp/runtime/hooks/api/v1alpha1/discovery_types.go @@ -100,7 +100,7 @@ func init() { "Runtime Extension implementers must use this hook to inform the Cluster API runtime about all the handlers " + "that are defined in an external component implementing Runtime Extensions.\n" + "\n" + - "Notes:\n" + + "Notes:\n" + //nolint:goconst "- When using Runtime SDK utils, a handler for this hook is automatically generated", Singleton: true, }) diff --git a/exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go b/exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go index 3293b10877b0..fa91a2e6635a 100644 --- a/exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go +++ b/exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go @@ -204,7 +204,7 @@ func init() { "all the objects which are part of a Cluster's topology are going to be created.\n" + "\n" + "Notes:\n" + - "- This hook will be called only for Clusters with a managed topology\n" + + "- This hook will be called only for Clusters with a managed topology\n" + //nolint:goconst "- The call's request contains the Cluster object\n" + "- This is a blocking hook; Runtime Extension implementers can use this hook to execute\n" + "tasks before the objects which are part of a Cluster's topology are created", diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 51ecf28da6b5..84c8095ef976 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -362,8 +362,8 @@ func (r *Reconciler) getMachineDeploymentsForMachineSet(ctx context.Context, ms } deployments := make([]*clusterv1.MachineDeployment, 0, len(dList.Items)) - for idx, d := range dList.Items { - selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector) + for idx := range dList.Items { + selector, err := metav1.LabelSelectorAsSelector(&dList.Items[idx].Spec.Selector) if err != nil { continue } diff --git a/internal/topology/check/compatibility.go b/internal/topology/check/compatibility.go index 13dac608b845..b38b59003720 100644 --- a/internal/topology/check/compatibility.go +++ b/internal/topology/check/compatibility.go @@ -343,7 +343,8 @@ func ClusterClassReferencesAreValid(clusterClass *clusterv1.ClusterClass) field. allErrs = append(allErrs, LocalObjectTemplateIsValid(clusterClass.Spec.ControlPlane.MachineInfrastructure, clusterClass.Namespace, field.NewPath("spec", "controlPlane", "machineInfrastructure"))...) } - for i, mdc := range clusterClass.Spec.Workers.MachineDeployments { + for i := range clusterClass.Spec.Workers.MachineDeployments { + mdc := clusterClass.Spec.Workers.MachineDeployments[i] allErrs = append(allErrs, LocalObjectTemplateIsValid(&mdc.Template.Bootstrap, clusterClass.Namespace, field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "bootstrap"))...) allErrs = append(allErrs, LocalObjectTemplateIsValid(&mdc.Template.Infrastructure, clusterClass.Namespace, diff --git a/internal/webhooks/cluster.go b/internal/webhooks/cluster.go index 9bce93a80e7a..32be58ddbd09 100644 --- a/internal/webhooks/cluster.go +++ b/internal/webhooks/cluster.go @@ -428,7 +428,8 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust } if cluster.Spec.Topology.Workers != nil { - for i, md := range cluster.Spec.Topology.Workers.MachineDeployments { + for i := range cluster.Spec.Topology.Workers.MachineDeployments { + md := cluster.Spec.Topology.Workers.MachineDeployments[i] if md.MachineHealthCheck != nil { fldPath := field.NewPath("spec", "topology", "workers", "machineDeployments", "machineHealthCheck").Index(i) diff --git a/test/framework/machinedeployment_helpers.go b/test/framework/machinedeployment_helpers.go index b0fd5b25079c..46f59abe0752 100644 --- a/test/framework/machinedeployment_helpers.go +++ b/test/framework/machinedeployment_helpers.go @@ -152,7 +152,8 @@ func AssertMachineDeploymentFailureDomains(ctx context.Context, input AssertMach return input.Lister.List(ctx, ms, client.InNamespace(input.Cluster.Namespace), client.MatchingLabels(selectorMap)) }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to list MachineSets for Cluster %s", klog.KObj(input.Cluster)) - for _, machineSet := range ms.Items { + for i := range ms.Items { + machineSet := ms.Items[i] machineSetFD := pointer.StringDeref(machineSet.Spec.Template.Spec.FailureDomain, "") Expect(machineSetFD).To(Equal(machineDeploymentFD), "MachineSet %s is in the %q failure domain, expecting %q", machineSet.Name, machineSetFD, machineDeploymentFD) diff --git a/test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller_test.go b/test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller_test.go index eea1c6bc7fc0..70643ba4d280 100644 --- a/test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller_test.go +++ b/test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller_test.go @@ -313,7 +313,7 @@ func TestReconcileNormalEtcd(t *testing.T) { manager := cmanager.New(scheme) - host := "127.0.0.1" //nolint:goconst + host := "127.0.0.1" wcmux, err := server.NewWorkloadClustersMux(manager, host, server.CustomPorts{ // NOTE: make sure to use ports different than other tests, so we can run tests in parallel MinPort: server.DefaultMinPort + 1000, diff --git a/test/infrastructure/inmemory/internal/server/mux_test.go b/test/infrastructure/inmemory/internal/server/mux_test.go index 7072df7a9518..914ad30ff055 100644 --- a/test/infrastructure/inmemory/internal/server/mux_test.go +++ b/test/infrastructure/inmemory/internal/server/mux_test.go @@ -67,7 +67,7 @@ func TestMux(t *testing.T) { manager := cmanager.New(scheme) wcl := "workload-cluster" - host := "127.0.0.1" //nolint:goconst + host := "127.0.0.1" wcmux, err := NewWorkloadClustersMux(manager, host, CustomPorts{ // NOTE: make sure to use ports different than other tests, so we can run tests in parallel MinPort: DefaultMinPort, diff --git a/util/version/version.go b/util/version/version.go index 277ed61050ec..7ddfa4d27a42 100644 --- a/util/version/version.go +++ b/util/version/version.go @@ -115,9 +115,9 @@ func (v buildIdentifiers) compare(o buildIdentifiers) int { return 0 } else if i == len(v) && i < len(o) { return -1 - } else { - return 1 } + + return 1 } type buildIdentifier struct {