Skip to content

Commit ffc15e4

Browse files
committed
add nilaway to GHA, fix or ignore errors
1 parent a4b1993 commit ffc15e4

File tree

7 files changed

+101
-48
lines changed

7 files changed

+101
-48
lines changed

.github/workflows/build-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ jobs:
7373
run: make vet
7474

7575
- name: lint
76-
uses: golangci/golangci-lint-action@v8
76+
run: make lint
77+
78+
- name: nilcheck
79+
run: make nilcheck
7780

7881
- name: Helm Lint
7982
run: make helm-lint

.golangci-nilaway.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ linters:
1717
settings:
1818
include-pkgs: ""
1919
exclude-file-docstrings: ignore_autogenerated
20-
exclusions:
21-
rules:
22-
- path-except: "^api/"
23-
linters:
24-
- nilaway
2520
issues:
2621
max-issues-per-linter: 0
2722
max-same-issues: 0

cloud/linode/loadbalancers_test.go

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func testCreateNodeBalancerWithInvalidFirewall(t *testing.T, client *linodego.Cl
609609
}
610610
expectedError := "strconv.Atoi: parsing \"qwerty\": invalid syntax"
611611
err := testCreateNodeBalancer(t, client, f, annotations, nil)
612-
if err.Error() != expectedError {
612+
if err != nil && err.Error() != expectedError {
613613
t.Fatalf("expected a %s error, got %v", expectedError, err)
614614
}
615615
}
@@ -748,7 +748,9 @@ func testUpdateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client,
748748
if err != nil {
749749
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
750750
}
751-
svc.Status.LoadBalancer = *lbStatus
751+
if lbStatus != nil {
752+
svc.Status.LoadBalancer = *lbStatus
753+
}
752754

753755
stubServiceUpdate(fakeClientset, svc)
754756
svc.SetAnnotations(map[string]string{
@@ -834,7 +836,9 @@ func testCreateNodeBalancerWithVPCOnlySubnetFlag(t *testing.T, client *linodego.
834836
if err != nil {
835837
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
836838
}
837-
svc.Status.LoadBalancer = *lbStatus
839+
if lbStatus != nil {
840+
svc.Status.LoadBalancer = *lbStatus
841+
}
838842

839843
stubService(fakeClientset, svc)
840844
svc.SetAnnotations(map[string]string{
@@ -927,7 +931,9 @@ func testCreateNodeBalancerWithVPCNoFlagOrAnnotation(t *testing.T, client *linod
927931
if err != nil {
928932
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
929933
}
930-
svc.Status.LoadBalancer = *lbStatus
934+
if lbStatus != nil {
935+
svc.Status.LoadBalancer = *lbStatus
936+
}
931937

932938
stubService(fakeClientset, svc)
933939
svc.SetAnnotations(map[string]string{
@@ -1017,7 +1023,9 @@ func testCreateNodeBalancerWithVPCAnnotationOnly(t *testing.T, client *linodego.
10171023
if err != nil {
10181024
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
10191025
}
1020-
svc.Status.LoadBalancer = *lbStatus
1026+
if lbStatus != nil {
1027+
svc.Status.LoadBalancer = *lbStatus
1028+
}
10211029

10221030
stubServiceUpdate(fakeClientset, svc)
10231031
svc.SetAnnotations(map[string]string{})
@@ -1101,7 +1109,9 @@ func testCreateNodeBalancerWithVPCOnlySubnetIDFlag(t *testing.T, client *linodeg
11011109
if err != nil {
11021110
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
11031111
}
1104-
svc.Status.LoadBalancer = *lbStatus
1112+
if lbStatus != nil {
1113+
svc.Status.LoadBalancer = *lbStatus
1114+
}
11051115

11061116
stubService(fakeClientset, svc)
11071117

@@ -1247,7 +1257,9 @@ func testUpdateLoadBalancerAddNode(t *testing.T, client *linodego.Client, f *fak
12471257
if err != nil {
12481258
t.Errorf("EnsureLoadBalancer returned an error %s", err)
12491259
}
1250-
svc.Status.LoadBalancer = *lbStatus
1260+
if lbStatus != nil {
1261+
svc.Status.LoadBalancer = *lbStatus
1262+
}
12511263

12521264
stubService(fakeClientset, svc)
12531265

@@ -1412,7 +1424,9 @@ func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client,
14121424
if err != nil {
14131425
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
14141426
}
1415-
svc.Status.LoadBalancer = *lbStatus
1427+
if lbStatus != nil {
1428+
svc.Status.LoadBalancer = *lbStatus
1429+
}
14161430

14171431
stubService(fakeClientset, svc)
14181432
svc.SetAnnotations(map[string]string{
@@ -1488,7 +1502,9 @@ func testUpdateLoadBalancerAddPortAnnotation(t *testing.T, client *linodego.Clie
14881502
if err != nil {
14891503
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
14901504
}
1491-
svc.Status.LoadBalancer = *lbStatus
1505+
if lbStatus != nil {
1506+
svc.Status.LoadBalancer = *lbStatus
1507+
}
14921508
stubServiceUpdate(fakeClientset, svc)
14931509

14941510
svc.SetAnnotations(map[string]string{
@@ -1601,7 +1617,9 @@ func testVeryLongServiceName(t *testing.T, client *linodego.Client, _ *fakeAPI)
16011617
if err != nil {
16021618
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
16031619
}
1604-
svc.Status.LoadBalancer = *lbStatus
1620+
if lbStatus != nil {
1621+
svc.Status.LoadBalancer = *lbStatus
1622+
}
16051623
stubServiceUpdate(fakeClientset, svc)
16061624

16071625
svc.SetAnnotations(map[string]string{
@@ -1669,7 +1687,9 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak
16691687
if err != nil {
16701688
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
16711689
}
1672-
svc.Status.LoadBalancer = *lbStatus
1690+
if lbStatus != nil {
1691+
svc.Status.LoadBalancer = *lbStatus
1692+
}
16731693
stubService(fakeClientset, svc)
16741694

16751695
testTags := "test,new,tags"
@@ -1756,7 +1776,9 @@ func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ *
17561776
if err != nil {
17571777
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
17581778
}
1759-
svc.Status.LoadBalancer = *lbStatus
1779+
if lbStatus != nil {
1780+
svc.Status.LoadBalancer = *lbStatus
1781+
}
17601782

17611783
stubServiceUpdate(fakeClientset, svc)
17621784
svc.Spec.Ports = append(svc.Spec.Ports, extraPort)
@@ -1963,7 +1985,9 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client,
19631985
if err != nil {
19641986
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
19651987
}
1966-
svc.Status.LoadBalancer = *lbStatus
1988+
if lbStatus != nil {
1989+
svc.Status.LoadBalancer = *lbStatus
1990+
}
19671991
stubServiceUpdate(fakeClientset, svc)
19681992
fwClient := services.LinodeClient{Client: client}
19691993
fw, err := fwClient.CreateFirewall(t.Context(), linodego.FirewallCreateOptions{
@@ -1987,7 +2011,7 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client,
19872011
}()
19882012

19892013
svc.SetAnnotations(map[string]string{
1990-
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID),
2014+
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID), //nolint:nilaway
19912015
})
19922016

19932017
err = lb.UpdateLoadBalancer(t.Context(), "linodelb", svc, nodes)
@@ -2009,7 +2033,7 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client,
20092033
t.Fatalf("No attached firewalls found")
20102034
}
20112035

2012-
if firewalls[0].ID != fw.ID {
2036+
if firewalls[0].ID != fw.ID { //nolint:nilaway
20132037
t.Fatalf("Attached firewallID not matching with created firewall")
20142038
}
20152039
}
@@ -2063,7 +2087,9 @@ func testUpdateLoadBalancerAddNewFirewallACL(t *testing.T, client *linodego.Clie
20632087
if err != nil {
20642088
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
20652089
}
2066-
svc.Status.LoadBalancer = *lbStatus
2090+
if lbStatus != nil {
2091+
svc.Status.LoadBalancer = *lbStatus
2092+
}
20672093
stubService(fakeClientset, svc)
20682094

20692095
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2203,7 +2229,9 @@ func testUpdateLoadBalancerDeleteFirewallRemoveACL(t *testing.T, client *linodeg
22032229
if err != nil {
22042230
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
22052231
}
2206-
svc.Status.LoadBalancer = *lbStatus
2232+
if lbStatus != nil {
2233+
svc.Status.LoadBalancer = *lbStatus
2234+
}
22072235
stubService(fakeClientset, svc)
22082236

22092237
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2302,7 +2330,9 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li
23022330
if err != nil {
23032331
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
23042332
}
2305-
svc.Status.LoadBalancer = *lbStatus
2333+
if lbStatus != nil {
2334+
svc.Status.LoadBalancer = *lbStatus
2335+
}
23062336
stubService(fakeClientset, svc)
23072337

23082338
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2350,7 +2380,7 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li
23502380
}()
23512381

23522382
svc.SetAnnotations(map[string]string{
2353-
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID),
2383+
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID), //nolint:nilaway
23542384
})
23552385

23562386
err = lb.UpdateLoadBalancer(t.Context(), "linodelb", svc, nodes)
@@ -2381,7 +2411,7 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li
23812411
t.Errorf("expected 2.2.2.2, got %v", fwIPs)
23822412
}
23832413

2384-
if firewallsNew[0].ID != fw.ID {
2414+
if firewallsNew[0].ID != fw.ID { //nolint:nilaway
23852415
t.Errorf("Firewall ID does not match what we created, something wrong.")
23862416
}
23872417
}
@@ -2448,7 +2478,7 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li
24482478
}()
24492479

24502480
svc.SetAnnotations(map[string]string{
2451-
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID),
2481+
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID), //nolint:nilaway
24522482
})
24532483

24542484
defer func() {
@@ -2460,7 +2490,9 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li
24602490
if err != nil {
24612491
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
24622492
}
2463-
svc.Status.LoadBalancer = *lbStatus
2493+
if lbStatus != nil {
2494+
svc.Status.LoadBalancer = *lbStatus
2495+
}
24642496
stubServiceUpdate(fakeClientset, svc)
24652497

24662498
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2521,7 +2553,7 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li
25212553
t.Errorf("expected 2.2.2.2, got %v", fwIPs)
25222554
}
25232555

2524-
if firewallsNew[0].ID != fw.ID {
2556+
if firewallsNew[0].ID != fw.ID { //nolint:nilaway
25252557
t.Errorf("Firewall ID does not match, something wrong.")
25262558
}
25272559
}
@@ -2581,7 +2613,9 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie
25812613
if err != nil {
25822614
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
25832615
}
2584-
svc.Status.LoadBalancer = *lbStatus
2616+
if lbStatus != nil {
2617+
svc.Status.LoadBalancer = *lbStatus
2618+
}
25852619
stubService(fakeClientset, svc)
25862620

25872621
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2823,14 +2857,16 @@ func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client,
28232857
}()
28242858

28252859
svc.SetAnnotations(map[string]string{
2826-
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID),
2860+
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID), //nolint:nilaway
28272861
})
28282862

28292863
lbStatus, err := lb.EnsureLoadBalancer(t.Context(), "linodelb", svc, nodes)
28302864
if err != nil {
28312865
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
28322866
}
2833-
svc.Status.LoadBalancer = *lbStatus
2867+
if lbStatus != nil {
2868+
svc.Status.LoadBalancer = *lbStatus
2869+
}
28342870
stubService(fakeClientset, svc)
28352871

28362872
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2847,7 +2883,7 @@ func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client,
28472883
t.Fatalf("No firewalls attached")
28482884
}
28492885

2850-
if fw.ID != firewalls[0].ID {
2886+
if fw.ID != firewalls[0].ID { //nolint:nilaway
28512887
t.Fatalf("Attached firewallID not matching with created firewall")
28522888
}
28532889

@@ -2956,15 +2992,17 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego
29562992
}()
29572993

29582994
svc.SetAnnotations(map[string]string{
2959-
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID),
2995+
annotations.AnnLinodeCloudFirewallID: strconv.Itoa(fw.ID), //nolint:nilaway
29602996
})
29612997

29622998
stubService(fakeClientset, svc)
29632999
lbStatus, err := lb.EnsureLoadBalancer(t.Context(), "linodelb", svc, nodes)
29643000
if err != nil {
29653001
t.Errorf("EnsureLoadBalancer returned an error: %s", err)
29663002
}
2967-
svc.Status.LoadBalancer = *lbStatus
3003+
if lbStatus != nil {
3004+
svc.Status.LoadBalancer = *lbStatus
3005+
}
29683006
stubServiceUpdate(fakeClientset, svc)
29693007

29703008
nb, err := lb.getNodeBalancerByStatus(t.Context(), svc)
@@ -2981,7 +3019,7 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego
29813019
t.Fatalf("No firewalls attached")
29823020
}
29833021

2984-
if fw.ID != firewalls[0].ID {
3022+
if fw.ID != firewalls[0].ID { //nolint:nilaway
29853023
t.Fatalf("Attached firewallID not matching with created firewall")
29863024
}
29873025

@@ -3077,6 +3115,12 @@ func testUpdateLoadBalancerAddReservedIP(t *testing.T, client *linodego.Client,
30773115
}
30783116

30793117
status, _, err := lb.GetLoadBalancer(t.Context(), clusterName, svc)
3118+
if err != nil {
3119+
t.Fatalf("failed to get loadbalancer status: %s", err)
3120+
}
3121+
if status == nil {
3122+
t.Fatalf("no loadbalancer status returned")
3123+
}
30803124
if status.Ingress[0].IP != initialIP {
30813125
t.Fatalf("IP should not have changed in service status: %s", err)
30823126
}
@@ -4334,6 +4378,9 @@ func testEnsureExistingLoadBalancer(t *testing.T, client *linodego.Client, _ *fa
43344378
if err != nil {
43354379
t.Fatalf("failed to create nodebalancer: %s", err)
43364380
}
4381+
if getLBStatus == nil {
4382+
t.Fatalf("failed to get nodebalancer")
4383+
}
43374384
if !exists {
43384385
t.Fatal("Node balancer not found")
43394386
}
@@ -4981,7 +5028,9 @@ func testGetLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) {
49815028
defer func() { _ = lb.EnsureLoadBalancerDeleted(t.Context(), "linodelb", svc) }()
49825029

49835030
lbStatus := makeLoadBalancerStatus(svc, nb)
4984-
svc.Status.LoadBalancer = *lbStatus
5031+
if lbStatus != nil {
5032+
svc.Status.LoadBalancer = *lbStatus
5033+
}
49855034
stubService(fakeClientset, svc)
49865035
stubService(fakeClientset, svc2)
49875036

cloud/linode/nodeipamcontroller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func Test_processCIDRs(t *testing.T) {
104104
},
105105
want: []*net.IPNet{
106106
{
107-
IP: ipv4Net.IP,
108-
Mask: ipv4Net.Mask,
107+
IP: ipv4Net.IP, //nolint:nilaway
108+
Mask: ipv4Net.Mask, //nolint:nilaway
109109
},
110110
},
111111
wantErr: false,

cloud/linode/services/firewalls.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func (l *LinodeClient) DeleteNodeBalancerFirewall(
8686
}
8787

8888
func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRule) bool {
89+
if ips == nil {
90+
return false
91+
}
92+
8993
var ruleIPv4s []string
9094
var ruleIPv6s []string
9195

@@ -260,6 +264,7 @@ func chunkIPs(ips []string) [][]string {
260264
}
261265

262266
// Append the remaining IPs as a chunk.
267+
// nolint:nilaway // we can safely slice into ips because we know it's not empty
263268
chunks = append(chunks, ips[chunkCount*maxIPsPerFirewall:])
264269

265270
return chunks

0 commit comments

Comments
 (0)