Skip to content

Commit 3e11f9d

Browse files
authored
Bump golangci-lint to v2.7.0 (#37)
1 parent 924c943 commit 3e11f9d

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

.custom-gcl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: v2.6.2
1+
version: v2.7.0
22
name: golangci-lint-kube-api-linter
33
destination: ./bin
44
plugins:

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: golangci/golangci-lint-action@v7
2222
with:
2323
install-mode: goinstall
24-
version: v2.6.2
24+
version: v2.7.0
2525

2626
- name: Run ShellCheck
2727
uses: ludeeus/action-shellcheck@master

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
236236
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
237237
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
238238
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
239-
GOLANGCI_LINT_VERSION ?= v2.6.2
239+
GOLANGCI_LINT_VERSION ?= v2.7.0
240240
NILAWAY_VERSION ?= latest
241241
MOCKGEN_VERSION ?= v0.6.0
242242
ENVSUBST_VERSION ?=latest

internal/service/scaleway/lb/lb.go

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
7979
conditions.Set(s.ScalewayCluster, condition)
8080
}()
8181

82-
lb, err := s.ensureLB(ctx)
82+
mainLB, err := s.ensureMainLB(ctx)
8383
if err != nil {
8484
condition.Reason = infrav1.ScalewayClusterMainLoadBalancerReconciliationFailedReason
8585
return err
@@ -101,17 +101,17 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
101101
return err
102102
}
103103

104-
if err := checkLBsReadiness(append(extraLBs, lb)); err != nil {
104+
if err := checkLBsReadiness(append(extraLBs, mainLB)); err != nil {
105105
condition.Reason = infrav1.ScalewayClusterLoadBalancersNotReadyReason
106106
return err
107107
}
108108

109-
if err := s.ensurePrivateNetwork(ctx, append(extraLBs, lb), pnID); err != nil {
109+
if err := s.ensurePrivateNetwork(ctx, append(extraLBs, mainLB), pnID); err != nil {
110110
condition.Reason = infrav1.ScalewayClusterLoadBalancerPrivateNetworkAttachmentFailedReason
111111
return err
112112
}
113113

114-
backendByLB, err := s.ensureBackend(ctx, lb, extraLBs)
114+
backendByLB, err := s.ensureBackend(ctx, mainLB, extraLBs)
115115
if err != nil {
116116
condition.Reason = infrav1.ScalewayClusterBackendReconciliationFailedReason
117117
return fmt.Errorf("failed to ensure lb backend: %w", err)
@@ -123,7 +123,7 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
123123
return fmt.Errorf("failed to ensure lb frontend: %w", err)
124124
}
125125

126-
if err := s.ensureACLs(ctx, lb, frontendByLB, pnID); err != nil {
126+
if err := s.ensureACLs(ctx, mainLB, frontendByLB, pnID); err != nil {
127127
condition.Reason = infrav1.ScalewayClusterLoadBalancerACLReconciliationFailedReason
128128
return fmt.Errorf("failed to ensure ACLs: %w", err)
129129
}
@@ -132,7 +132,7 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
132132
// private IP are set during this step.
133133
private := s.ControlPlaneLoadBalancerPrivate()
134134

135-
lbIP, err := getLBIPv4(lb, private)
135+
lbIP, err := getLBIPv4(mainLB, private)
136136
if err != nil {
137137
return err
138138
}
@@ -155,7 +155,7 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
155155
}
156156

157157
func (s *Service) Delete(ctx context.Context) error {
158-
if err := s.ensureDeleteLB(ctx); err != nil {
158+
if err := s.ensureDeleteMainLB(ctx); err != nil {
159159
return err
160160
}
161161

@@ -178,8 +178,8 @@ type lbWithPrivateIP struct {
178178
func sliceLBToLBWithPrivateIP(lbs []*lb.LB) []*lbWithPrivateIP {
179179
out := make([]*lbWithPrivateIP, 0, len(lbs))
180180

181-
for _, lb := range lbs {
182-
out = append(out, &lbWithPrivateIP{LB: lb})
181+
for _, l := range lbs {
182+
out = append(out, &lbWithPrivateIP{LB: l})
183183
}
184184

185185
return out
@@ -198,26 +198,26 @@ func checkLBsReadiness(lbs []*lbWithPrivateIP) error {
198198
return nil
199199
}
200200

201-
func (s *Service) ensureLB(ctx context.Context) (*lbWithPrivateIP, error) {
201+
func (s *Service) ensureMainLB(ctx context.Context) (*lbWithPrivateIP, error) {
202202
spec := s.ScalewayCluster.Spec.Network.ControlPlaneLoadBalancer.LoadBalancer
203203

204204
zone, lbType, err := lbutil.LBSpec(s.ScalewayClient, spec)
205205
if err != nil {
206206
return nil, err
207207
}
208208

209-
lb, err := s.ScalewayClient.FindLB(ctx, zone, s.ResourceTags(CAPSMainLBTag))
209+
mainLB, err := s.ScalewayClient.FindLB(ctx, zone, s.ResourceTags(CAPSMainLBTag))
210210
if err := utilerrors.FilterOut(err, client.IsNotFoundError); err != nil {
211211
return nil, err
212212
}
213213

214214
// If lb type does not match, migrate the LB.
215-
if lb != nil && !strings.EqualFold(lb.Type, lbType) {
216-
lb, err = s.ScalewayClient.MigrateLB(ctx, zone, lb.ID, lbType)
215+
if mainLB != nil && !strings.EqualFold(mainLB.Type, lbType) {
216+
mainLB, err = s.ScalewayClient.MigrateLB(ctx, zone, mainLB.ID, lbType)
217217
if err != nil {
218218
return nil, fmt.Errorf("failed to migrate lb: %w", err)
219219
}
220-
} else if lb == nil {
220+
} else if mainLB == nil {
221221
var ipID *string
222222

223223
if spec.IP != "" {
@@ -234,7 +234,7 @@ func (s *Service) ensureLB(ctx context.Context) (*lbWithPrivateIP, error) {
234234
}
235235

236236
logf.FromContext(ctx).Info("Creating main LB", "zone", zone)
237-
lb, err = s.ScalewayClient.CreateLB(
237+
mainLB, err = s.ScalewayClient.CreateLB(
238238
ctx,
239239
zone,
240240
s.ResourceName(),
@@ -249,12 +249,12 @@ func (s *Service) ensureLB(ctx context.Context) (*lbWithPrivateIP, error) {
249249
}
250250

251251
return &lbWithPrivateIP{
252-
LB: lb,
252+
LB: mainLB,
253253
privateIP: string(spec.PrivateIP),
254254
}, nil
255255
}
256256

257-
func (s *Service) ensureDeleteLB(ctx context.Context) error {
257+
func (s *Service) ensureDeleteMainLB(ctx context.Context) error {
258258
spec := s.ScalewayCluster.Spec.Network.ControlPlaneLoadBalancer.LoadBalancer
259259

260260
zone, _, err := lbutil.LBSpec(s.ScalewayClient, spec)
@@ -264,7 +264,7 @@ func (s *Service) ensureDeleteLB(ctx context.Context) error {
264264
return nil
265265
}
266266

267-
lb, err := s.ScalewayClient.FindLB(ctx, zone, s.ResourceTags(CAPSMainLBTag))
267+
mainLB, err := s.ScalewayClient.FindLB(ctx, zone, s.ResourceTags(CAPSMainLBTag))
268268
if err != nil {
269269
if errors.Is(err, client.ErrNoItemFound) {
270270
return nil
@@ -274,23 +274,23 @@ func (s *Service) ensureDeleteLB(ctx context.Context) error {
274274
}
275275

276276
logf.FromContext(ctx).Info("Deleting main LB")
277-
if err := s.ScalewayClient.DeleteLB(ctx, zone, lb.ID, spec.IP == ""); err != nil {
277+
if err := s.ScalewayClient.DeleteLB(ctx, zone, mainLB.ID, spec.IP == ""); err != nil {
278278
return fmt.Errorf("failed to delete lb: %w", err)
279279
}
280280

281281
return nil
282282
}
283283

284-
func getLBIPv4(lb *lbWithPrivateIP, private bool) (string, error) {
284+
func getLBIPv4(lbWithPrivateIP *lbWithPrivateIP, private bool) (string, error) {
285285
if private {
286-
if lb.privateIP == "" {
287-
return "", fmt.Errorf("did not find private ipv4 for lb %s", lb.ID)
286+
if lbWithPrivateIP.privateIP == "" {
287+
return "", fmt.Errorf("did not find private ipv4 for lb %s", lbWithPrivateIP.ID)
288288
}
289289

290-
return lb.privateIP, nil
290+
return lbWithPrivateIP.privateIP, nil
291291
}
292292

293-
for _, ip := range lb.IP {
293+
for _, ip := range lbWithPrivateIP.IP {
294294
addr, err := netip.ParseAddr(ip.IPAddress)
295295
if err != nil {
296296
return "", err
@@ -301,7 +301,7 @@ func getLBIPv4(lb *lbWithPrivateIP, private bool) (string, error) {
301301
}
302302
}
303303

304-
return "", fmt.Errorf("did not find ipv4 for lb %s", lb.ID)
304+
return "", fmt.Errorf("did not find ipv4 for lb %s", lbWithPrivateIP.ID)
305305
}
306306

307307
func (s *Service) ensureExtraLBs(ctx context.Context, pnID *string, delete bool) ([]*lbWithPrivateIP, error) {
@@ -431,13 +431,13 @@ func (d *desiredResourceListManager) CreateResource(
431431
}
432432

433433
logf.FromContext(ctx).Info("Creating extra LB", "lbName", name, "zone", zone)
434-
lb, err := d.ScalewayClient.CreateLB(ctx, zone, name, lbType, ipID, d.ControlPlaneLoadBalancerPrivate(), tags)
434+
l, err := d.ScalewayClient.CreateLB(ctx, zone, name, lbType, ipID, d.ControlPlaneLoadBalancerPrivate(), tags)
435435
if err != nil {
436436
return nil, err
437437
}
438438

439439
return &lbWithPrivateIP{
440-
LB: lb,
440+
LB: l,
441441
privateIP: string(desired.IP),
442442
}, nil
443443
}
@@ -449,12 +449,12 @@ func (d *desiredResourceListManager) UpdateResource(
449449
) (*lbWithPrivateIP, error) {
450450
if desired.Type != "" && !strings.EqualFold(desired.Type, resource.Type) {
451451
logf.FromContext(ctx).Info("Migrating extra LB", "lbName", resource.Name, "zone", resource, "type", desired.Type)
452-
lb, err := d.ScalewayClient.MigrateLB(ctx, resource.Zone, resource.ID, desired.Type)
452+
l, err := d.ScalewayClient.MigrateLB(ctx, resource.Zone, resource.ID, desired.Type)
453453
if err != nil {
454454
return nil, err
455455
}
456456

457-
resource.LB = lb
457+
resource.LB = l
458458
}
459459

460460
// Set desired private IP.
@@ -465,22 +465,22 @@ func (d *desiredResourceListManager) UpdateResource(
465465

466466
func (s *Service) getOrCreateBackend(
467467
ctx context.Context,
468-
lb *lbWithPrivateIP,
468+
lbWithPrivateIP *lbWithPrivateIP,
469469
servers []string,
470470
updateServers bool,
471471
) (*lb.Backend, error) {
472472
servers = slices.Sorted(slices.Values(servers))
473473

474-
backend, err := s.ScalewayClient.FindBackend(ctx, lb.Zone, lb.ID, BackendName)
474+
backend, err := s.ScalewayClient.FindBackend(ctx, lbWithPrivateIP.Zone, lbWithPrivateIP.ID, BackendName)
475475
if err := utilerrors.FilterOut(err, client.IsNotFoundError); err != nil {
476476
return nil, err
477477
}
478478

479479
if backend == nil {
480480
backend, err = s.ScalewayClient.CreateBackend(
481481
ctx,
482-
lb.Zone,
483-
lb.ID,
482+
lbWithPrivateIP.Zone,
483+
lbWithPrivateIP.ID,
484484
BackendName,
485485
servers,
486486
backendControlPlanePort,
@@ -489,7 +489,7 @@ func (s *Service) getOrCreateBackend(
489489
return nil, err
490490
}
491491
} else if updateServers && !slices.Equal(servers, slices.Sorted(slices.Values(backend.Pool))) {
492-
backend, err = s.ScalewayClient.SetBackendServers(ctx, lb.Zone, backend.ID, servers)
492+
backend, err = s.ScalewayClient.SetBackendServers(ctx, lbWithPrivateIP.Zone, backend.ID, servers)
493493
if err != nil {
494494
return nil, err
495495
}
@@ -561,16 +561,16 @@ func (s *Service) ensurePrivateNetwork(ctx context.Context, lbs []*lbWithPrivate
561561
var availableIPs []*ipam.IP // Will be lazy loaded if needed.
562562
var lbIDsWithMissingIP []string
563563

564-
for _, lb := range lbs {
565-
lbPN, err := s.ScalewayClient.FindLBPrivateNetwork(ctx, lb.Zone, lb.ID, *pnID)
564+
for _, l := range lbs {
565+
lbPN, err := s.ScalewayClient.FindLBPrivateNetwork(ctx, l.Zone, l.ID, *pnID)
566566
if err := utilerrors.FilterOut(err, client.IsNotFoundError); err != nil {
567567
return err
568568
}
569569

570570
if lbPN == nil {
571571
var ipID *string
572572

573-
if lb.privateIP != "" {
573+
if l.privateIP != "" {
574574
// Lazy load available IPs.
575575
if len(availableIPs) == 0 {
576576
availableIPs, err = s.ScalewayClient.FindAvailableIPs(ctx, *pnID)
@@ -579,21 +579,21 @@ func (s *Service) ensurePrivateNetwork(ctx context.Context, lbs []*lbWithPrivate
579579
}
580580
}
581581

582-
ipIndex := slices.IndexFunc(availableIPs, ipMatchFunc(lb.privateIP))
582+
ipIndex := slices.IndexFunc(availableIPs, ipMatchFunc(l.privateIP))
583583
if ipIndex == -1 {
584-
return fmt.Errorf("did not find available IP with address %s in IPAM", lb.privateIP)
584+
return fmt.Errorf("did not find available IP with address %s in IPAM", l.privateIP)
585585
}
586586

587587
ipID = &availableIPs[ipIndex].ID
588588
}
589589

590-
if err := s.ScalewayClient.AttachLBPrivateNetwork(ctx, lb.Zone, lb.ID, *pnID, ipID); err != nil {
590+
if err := s.ScalewayClient.AttachLBPrivateNetwork(ctx, l.Zone, l.ID, *pnID, ipID); err != nil {
591591
return err
592592
}
593593
}
594594

595-
if lb.privateIP == "" {
596-
lbIDsWithMissingIP = append(lbIDsWithMissingIP, lb.ID)
595+
if l.privateIP == "" {
596+
lbIDsWithMissingIP = append(lbIDsWithMissingIP, l.ID)
597597
}
598598
}
599599

@@ -602,17 +602,17 @@ func (s *Service) ensurePrivateNetwork(ctx context.Context, lbs []*lbWithPrivate
602602
return fmt.Errorf("failed to find lb missing IPs: %w", err)
603603
}
604604

605-
for _, lb := range lbs {
606-
if lb.privateIP != "" {
605+
for _, l := range lbs {
606+
if l.privateIP != "" {
607607
continue
608608
}
609609

610-
ipIndex := slices.IndexFunc(missingIPs, ipResourceMatchFunc(lb.ID))
610+
ipIndex := slices.IndexFunc(missingIPs, ipResourceMatchFunc(l.ID))
611611
if ipIndex == -1 {
612-
return scaleway.WithTransientError(fmt.Errorf("private IP for lb %s is not yet available in IPAM", lb.Name), 3*time.Second)
612+
return scaleway.WithTransientError(fmt.Errorf("private IP for lb %s is not yet available in IPAM", l.Name), 3*time.Second)
613613
}
614614

615-
lb.privateIP = missingIPs[ipIndex].Address.IP.String()
615+
l.privateIP = missingIPs[ipIndex].Address.IP.String()
616616
}
617617

618618
return nil

0 commit comments

Comments
 (0)