Skip to content

Commit 01b3b04

Browse files
committed
Golang 1.24.1 / Golangci-lint 1.64.7
This patch updates VM Operator to use Golang 1.24.1 and Golangci-lint 1.64.7 (as it supports Golang 1.24.1). This patch also addresses several new linter errors: * Loop variables no longer need to be captured due to Go 1.22 * There are a massive number of false positives regarding int overflows. See securego/gosec#1212 The linter directive G115 is used surgically to disable the false-positives but also places where we know there is not a chance for an overflow. There is also a good blog on the issue at https://dev.to/ccoveille/about-the-gosec-g115-drama-or-how-i-faced-back-integer-conversion-overflow-in-go-1302.
1 parent 3235431 commit 01b3b04

File tree

25 files changed

+410
-363
lines changed

25 files changed

+410
-363
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66
# sometimes we need to explicitly override the Go version, ex. CVEs,
77
# when it is not possible to update the go.mod version yet, ex. the
88
# internal builds do not yet support that version of Go.
9-
GO_VERSION: 1.23.6
9+
GO_VERSION:
1010

1111
on:
1212
pull_request:

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ linters:
170170
enable:
171171
- asciicheck
172172
- bodyclose
173+
- copyloopvar
173174
- depguard
174175
- dogsled
175176
- errcheck
176177
- errorlint
177-
- exportloopref
178178
- goconst
179179
- gocritic
180180
- gocyclo

Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,19 @@ lint: ## Run all the lint targets
285285

286286
GOLANGCI_LINT_FLAGS ?= --fast=true
287287
GOLANGCI_LINT_ABS_PATH := $(abspath $(GOLANGCI_LINT))
288+
289+
GO_MOD_DIRS_TO_LINT := $(GO_MOD_DIRS)
290+
GO_MOD_DIRS_TO_LINT := $(filter-out ./external%,$(GO_MOD_DIRS_TO_LINT))
291+
GO_MOD_DIRS_TO_LINT := $(filter-out ./hack/tools%,$(GO_MOD_DIRS_TO_LINT))
292+
GO_LINT_DIR_TARGETS := $(addprefix lint-,$(GO_MOD_DIRS_TO_LINT))
293+
294+
.PHONY: $(GO_LINT_DIR_TARGETS)
295+
$(GO_LINT_DIR_TARGETS): | $(GOLANGCI_LINT)
296+
cd $(subst lint-,,$@) && $(GOLANGCI_LINT_ABS_PATH) run -v $(GOLANGCI_LINT_FLAGS)
297+
288298
.PHONY: lint-go
289-
lint-go: $(GOLANGCI_LINT)
299+
lint-go: $(GO_LINT_DIR_TARGETS)
290300
lint-go: ## Lint codebase
291-
@for dir in $(GO_MOD_DIRS); do \
292-
if [[ "$$dir" == ./external* || "$$dir" == ./hack/tools* ]]; then \
293-
echo "Skipping $$dir"; \
294-
continue; \
295-
fi; \
296-
echo "Running golangci-lint in $$dir"; \
297-
(cd $$dir && $(GOLANGCI_LINT_ABS_PATH) run -v $(GOLANGCI_LINT_FLAGS)); \
298-
done
299301

300302
.PHONY: lint-go-full
301303
lint-go-full: GOLANGCI_LINT_FLAGS = --fast=false

controllers/virtualmachine/volume/volume_controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ func (r *Reconciler) reconcileInstanceStoragePVCs(ctx *pkgctx.VolumeContext) (bo
374374
createPVCs := len(selectedNode) > 0
375375

376376
for _, pvc := range pvcList {
377-
pvc := pvc
378-
379377
if !pvc.DeletionTimestamp.IsZero() {
380378
// Ignore PVC that is being deleted. Likely this is from a previous failed
381379
// placement and CSI hasn't fully cleaned up yet (a finalizer is still present).

controllers/virtualmachine/volume/volume_controller_unit_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,6 @@ func adjustPVCCreationTimestamp(ctx *pkgctx.VolumeContext, testCtx *builder.Unit
13941394
Expect(err).ToNot(HaveOccurred())
13951395

13961396
for _, pvc := range pvcList {
1397-
pvc := pvc
13981397
pvc.CreationTimestamp = metav1.NewTime(time.Now().Add(-2 * pkgcfg.FromContext(ctx).InstanceStorage.PVPlacementFailedTTL))
13991398
Expect(testCtx.Client.Update(ctx, &pvc)).To(Succeed())
14001399
}
@@ -1431,7 +1430,6 @@ func patchInstanceStoragePVCs(ctx *pkgctx.VolumeContext, testCtx *builder.UnitTe
14311430
Expect(err).ToNot(HaveOccurred())
14321431

14331432
for _, pvc := range pvcList {
1434-
pvc := pvc
14351433
if setStatusBound {
14361434
pvc.Status.Phase = corev1.ClaimBound
14371435
Expect(testCtx.Client.Status().Update(ctx, &pvc)).To(Succeed())

controllers/virtualmachinereplicaset/virtualmachinereplicaset_controller.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strings"
2929
"time"
3030

31+
"github.com/go-logr/logr"
3132
apierrors "k8s.io/apimachinery/pkg/api/errors"
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3334
"k8s.io/apimachinery/pkg/labels"
@@ -41,8 +42,6 @@ import (
4142
"sigs.k8s.io/controller-runtime/pkg/manager"
4243
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4344

44-
"github.com/go-logr/logr"
45-
4645
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha4"
4746
"github.com/vmware-tanzu/vm-operator/pkg/conditions"
4847
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
@@ -154,7 +153,6 @@ func (r *Reconciler) getReplicaSetsForVM(
154153

155154
var rss []*vmopv1.VirtualMachineReplicaSet
156155
for _, rs := range rsList.Items {
157-
rs := rs
158156
selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
159157
if err != nil {
160158
continue
@@ -623,9 +621,9 @@ func (r *Reconciler) updateStatus(
623621

624622
}
625623

626-
newStatus.Replicas = int32(len(filteredVMs))
627-
newStatus.FullyLabeledReplicas = int32(fullyLabeledReplicasCount)
628-
newStatus.ReadyReplicas = int32(readyReplicasCount)
624+
newStatus.Replicas = int32(len(filteredVMs)) //nolint:gosec // disable G115
625+
newStatus.FullyLabeledReplicas = int32(fullyLabeledReplicasCount) //nolint:gosec // disable G115
626+
newStatus.ReadyReplicas = int32(readyReplicasCount) //nolint:gosec // disable G115
629627

630628
// Copy the newly calculated status into the VirtualMachineReplicaSet.
631629
if rs.Status.Replicas != newStatus.Replicas ||

controllers/virtualmachineservice/virtualmachineservice_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,11 @@ func (r *ReconcileVirtualMachineService) generateSubsetsForService(
699699
}
700700

701701
subset.Ports = append(subset.Ports,
702-
corev1.EndpointPort{Name: portName, Port: int32(portNum), Protocol: portProto})
702+
corev1.EndpointPort{
703+
Name: portName,
704+
Port: int32(portNum), //nolint:gosec // disable G115
705+
Protocol: portProto,
706+
})
703707
}
704708

705709
subsets = append(subsets, subset)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/vmware-tanzu/vm-operator
22

3-
go 1.23.5
3+
go 1.24.1
44

55
replace (
66
github.com/vmware-tanzu/vm-operator/api => ./api

hack/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ GO_TEST_FLAGS+=("-v") # verbose
1717
GO_TEST_FLAGS+=("-r") # recursive
1818
GO_TEST_FLAGS+=("--race") # check for possible races
1919
GO_TEST_FLAGS+=("--keep-going") # do not fail on the first error
20+
GO_TEST_FLAGS+=("--vet=off") # disable govet during tests until the issue
21+
# outlined at https://github.com/golang/go/issues/60529#issuecomment-2043669945
22+
# and https://github.com/kubernetes/kubernetes/issues/127191
23+
# is able to be solved at point-of-use
2024

2125
# Only run tests that match given labels if LABEL_FILTER is non-empty.
2226
if [ -n "${LABEL_FILTER:-}" ]; then

0 commit comments

Comments
 (0)