Skip to content

Commit 9856847

Browse files
authored
🌱 Bump golangci to v1.60.2 (#11132)
* Bump golangci to v1.60.2 * Fix lint * Improve disabling of rules * Fix lint and remove duplicate config
1 parent 2e321e8 commit 9856847

File tree

11 files changed

+43
-32
lines changed

11 files changed

+43
-32
lines changed

.github/workflows/pr-golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ jobs:
3030
- name: golangci-lint
3131
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # tag=v6.1.0
3232
with:
33-
version: v1.59.0
33+
version: v1.60.2
3434
args: --out-format=colored-line-number
3535
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ linters:
5555
- whitespace # unnecessary newlines
5656

5757
linters-settings:
58+
gosec:
59+
excludes:
60+
# integer overflow conversion int -> int32
61+
- G115
5862
gci:
5963
sections:
6064
- standard # Standard section: captures all standard packages.
@@ -348,3 +352,7 @@ issues:
348352
- gocritic
349353
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
350354
path: _test\.go
355+
# Ignore non-constant format string in call to condition utils
356+
- linters:
357+
- govet
358+
text: "non-constant format string in call to sigs\\.k8s\\.io\\/cluster-api\\/util\\/conditions\\."

cmd/clusterctl/cmd/describe_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func getRowName(obj ctrlclient.Object) string {
338338

339339
name := objName
340340
if objectPrefix := tree.GetMetaName(obj); objectPrefix != "" {
341-
name = fmt.Sprintf("%s - %s", objectPrefix, gray.Sprintf(name))
341+
name = fmt.Sprintf("%s - %s", objectPrefix, gray.Sprintf("%s", name))
342342
}
343343

344344
if !obj.GetDeletionTimestamp().IsZero() {

internal/controllers/machinedeployment/mdutil/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ func SetDeploymentRevision(deployment *clusterv1.MachineDeployment, revision str
120120
func MaxRevision(ctx context.Context, allMSs []*clusterv1.MachineSet) int64 {
121121
log := ctrl.LoggerFrom(ctx)
122122

123-
max := int64(0)
123+
maxVal := int64(0)
124124
for _, ms := range allMSs {
125125
if v, err := Revision(ms); err != nil {
126126
// Skip the machine sets when it failed to parse their revision information
127127
log.Error(err, fmt.Sprintf("Couldn't parse revision for MachineSet %s, deployment controller will skip it when reconciling revisions", ms.Name))
128-
} else if v > max {
129-
max = v
128+
} else if v > maxVal {
129+
maxVal = v
130130
}
131131
}
132-
return max
132+
return maxVal
133133
}
134134

135135
// Revision returns the revision number of the input object.

internal/controllers/machinehealthcheck/machinehealthcheck_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,13 @@ func isAllowedRemediation(mhc *clusterv1.MachineHealthCheck) (bool, int32, error
580580
var remediationAllowed bool
581581
var remediationCount int32
582582
if mhc.Spec.UnhealthyRange != nil {
583-
min, max, err := getUnhealthyRange(mhc)
583+
minVal, maxVal, err := getUnhealthyRange(mhc)
584584
if err != nil {
585585
return false, 0, err
586586
}
587587
unhealthyMachineCount := unhealthyMachineCount(mhc)
588-
remediationAllowed = unhealthyMachineCount >= min && unhealthyMachineCount <= max
589-
remediationCount = int32(max - unhealthyMachineCount)
588+
remediationAllowed = unhealthyMachineCount >= minVal && unhealthyMachineCount <= maxVal
589+
remediationCount = int32(maxVal - unhealthyMachineCount)
590590
return remediationAllowed, remediationCount, nil
591591
}
592592

@@ -610,21 +610,21 @@ func getUnhealthyRange(mhc *clusterv1.MachineHealthCheck) (int, int, error) {
610610

611611
parts := strings.Split(unhealthyRange, "-")
612612

613-
min, err := strconv.ParseUint(parts[0], 10, 32)
613+
minVal, err := strconv.ParseUint(parts[0], 10, 32)
614614
if err != nil {
615615
return 0, 0, err
616616
}
617617

618-
max, err := strconv.ParseUint(parts[1], 10, 32)
618+
maxVal, err := strconv.ParseUint(parts[1], 10, 32)
619619
if err != nil {
620620
return 0, 0, err
621621
}
622622

623-
if max < min {
624-
return 0, 0, errors.Errorf("max value %d cannot be less than min value %d for unhealthyRange", max, min)
623+
if maxVal < minVal {
624+
return 0, 0, errors.Errorf("max value %d cannot be less than min value %d for unhealthyRange", maxVal, minVal)
625625
}
626626

627-
return int(min), int(max), nil
627+
return int(minVal), int(maxVal), nil
628628
}
629629

630630
func getMaxUnhealthy(mhc *clusterv1.MachineHealthCheck) (int, error) {

internal/controllers/machinehealthcheck/machinehealthcheck_targets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func TestHealthCheckTargets(t *testing.T) {
406406
machineFailureMsgCondition := newFailedHealthCheckCondition(clusterv1.MachineHasFailureReason, "FailureMessage: %s", failureMsg)
407407

408408
// Target for when the machine has the remediate machine annotation
409-
annotationRemediationMsg := "Marked for remediation via remediate-machine annotation"
409+
const annotationRemediationMsg = "Marked for remediation via remediate-machine annotation"
410410
testMachineAnnotationRemediation := testMachine.DeepCopy()
411411
testMachineAnnotationRemediation.Annotations = map[string]string{clusterv1.RemediateMachineAnnotation: ""}
412412
machineAnnotationRemediation := healthCheckTarget{

test/framework/docker_logcollector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
147147
"tar", "--hard-dereference", "--dereference", "--directory", containerDir, "--create", "--file", "-", ".",
148148
)
149149
if err != nil {
150-
return errors.Wrapf(err, execErr)
150+
return errors.Wrap(err, execErr)
151151
}
152152

153153
err = os.MkdirAll(outputDir, 0750)

test/infrastructure/docker/internal/docker/loadbalancer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func NewLoadBalancer(ctx context.Context, cluster *clusterv1.Cluster, dockerClus
6565
return nil, err
6666
}
6767

68-
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck // We tolerate this until removal; after removal IPFamily will become an internal CAPD concept. See https://github.com/kubernetes-sigs/cluster-api/issues/7521.
68+
// We tolerate this until removal;
69+
// after removal IPFamily will become an internal CAPD concept.
70+
// See https://github.com/kubernetes-sigs/cluster-api/issues/7521.
71+
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck
6972
if err != nil {
7073
return nil, fmt.Errorf("create load balancer: %s", err)
7174
}

test/infrastructure/docker/internal/docker/machine.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ func NewMachine(ctx context.Context, cluster *clusterv1.Cluster, machine string,
9292
return nil, err
9393
}
9494

95-
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck // We tolerate this until removal; after removal IPFamily will become an internal CAPD concept. See https://github.com/kubernetes-sigs/cluster-api/issues/7521.
95+
// We tolerate this until removal;
96+
// after removal IPFamily will become an internal CAPD concept.
97+
// See https://github.com/kubernetes-sigs/cluster-api/issues/7521.
98+
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck
9699
if err != nil {
97100
return nil, fmt.Errorf("create docker machine: %s", err)
98101
}
@@ -126,7 +129,10 @@ func ListMachinesByCluster(ctx context.Context, cluster *clusterv1.Cluster, labe
126129
return nil, err
127130
}
128131

129-
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck // We tolerate this until removal; after removal IPFamily will become an internal CAPD concept. See https://github.com/kubernetes-sigs/cluster-api/issues/7521.
132+
// We tolerate this until removal;
133+
// after removal IPFamily will become an internal CAPD concept.
134+
// See https://github.com/kubernetes-sigs/cluster-api/issues/7521 .
135+
ipFamily, err := cluster.GetIPFamily() //nolint:staticcheck
130136
if err != nil {
131137
return nil, fmt.Errorf("list docker machines by cluster: %s", err)
132138
}

test/infrastructure/inmemory/pkg/runtime/cache/client.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ func (c *cache) store(resourceGroup string, obj client.Object, replaceExisting b
212212
return apierrors.NewConflict(unsafeGuessGroupVersionResource(objGVK).GroupResource(), objKey.String(), fmt.Errorf("object has been modified"))
213213
}
214214

215-
if err := c.beforeUpdate(resourceGroup, trackedObj, obj); err != nil {
216-
return err
217-
}
215+
c.beforeUpdate(resourceGroup, trackedObj, obj)
216+
218217
tracker.objects[objGVK][objKey] = obj.DeepCopyObject().(client.Object)
219218
updateTrackerOwnerReferences(tracker, trackedObj, obj, objRef)
220219
c.afterUpdate(resourceGroup, trackedObj, obj)
@@ -227,9 +226,8 @@ func (c *cache) store(resourceGroup string, obj client.Object, replaceExisting b
227226
return apierrors.NewNotFound(unsafeGuessGroupVersionResource(objGVK).GroupResource(), objKey.String())
228227
}
229228

230-
if err := c.beforeCreate(resourceGroup, obj); err != nil {
231-
return err
232-
}
229+
c.beforeCreate(resourceGroup, obj)
230+
233231
tracker.objects[objGVK][objKey] = obj.DeepCopyObject().(client.Object)
234232
updateTrackerOwnerReferences(tracker, nil, obj, objRef)
235233
c.afterCreate(resourceGroup, obj)
@@ -424,9 +422,7 @@ func (c *cache) doTryDeleteLocked(resourceGroup string, tracker *resourceGroupTr
424422
oldObj := obj.DeepCopyObject().(client.Object)
425423
now := metav1.Time{Time: time.Now().UTC()}
426424
obj.SetDeletionTimestamp(&now)
427-
if err := c.beforeUpdate(resourceGroup, oldObj, obj); err != nil {
428-
return false, apierrors.NewBadRequest(err.Error())
429-
}
425+
c.beforeUpdate(resourceGroup, oldObj, obj)
430426

431427
objects[objKey] = obj
432428
c.afterUpdate(resourceGroup, oldObj, obj)

0 commit comments

Comments
 (0)