Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1b9b441
Added linters and settings
Andrews2024 Mar 3, 2025
dafe116
golangci-lint --fix fixes
Andrews2024 Mar 3, 2025
8167db6
Fixed goconst lint errors
Andrews2024 Mar 4, 2025
1a3c10e
Temporarily disabled several linters and fixed nolintlint errors
Andrews2024 Mar 4, 2025
8f6d9b1
Merge branch 'main' into golint-update
Andrews2024 Mar 4, 2025
6b32d93
Addressed comments
Andrews2024 Mar 4, 2025
a9ce5f6
Fixed remaining goconst errors
Andrews2024 Mar 5, 2025
59f2801
Fixed varnamelen errors
Andrews2024 Mar 5, 2025
aa3836c
Fixed prealloc errors
Andrews2024 Mar 5, 2025
e5cb40b
Temporarily resolved depgaurd reflect error
Andrews2024 Mar 5, 2025
e9e0e26
Merge branch 'main' into golint-update
Andrews2024 Mar 5, 2025
0bee7c8
Resolved thelper issues and switched tenv to usetesting
Andrews2024 Mar 5, 2025
b333480
Resolved paralleltest errors
Andrews2024 Mar 6, 2025
d4f2740
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 6, 2025
0819344
Fixed small errors from merge
Andrews2024 Mar 6, 2025
7b71da3
Merge branch 'main' into golint-update
Andrews2024 Mar 6, 2025
da91a34
Removed unused thelper configuration
Andrews2024 Mar 6, 2025
f93ea50
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 6, 2025
5584cdf
Fixed bug from merge
Andrews2024 Mar 6, 2025
382d8d4
Resolved setenv after t.Parallel error
Andrews2024 Mar 6, 2025
ffafbc3
Resolved setenv after t.Parallel error
Andrews2024 Mar 6, 2025
ab7bb25
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 6, 2025
1bc145b
Revert "Resolved paralleltest errors" due to major testing issues
Andrews2024 Mar 7, 2025
ba27a3a
Added annotation for paralleltest and resolved govet errors
Andrews2024 Mar 7, 2025
d2c6669
Resolved forcetypeassert errors
Andrews2024 Mar 7, 2025
b943dad
Updated GHA to use make lint
Andrews2024 Mar 7, 2025
a65c855
Updated GHA to use make lint
Andrews2024 Mar 7, 2025
03e2713
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 7, 2025
489b95b
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 7, 2025
b742af5
Merge branch 'golint-update' of github.com:linode/linode-cloud-contro…
Andrews2024 Mar 7, 2025
466de62
Enabled docker image for build-test for linting
Andrews2024 Mar 7, 2025
604b10d
Preventing refused connection when connecting to docker registry
Andrews2024 Mar 7, 2025
61dbc64
WIP: Attempt to resolve staticcheck error with GHA
Andrews2024 Mar 10, 2025
900edef
WIP: Try explicit return to satisfy staticcheck
Andrews2024 Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ linters:
- errcheck
- errchkjson
- errorlint
- govet
#- govet
- testifylint
enable:
# these are enabled by default
#- errcheck
- gosimple
#- govet
- govet
- ineffassign
- staticcheck
- typecheck
Expand All @@ -123,7 +123,7 @@ linters:
#- errorlint
- exhaustive
#- forbidigo
#- forcetypeassert
- forcetypeassert
- gci
- gocheckcompilerdirectives
- gofmt
Expand All @@ -147,15 +147,15 @@ linters:
- noctx
- nolintlint
- nosprintfhostport
#- paralleltest
#- paralleltest # adding t.Parallel() to tests broke so many and made others flaky
- prealloc
- predeclared
- reassign
#- tenv
#- thelper
- thelper
- unconvert
- unparam
- usestdlibvars
- usetesting
- varnamelen
- wastedassign
- whitespace
Expand Down
4 changes: 3 additions & 1 deletion cloud/linode/cilium_loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ func (l *loadbalancers) deleteSharedIP(ctx context.Context, service *v1.Service)
}
svcIngress := service.Status.LoadBalancer.Ingress
if len(svcIngress) > 0 && ipHolder != nil {
var nodeLinodeID int

for _, ingress := range svcIngress {
// delete the shared IP on the Linodes it's shared on
for _, node := range bgpNodes {
nodeLinodeID, err := parseProviderID(node.Spec.ProviderID)
nodeLinodeID, err = parseProviderID(node.Spec.ProviderID)
if err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions cloud/linode/cilium_loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestCiliumCCMLoadBalancers(t *testing.T) {
f: testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention,
},
}
//nolint: paralleltest // two tests use t.Setenv, which fails after t.Parallel() call
for _, tc := range testCases {
ctrl := gomock.NewController(t)
mc := mocks.NewMockClient(ctrl)
Expand Down Expand Up @@ -180,13 +181,17 @@ func createTestService() *v1.Service {
}

func addService(t *testing.T, kubeClient kubernetes.Interface, svc *v1.Service) {
t.Helper()

_, err := kubeClient.CoreV1().Services(svc.Namespace).Create(context.TODO(), svc, metav1.CreateOptions{})
if err != nil {
t.Fatalf("failed to add Service: %v", err)
}
}

func addNodes(t *testing.T, kubeClient kubernetes.Interface, nodes []*v1.Node) {
t.Helper()

for _, node := range nodes {
_, err := kubeClient.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{})
if err != nil {
Expand All @@ -206,6 +211,8 @@ func createNewIpHolderInstance() linodego.Instance {
}

func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = ""
Options.IpHolderSuffix = clusterName
t.Setenv("BGP_PEER_PREFIX", "2600:3cef")
Expand Down Expand Up @@ -255,6 +262,8 @@ func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) {
}

func testUnsupportedRegion(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
svc := createTestService()

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

func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
svc := createTestService()
newIpHolderInstance = createNewIpHolderInstance()
Expand Down Expand Up @@ -323,6 +334,8 @@ func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T,
}

func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = clusterName
svc := createTestService()
Expand Down Expand Up @@ -363,6 +376,8 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T,
}

func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffix(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp"
svc := createTestService()
Expand Down Expand Up @@ -403,6 +418,8 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi
}

func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = ""
svc := createTestService()
Expand Down Expand Up @@ -447,6 +464,8 @@ func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockC
}

func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = clusterName
svc := createTestService()
Expand Down Expand Up @@ -491,6 +510,8 @@ func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.Mo
}

func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp"
svc := createTestService()
Expand Down Expand Up @@ -535,6 +556,8 @@ func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.Moc
}

func testEnsureCiliumLoadBalancerDeletedWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
svc := createTestService()

Expand All @@ -561,6 +584,8 @@ func testEnsureCiliumLoadBalancerDeletedWithOldIpHolderNamingConvention(t *testi
}

func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = clusterName
svc := createTestService()
Expand Down Expand Up @@ -592,6 +617,8 @@ func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testi
}

func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
svc := createTestService()

Expand Down Expand Up @@ -648,6 +675,8 @@ func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testi
}

func testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) {
t.Helper()

Options.BGPNodeSelector = nodeSelector
Options.IpHolderSuffix = clusterName
svc := createTestService()
Expand Down
10 changes: 8 additions & 2 deletions cloud/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
var healthChecker *healthChecker

if Options.EnableTokenHealthChecker {
authenticated, err := client.CheckClientAuthenticated(context.TODO(), linodeClient)
var authenticated bool
authenticated, err = client.CheckClientAuthenticated(context.TODO(), linodeClient)

Check warning on line 119 in cloud/linode/cloud.go

View check run for this annotation

Codecov / codecov/patch

cloud/linode/cloud.go#L118-L119

Added lines #L118 - L119 were not covered by tests
if err != nil {
return nil, fmt.Errorf("linode client authenticated connection error: %w", err)
}
Expand Down Expand Up @@ -187,7 +188,12 @@
go c.linodeTokenHealthChecker.Run(stopCh)
}

serviceController := newServiceController(c.loadbalancers.(*loadbalancers), serviceInformer)
lb, assertion := c.loadbalancers.(*loadbalancers)
if !assertion {
klog.Error("type assertion during Initialize() failed")
return
}
serviceController := newServiceController(lb, serviceInformer)

Check warning on line 196 in cloud/linode/cloud.go

View check run for this annotation

Codecov / codecov/patch

cloud/linode/cloud.go#L191-L196

Added lines #L191 - L196 were not covered by tests
go serviceController.Run(stopCh)

nodeController := newNodeController(kubeclient, c.client, nodeInformer, instanceCache)
Expand Down
2 changes: 2 additions & 0 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type fakeRequest struct {
}

func newFake(t *testing.T) *fakeAPI {
t.Helper()

fake := &fakeAPI{
t: t,
nb: make(map[string]*linodego.NodeBalancer),
Expand Down
6 changes: 6 additions & 0 deletions cloud/linode/health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func TestHealthCheck(t *testing.T) {
}

func testSucceedingCallsToLinodeAPIHappenStopSignalNotFired(t *testing.T, client *mocks.MockClient) {
t.Helper()

writableStopCh := make(chan struct{})
readableStopCh := make(chan struct{})

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

func testFailingCallsToLinodeAPIHappenStopSignalFired(t *testing.T, client *mocks.MockClient) {
t.Helper()

writableStopCh := make(chan struct{})
readableStopCh := make(chan struct{})

Expand Down Expand Up @@ -95,6 +99,8 @@ func testFailingCallsToLinodeAPIHappenStopSignalFired(t *testing.T, client *mock
}

func testErrorCallsToLinodeAPIHappenStopSignalNotFired(t *testing.T, client *mocks.MockClient) {
t.Helper()

writableStopCh := make(chan struct{})
readableStopCh := make(chan struct{})

Expand Down
1 change: 0 additions & 1 deletion cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
cloudprovider "k8s.io/cloud-provider"

"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"

)

const (
Expand Down
Loading
Loading