Skip to content

Commit e1575ec

Browse files
authored
Merge branch 'main' into edit-template
2 parents abcf413 + f9a23e1 commit e1575ec

10 files changed

+295
-71
lines changed

.golangci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ linters:
9292
- errcheck
9393
- errchkjson
9494
- errorlint
95-
- govet
95+
#- govet
9696
- testifylint
9797
enable:
9898
# these are enabled by default
9999
#- errcheck
100100
- gosimple
101-
#- govet
101+
- govet
102102
- ineffassign
103103
- staticcheck
104104
- typecheck
@@ -123,7 +123,7 @@ linters:
123123
#- errorlint
124124
- exhaustive
125125
#- forbidigo
126-
#- forcetypeassert
126+
- forcetypeassert
127127
- gci
128128
- gocheckcompilerdirectives
129129
- gofmt
@@ -147,15 +147,15 @@ linters:
147147
- noctx
148148
- nolintlint
149149
- nosprintfhostport
150-
#- paralleltest
150+
#- paralleltest # adding t.Parallel() to tests broke so many and made others flaky
151151
- prealloc
152152
- predeclared
153153
- reassign
154-
#- tenv
155-
#- thelper
154+
- thelper
156155
- unconvert
157156
- unparam
158157
- usestdlibvars
158+
- usetesting
159159
- varnamelen
160160
- wastedassign
161161
- whitespace

cloud/linode/cilium_loadbalancers.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ func (l *loadbalancers) deleteSharedIP(ctx context.Context, service *v1.Service)
294294
}
295295
svcIngress := service.Status.LoadBalancer.Ingress
296296
if len(svcIngress) > 0 && ipHolder != nil {
297+
var nodeLinodeID int
298+
297299
for _, ingress := range svcIngress {
298300
// delete the shared IP on the Linodes it's shared on
299301
for _, node := range bgpNodes {
300-
nodeLinodeID, err := parseProviderID(node.Spec.ProviderID)
302+
nodeLinodeID, err = parseProviderID(node.Spec.ProviderID)
301303
if err != nil {
302304
return err
303305
}

cloud/linode/cilium_loadbalancers_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func TestCiliumCCMLoadBalancers(t *testing.T) {
141141
f: testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention,
142142
},
143143
}
144+
//nolint: paralleltest // two tests use t.Setenv, which fails after t.Parallel() call
144145
for _, tc := range testCases {
145146
ctrl := gomock.NewController(t)
146147
mc := mocks.NewMockClient(ctrl)
@@ -180,13 +181,17 @@ func createTestService() *v1.Service {
180181
}
181182

182183
func addService(t *testing.T, kubeClient kubernetes.Interface, svc *v1.Service) {
184+
t.Helper()
185+
183186
_, err := kubeClient.CoreV1().Services(svc.Namespace).Create(context.TODO(), svc, metav1.CreateOptions{})
184187
if err != nil {
185188
t.Fatalf("failed to add Service: %v", err)
186189
}
187190
}
188191

189192
func addNodes(t *testing.T, kubeClient kubernetes.Interface, nodes []*v1.Node) {
193+
t.Helper()
194+
190195
for _, node := range nodes {
191196
_, err := kubeClient.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{})
192197
if err != nil {
@@ -206,6 +211,8 @@ func createNewIpHolderInstance() linodego.Instance {
206211
}
207212

208213
func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) {
214+
t.Helper()
215+
209216
Options.BGPNodeSelector = ""
210217
Options.IpHolderSuffix = clusterName
211218
t.Setenv("BGP_PEER_PREFIX", "2600:3cef")
@@ -255,6 +262,8 @@ func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) {
255262
}
256263

257264
func testUnsupportedRegion(t *testing.T, mc *mocks.MockClient) {
265+
t.Helper()
266+
258267
Options.BGPNodeSelector = nodeSelector
259268
svc := createTestService()
260269

@@ -284,6 +293,8 @@ func testUnsupportedRegion(t *testing.T, mc *mocks.MockClient) {
284293
}
285294

286295
func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
296+
t.Helper()
297+
287298
Options.BGPNodeSelector = nodeSelector
288299
svc := createTestService()
289300
newIpHolderInstance = createNewIpHolderInstance()
@@ -323,6 +334,8 @@ func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T,
323334
}
324335

325336
func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
337+
t.Helper()
338+
326339
Options.BGPNodeSelector = nodeSelector
327340
Options.IpHolderSuffix = clusterName
328341
svc := createTestService()
@@ -363,6 +376,8 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T,
363376
}
364377

365378
func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffix(t *testing.T, mc *mocks.MockClient) {
379+
t.Helper()
380+
366381
Options.BGPNodeSelector = nodeSelector
367382
Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp"
368383
svc := createTestService()
@@ -403,6 +418,8 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi
403418
}
404419

405420
func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockClient) {
421+
t.Helper()
422+
406423
Options.BGPNodeSelector = nodeSelector
407424
Options.IpHolderSuffix = ""
408425
svc := createTestService()
@@ -447,6 +464,8 @@ func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockC
447464
}
448465

449466
func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.MockClient) {
467+
t.Helper()
468+
450469
Options.BGPNodeSelector = nodeSelector
451470
Options.IpHolderSuffix = clusterName
452471
svc := createTestService()
@@ -491,6 +510,8 @@ func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.Mo
491510
}
492511

493512
func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.MockClient) {
513+
t.Helper()
514+
494515
Options.BGPNodeSelector = nodeSelector
495516
Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp"
496517
svc := createTestService()
@@ -535,6 +556,8 @@ func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.Moc
535556
}
536557

537558
func testEnsureCiliumLoadBalancerDeletedWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
559+
t.Helper()
560+
538561
Options.BGPNodeSelector = nodeSelector
539562
svc := createTestService()
540563

@@ -561,6 +584,8 @@ func testEnsureCiliumLoadBalancerDeletedWithOldIpHolderNamingConvention(t *testi
561584
}
562585

563586
func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
587+
t.Helper()
588+
564589
Options.BGPNodeSelector = nodeSelector
565590
Options.IpHolderSuffix = clusterName
566591
svc := createTestService()
@@ -592,6 +617,8 @@ func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testi
592617
}
593618

594619
func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
620+
t.Helper()
621+
595622
Options.BGPNodeSelector = nodeSelector
596623
svc := createTestService()
597624

@@ -648,6 +675,8 @@ func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testi
648675
}
649676

650677
func testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
678+
t.Helper()
679+
651680
Options.BGPNodeSelector = nodeSelector
652681
Options.IpHolderSuffix = clusterName
653682
svc := createTestService()

cloud/linode/cloud.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ func newCloud() (cloudprovider.Interface, error) {
115115
var healthChecker *healthChecker
116116

117117
if Options.EnableTokenHealthChecker {
118-
authenticated, err := client.CheckClientAuthenticated(context.TODO(), linodeClient)
118+
var authenticated bool
119+
authenticated, err = client.CheckClientAuthenticated(context.TODO(), linodeClient)
119120
if err != nil {
120121
return nil, fmt.Errorf("linode client authenticated connection error: %w", err)
121122
}
@@ -187,7 +188,12 @@ func (c *linodeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBui
187188
go c.linodeTokenHealthChecker.Run(stopCh)
188189
}
189190

190-
serviceController := newServiceController(c.loadbalancers.(*loadbalancers), serviceInformer)
191+
lb, assertion := c.loadbalancers.(*loadbalancers)
192+
if !assertion {
193+
klog.Error("type assertion during Initialize() failed")
194+
return
195+
}
196+
serviceController := newServiceController(lb, serviceInformer)
191197
go serviceController.Run(stopCh)
192198

193199
nodeController := newNodeController(kubeclient, c.client, nodeInformer, instanceCache)

cloud/linode/fake_linode_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type fakeRequest struct {
4040
}
4141

4242
func newFake(t *testing.T) *fakeAPI {
43+
t.Helper()
44+
4345
fake := &fakeAPI{
4446
t: t,
4547
nb: make(map[string]*linodego.NodeBalancer),

cloud/linode/health_check_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func TestHealthCheck(t *testing.T) {
4141
}
4242

4343
func testSucceedingCallsToLinodeAPIHappenStopSignalNotFired(t *testing.T, client *mocks.MockClient) {
44+
t.Helper()
45+
4446
writableStopCh := make(chan struct{})
4547
readableStopCh := make(chan struct{})
4648

@@ -62,6 +64,8 @@ func testSucceedingCallsToLinodeAPIHappenStopSignalNotFired(t *testing.T, client
6264
}
6365

6466
func testFailingCallsToLinodeAPIHappenStopSignalFired(t *testing.T, client *mocks.MockClient) {
67+
t.Helper()
68+
6569
writableStopCh := make(chan struct{})
6670
readableStopCh := make(chan struct{})
6771

@@ -95,6 +99,8 @@ func testFailingCallsToLinodeAPIHappenStopSignalFired(t *testing.T, client *mock
9599
}
96100

97101
func testErrorCallsToLinodeAPIHappenStopSignalNotFired(t *testing.T, client *mocks.MockClient) {
102+
t.Helper()
103+
98104
writableStopCh := make(chan struct{})
99105
readableStopCh := make(chan struct{})
100106

0 commit comments

Comments
 (0)