Skip to content

Commit 661c3d2

Browse files
committed
Update golangci-lint to v2.8.0 and fix lint issues
1 parent 43d7661 commit 661c3d2

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

controllers/openstackserver_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ func TestOpenStackServerReconciler_requeueOpenStackServersForCluster(t *testing.
353353
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
354354
g.Expect(infrav1alpha1.AddToScheme(scheme)).To(Succeed())
355355

356-
objs := []client.Object{tt.cluster}
356+
objs := make([]client.Object, 0, 1+len(tt.servers))
357+
objs = append(objs, tt.cluster)
357358
for _, server := range tt.servers {
358359
objs = append(objs, server)
359360
}

hack/tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ROOT_DIR_RELATIVE := ../..
1616
include $(ROOT_DIR_RELATIVE)/common.mk
1717

18-
GOLANGCI_LINT_VERSION ?= v2.7.2
18+
GOLANGCI_LINT_VERSION ?= v2.8.0
1919

2020
# GOTESTSUM version without the leading 'v'
2121
GOTESTSUM_VERSION ?= 1.12.0

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, caCerts []byte) {
344344
UseCache: true,
345345
},
346346
}
347-
crdMigratorSkipPhases := []crdmigrator.Phase{}
347+
crdMigratorSkipPhases := make([]crdmigrator.Phase, 0, len(skipCRDMigrationPhases))
348348
for _, p := range skipCRDMigrationPhases {
349349
crdMigratorSkipPhases = append(crdMigratorSkipPhases, crdmigrator.Phase(p))
350350
}

pkg/cloud/services/compute/instance_types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ func (is *InstanceStatus) NetworkStatus() (*InstanceNetworkStatus, error) {
146146
return nil, fmt.Errorf("error unmarshalling addresses for instance %s: %w", is.ID(), err)
147147
}
148148

149-
var IPv4addresses, IPv6addresses []corev1.NodeAddress
149+
IPv4addresses := make([]corev1.NodeAddress, 0, len(interfaceList))
150+
IPv6addresses := make([]corev1.NodeAddress, 0, len(interfaceList))
150151
for i := range interfaceList {
151152
address := &interfaceList[i]
152153

@@ -194,7 +195,12 @@ func (ns *InstanceNetworkStatus) Addresses() []corev1.NodeAddress {
194195
}
195196
sort.Strings(networks)
196197

197-
var addresses []corev1.NodeAddress
198+
// Calculate total number of addresses to preallocate
199+
totalAddresses := 0
200+
for _, addrs := range ns.addresses {
201+
totalAddresses += len(addrs)
202+
}
203+
addresses := make([]corev1.NodeAddress, 0, totalAddresses)
198204
for _, network := range networks {
199205
addressList := ns.addresses[network]
200206
addresses = append(addresses, addressList...)

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
153153
lbStatus.AllowedCIDRs = nil
154154
}
155155

156-
portList := []int{apiServerPort}
156+
portList := make([]int, 0, 1+len(lbSpec.AdditionalPorts))
157+
portList = append(portList, apiServerPort)
157158
portList = append(portList, lbSpec.AdditionalPorts...)
158159
for _, port := range portList {
159160
if err := s.reconcileAPILoadBalancerListener(lb, openStackCluster, clusterResourceName, port); err != nil {
@@ -247,7 +248,7 @@ func getCanonicalAllowedCIDRs(openStackCluster *infrav1.OpenStackCluster) []stri
247248
}
248249

249250
// Filter invalid CIDRs and convert any IPs into CIDRs.
250-
validCIDRs := []string{}
251+
validCIDRs := make([]string, 0, len(allowedCIDRs))
251252
for _, v := range allowedCIDRs {
252253
switch {
253254
case utilsnet.IsIPv4String(v):

pkg/cloud/services/networking/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ func uniqueSortedTags(tags []string) []string {
663663
tagsMap[t] = t
664664
}
665665

666-
uniqueTags := []string{}
666+
uniqueTags := make([]string, 0, len(tagsMap))
667667
for k := range tagsMap {
668668
uniqueTags = append(uniqueTags, k)
669669
}

pkg/cloud/services/networking/securitygroups_rules.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func getSGWorkerAllowAll(remoteGroupIDSelf, secControlPlaneGroupID string) []res
257257

258258
// Permit ports that defined in openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts.
259259
func getSGControlPlaneAdditionalPorts(ports []int) []resolvedSecurityGroupRuleSpec {
260-
controlPlaneRules := []resolvedSecurityGroupRuleSpec{}
261260
// Preallocate r with len(ports)
262261
r := make([]resolvedSecurityGroupRuleSpec, len(ports))
263262
for i, p := range ports {
@@ -270,18 +269,13 @@ func getSGControlPlaneAdditionalPorts(ports []int) []resolvedSecurityGroupRuleSp
270269
PortRangeMax: p,
271270
}
272271
}
273-
controlPlaneRules = append(controlPlaneRules, r...)
274-
return controlPlaneRules
272+
return r
275273
}
276274

277275
func getSGControlPlaneGeneral(remoteGroupIDSelf, secWorkerGroupID string) []resolvedSecurityGroupRuleSpec {
278-
controlPlaneRules := []resolvedSecurityGroupRuleSpec{}
279-
controlPlaneRules = append(controlPlaneRules, getSGControlPlaneCommon(remoteGroupIDSelf, secWorkerGroupID)...)
280-
return controlPlaneRules
276+
return getSGControlPlaneCommon(remoteGroupIDSelf, secWorkerGroupID)
281277
}
282278

283279
func getSGWorkerGeneral(remoteGroupIDSelf, secControlPlaneGroupID string) []resolvedSecurityGroupRuleSpec {
284-
workerRules := []resolvedSecurityGroupRuleSpec{}
285-
workerRules = append(workerRules, getSGWorkerCommon(remoteGroupIDSelf, secControlPlaneGroupID)...)
286-
return workerRules
280+
return getSGWorkerCommon(remoteGroupIDSelf, secControlPlaneGroupID)
287281
}

test/e2e/suites/e2e/e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
764764
openStackCluster, err := shared.ClusterForSpec(ctx, e2eCtx, namespace)
765765
Expect(err).NotTo(HaveOccurred())
766766

767-
var allMachines []clusterv1.Machine
767+
allMachines := make([]clusterv1.Machine, 0, len(controlPlaneMachines)+len(workerMachines))
768768
allMachines = append(allMachines, controlPlaneMachines...)
769769
allMachines = append(allMachines, workerMachines...)
770770

@@ -787,7 +787,7 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
787787
Expect(err).NotTo(HaveOccurred())
788788
Expect(ports).To(HaveLen(len(expectedPorts)))
789789

790-
var seenNetworks []string
790+
seenNetworks := make([]string, 0, len(ports))
791791
var seenAddresses clusterv1.MachineAddresses
792792
for j := range ports {
793793
port := &ports[j]
@@ -938,7 +938,7 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
938938
fmt.Sprintf("Cluster %s: worker machines were not scheduled in the expected AZ", cluster.Name))
939939

940940
// Check that all machines were actually scheduled in the correct AZ
941-
var allMachines []clusterv1.Machine
941+
allMachines := make([]clusterv1.Machine, 0, len(controlPlaneMachines)+len(workerMachines))
942942
allMachines = append(allMachines, controlPlaneMachines...)
943943
allMachines = append(allMachines, workerMachines...)
944944

0 commit comments

Comments
 (0)