diff --git a/.golangci.yml b/.golangci.yml index ecdaa2cb..45d31060 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -92,13 +92,13 @@ linters: - errcheck - errchkjson - errorlint - - govet + #- govet - testifylint enable: # these are enabled by default #- errcheck - gosimple - #- govet + - govet - ineffassign - staticcheck - typecheck @@ -123,7 +123,7 @@ linters: #- errorlint - exhaustive #- forbidigo - #- forcetypeassert + - forcetypeassert - gci - gocheckcompilerdirectives - gofmt @@ -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 diff --git a/cloud/linode/cilium_loadbalancers.go b/cloud/linode/cilium_loadbalancers.go index f69bc0c8..4dc30a61 100644 --- a/cloud/linode/cilium_loadbalancers.go +++ b/cloud/linode/cilium_loadbalancers.go @@ -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 } diff --git a/cloud/linode/cilium_loadbalancers_test.go b/cloud/linode/cilium_loadbalancers_test.go index 1d55eb2c..f19fa6d2 100644 --- a/cloud/linode/cilium_loadbalancers_test.go +++ b/cloud/linode/cilium_loadbalancers_test.go @@ -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) @@ -180,6 +181,8 @@ 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) @@ -187,6 +190,8 @@ func addService(t *testing.T, kubeClient kubernetes.Interface, svc *v1.Service) } 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 { @@ -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") @@ -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() @@ -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() @@ -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() @@ -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() @@ -403,6 +418,8 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi } func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockClient) { + t.Helper() + Options.BGPNodeSelector = nodeSelector Options.IpHolderSuffix = "" svc := createTestService() @@ -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() @@ -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() @@ -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() @@ -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() @@ -592,6 +617,8 @@ func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testi } func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) { + t.Helper() + Options.BGPNodeSelector = nodeSelector svc := createTestService() @@ -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() diff --git a/cloud/linode/cloud.go b/cloud/linode/cloud.go index c901891f..ce50adaa 100644 --- a/cloud/linode/cloud.go +++ b/cloud/linode/cloud.go @@ -115,7 +115,8 @@ func newCloud() (cloudprovider.Interface, error) { var healthChecker *healthChecker if Options.EnableTokenHealthChecker { - authenticated, err := client.CheckClientAuthenticated(context.TODO(), linodeClient) + var authenticated bool + authenticated, err = client.CheckClientAuthenticated(context.TODO(), linodeClient) if err != nil { return nil, fmt.Errorf("linode client authenticated connection error: %w", err) } @@ -187,7 +188,12 @@ func (c *linodeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBui 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) go serviceController.Run(stopCh) nodeController := newNodeController(kubeclient, c.client, nodeInformer, instanceCache) diff --git a/cloud/linode/fake_linode_test.go b/cloud/linode/fake_linode_test.go index 43f366a6..47e990c6 100644 --- a/cloud/linode/fake_linode_test.go +++ b/cloud/linode/fake_linode_test.go @@ -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), diff --git a/cloud/linode/health_check_test.go b/cloud/linode/health_check_test.go index 7ba7cd57..b7e71972 100644 --- a/cloud/linode/health_check_test.go +++ b/cloud/linode/health_check_test.go @@ -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{}) @@ -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{}) @@ -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{}) diff --git a/cloud/linode/instances_test.go b/cloud/linode/instances_test.go index a1cd328e..cc88d8c4 100644 --- a/cloud/linode/instances_test.go +++ b/cloud/linode/instances_test.go @@ -17,7 +17,6 @@ import ( cloudprovider "k8s.io/cloud-provider" "github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks" - ) const ( diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index 557e1a13..629760a1 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1" ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1" "github.com/linode/linodego" v1 "k8s.io/api/core/v1" @@ -208,7 +209,8 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri } // check for existing CiliumLoadBalancerIPPool for service - pool, err := l.getCiliumLBIPPool(ctx, service) + var pool *v2alpha1.CiliumLoadBalancerIPPool + pool, err = l.getCiliumLBIPPool(ctx, service) if err != nil && !k8serrors.IsNotFound(err) { klog.Infof("Failed to get CiliumLoadBalancerIPPool: %s", err.Error()) return nil, err @@ -368,7 +370,8 @@ func (l *loadbalancers) updateNodeBalancer( oldNBNodeIDs := make(map[string]int) if currentNBCfg != nil { // Obtain list of current NB nodes and convert it to map of node IDs - currentNBNodes, err := l.client.ListNodeBalancerNodes(ctx, nb.ID, currentNBCfg.ID, nil) + var currentNBNodes []linodego.NodeBalancerNode + currentNBNodes, err = l.client.ListNodeBalancerNodes(ctx, nb.ID, currentNBCfg.ID, nil) if err != nil { // This error can be ignored, because if we fail to get nodes we can anyway rebuild the config from scratch, // it would just cause the NB to reload config even if the node list did not change, so we prefer to send IDs when it is posible. @@ -386,13 +389,15 @@ func (l *loadbalancers) updateNodeBalancer( subnetID := 0 backendIPv4Range, ok := service.GetAnnotations()[annotations.NodeBalancerBackendIPv4Range] if ok { - if err := validateNodeBalancerBackendIPv4Range(backendIPv4Range); err != nil { + if err = validateNodeBalancerBackendIPv4Range(backendIPv4Range); err != nil { return err } - id, err := l.getSubnetIDForSVC(ctx, service) + + var id int + id, err = l.getSubnetIDForSVC(ctx, service) if err != nil { sentry.CaptureError(ctx, err) - return fmt.Errorf("Error getting subnet ID for service %s: %v", service.Name, err) + return fmt.Errorf("Error getting subnet ID for service %s: %w", service.Name, err) } subnetID = id } @@ -456,7 +461,7 @@ func (l *loadbalancers) UpdateLoadBalancer(ctx context.Context, clusterName stri // make sure that IPs are shared properly on the Node if using load-balancers not backed by NodeBalancers for _, node := range nodes { - if err := l.handleIPSharing(ctx, node, ipHolderSuffix); err != nil { + if err = l.handleIPSharing(ctx, node, ipHolderSuffix); err != nil { return err } } @@ -711,7 +716,7 @@ func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName stri } func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1.Service, port int) (linodego.NodeBalancerConfig, error) { - portConfig, err := getPortConfig(service, port) + portConfigResult, err := getPortConfig(service, port) if err != nil { return linodego.NodeBalancerConfig{}, err } @@ -723,8 +728,8 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 config := linodego.NodeBalancerConfig{ Port: port, - Protocol: portConfig.Protocol, - ProxyProtocol: portConfig.ProxyProtocol, + Protocol: portConfigResult.Protocol, + ProxyProtocol: portConfigResult.ProxyProtocol, Check: health, } @@ -775,8 +780,8 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1 } config.CheckPassive = checkPassive - if portConfig.Protocol == linodego.ProtocolHTTPS { - if err = l.addTLSCert(ctx, service, &config, portConfig); err != nil { + if portConfigResult.Protocol == linodego.ProtocolHTTPS { + if err = l.addTLSCert(ctx, service, &config, portConfigResult); err != nil { return config, err } } @@ -922,12 +927,12 @@ func (l *loadbalancers) retrieveKubeClient() error { } func getPortConfig(service *v1.Service, port int) (portConfig, error) { - portConfig := portConfig{} - portConfigAnnotation, err := getPortConfigAnnotation(service, port) + portConfigResult := portConfig{} + portConfigAnnotationResult, err := getPortConfigAnnotation(service, port) if err != nil { - return portConfig, err + return portConfigResult, err } - protocol := portConfigAnnotation.Protocol + protocol := portConfigAnnotationResult.Protocol if protocol == "" { protocol = "tcp" if p, ok := service.GetAnnotations()[annotations.AnnLinodeDefaultProtocol]; ok { @@ -936,7 +941,7 @@ func getPortConfig(service *v1.Service, port int) (portConfig, error) { } protocol = strings.ToLower(protocol) - proxyProtocol := portConfigAnnotation.ProxyProtocol + proxyProtocol := portConfigAnnotationResult.ProxyProtocol if proxyProtocol == "" { proxyProtocol = string(linodego.ProxyProtocolNone) for _, ann := range []string{annotations.AnnLinodeDefaultProxyProtocol, annLinodeProxyProtocolDeprecated} { @@ -948,22 +953,22 @@ func getPortConfig(service *v1.Service, port int) (portConfig, error) { } if protocol != "tcp" && protocol != "http" && protocol != "https" { - return portConfig, fmt.Errorf("invalid protocol: %q specified", protocol) + return portConfigResult, fmt.Errorf("invalid protocol: %q specified", protocol) } switch proxyProtocol { case string(linodego.ProxyProtocolNone), string(linodego.ProxyProtocolV1), string(linodego.ProxyProtocolV2): break default: - return portConfig, fmt.Errorf("invalid NodeBalancer proxy protocol value '%s'", proxyProtocol) + return portConfigResult, fmt.Errorf("invalid NodeBalancer proxy protocol value '%s'", proxyProtocol) } - portConfig.Port = port - portConfig.Protocol = linodego.ConfigProtocol(protocol) - portConfig.ProxyProtocol = linodego.ConfigProxyProtocol(proxyProtocol) - portConfig.TLSSecretName = portConfigAnnotation.TLSSecretName + portConfigResult.Port = port + portConfigResult.Protocol = linodego.ConfigProtocol(protocol) + portConfigResult.ProxyProtocol = linodego.ConfigProxyProtocol(proxyProtocol) + portConfigResult.TLSSecretName = portConfigAnnotationResult.TLSSecretName - return portConfig, nil + return portConfigResult, nil } func getHealthCheckType(service *v1.Service) (linodego.ConfigCheck, error) { @@ -1134,7 +1139,7 @@ func validateNodeBalancerBackendIPv4Range(backendIPv4Range string) error { } withinCIDR, err := isCIDRWithinCIDR(Options.NodeBalancerBackendIPv4Subnet, backendIPv4Range) if err != nil { - return fmt.Errorf("invalid IPv4 range: %v", err) + return fmt.Errorf("invalid IPv4 range: %w", err) } if !withinCIDR { return fmt.Errorf("IPv4 range %s is not within the subnet %s", backendIPv4Range, Options.NodeBalancerBackendIPv4Subnet) @@ -1146,11 +1151,11 @@ func validateNodeBalancerBackendIPv4Range(backendIPv4Range string) error { func isCIDRWithinCIDR(outer, inner string) (bool, error) { _, ipNet1, err := net.ParseCIDR(outer) if err != nil { - return false, fmt.Errorf("invalid CIDR: %v", err) + return false, fmt.Errorf("invalid CIDR: %w", err) } _, ipNet2, err := net.ParseCIDR(inner) if err != nil { - return false, fmt.Errorf("invalid CIDR: %v", err) + return false, fmt.Errorf("invalid CIDR: %w", err) } return ipNet1.Contains(ipNet2.IP), nil } diff --git a/cloud/linode/loadbalancers_test.go b/cloud/linode/loadbalancers_test.go index 3ef2cd08..1303d15b 100644 --- a/cloud/linode/loadbalancers_test.go +++ b/cloud/linode/loadbalancers_test.go @@ -303,6 +303,8 @@ func stubService(fake *fake.Clientset, service *v1.Service) { } func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, annMap map[string]string, expectedTags []string) error { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -332,7 +334,10 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, a for key, value := range annMap { svc.Annotations[key] = value } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } nodes := []*v1.Node{ {ObjectMeta: metav1.ObjectMeta{Name: "node-1"}}, } @@ -396,6 +401,8 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, a } func testCreateNodeBalancerWithOutFirewall(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + err := testCreateNodeBalancer(t, client, f, nil, nil) if err != nil { t.Fatalf("expected a nil error, got %v", err) @@ -403,6 +410,8 @@ func testCreateNodeBalancerWithOutFirewall(t *testing.T, client *linodego.Client } func testCreateNodeBalanceWithNoAllowOrDenyList(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallACL: `{}`, } @@ -414,6 +423,8 @@ func testCreateNodeBalanceWithNoAllowOrDenyList(t *testing.T, client *linodego.C } func testCreateNodeBalanceWithBothAllowOrDenyList(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallACL: `{ "allowList": { @@ -434,6 +445,8 @@ func testCreateNodeBalanceWithBothAllowOrDenyList(t *testing.T, client *linodego } func testCreateNodeBalancerWithAllowList(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallACL: `{ "allowList": { @@ -450,6 +463,8 @@ func testCreateNodeBalancerWithAllowList(t *testing.T, client *linodego.Client, } func testCreateNodeBalancerWithDenyList(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallACL: `{ "denyList": { @@ -466,6 +481,8 @@ func testCreateNodeBalancerWithDenyList(t *testing.T, client *linodego.Client, f } func testCreateNodeBalancerWithFirewall(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallID: "123", } @@ -476,6 +493,8 @@ func testCreateNodeBalancerWithFirewall(t *testing.T, client *linodego.Client, f } func testCreateNodeBalancerWithInvalidFirewall(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + annotations := map[string]string{ annotations.AnnLinodeCloudFirewallID: "qwerty", } @@ -487,6 +506,8 @@ func testCreateNodeBalancerWithInvalidFirewall(t *testing.T, client *linodego.Cl } func testCreateNodeBalancerWithGlobalTags(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + original := Options.NodeBalancerTags defer func() { Options.NodeBalancerTags = original @@ -500,6 +521,8 @@ func testCreateNodeBalancerWithGlobalTags(t *testing.T, client *linodego.Client, } func testCreateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + // test when no VPCs are present ann := map[string]string{ annotations.NodeBalancerBackendIPv4Range: "10.100.0.0/30", @@ -550,6 +573,8 @@ func testCreateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client, } func testUpdateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + // provision vpc and test vpcNames := Options.VPCNames subnetNames := Options.SubnetNames @@ -604,7 +629,10 @@ func testUpdateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client, }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -630,6 +658,8 @@ func testUpdateNodeBalancerWithVPCBackend(t *testing.T, client *linodego.Client, } func testCreateNodeBalancerWithVPCAnnotationOverwrite(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + // provision multiple vpcs vpcNames := Options.VPCNames nodebalancerBackendIPv4Subnet := Options.NodeBalancerBackendIPv4Subnet @@ -675,6 +705,8 @@ func testCreateNodeBalancerWithVPCAnnotationOverwrite(t *testing.T, client *lino } func testUpdateLoadBalancerAddNode(t *testing.T, client *linodego.Client, f *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -738,7 +770,10 @@ func testUpdateLoadBalancerAddNode(t *testing.T, client *linodego.Client, f *fak }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -773,11 +808,12 @@ func testUpdateLoadBalancerAddNode(t *testing.T, client *linodego.Client, f *fak if req == nil { t.Fatalf("Nodebalancer config rebuild request was not called.") + return 0, 0 // explicitly return to satisfy staticcheck } var nbcro linodego.NodeBalancerConfigRebuildOptions - if err := json.Unmarshal([]byte(req.Body), &nbcro); err != nil { + if err = json.Unmarshal([]byte(req.Body), &nbcro); err != nil { t.Fatalf("Unable to unmarshall request body %#v, error: %#v", req.Body, err) } @@ -864,6 +900,8 @@ func testUpdateLoadBalancerAddNode(t *testing.T, client *linodego.Client, f *fak } func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -897,7 +935,10 @@ func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client, }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -934,6 +975,8 @@ func testUpdateLoadBalancerAddAnnotation(t *testing.T, client *linodego.Client, } func testUpdateLoadBalancerAddPortAnnotation(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + targetTestPort := 80 portConfigAnnotation := fmt.Sprintf("%s%d", annotations.AnnLinodePortConfigPrefix, targetTestPort) svc := &v1.Service{ @@ -967,7 +1010,10 @@ func testUpdateLoadBalancerAddPortAnnotation(t *testing.T, client *linodego.Clie }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1021,6 +1067,8 @@ func toJSON(v interface{}) string { } func testVeryLongServiceName(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + ipv4DenyList := make([]string, 130) ipv6DenyList := make([]string, 130) @@ -1068,7 +1116,10 @@ func testVeryLongServiceName(t *testing.T, client *linodego.Client, _ *fakeAPI) }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1099,6 +1150,8 @@ func testVeryLongServiceName(t *testing.T, client *linodego.Client, _ *fakeAPI) } func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1130,7 +1183,10 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset clusterName := "linodelb" @@ -1170,6 +1226,8 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak } func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1210,7 +1268,10 @@ func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ * NodePort: int32(30001), } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } defer func() { _ = lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) @@ -1272,6 +1333,8 @@ func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ * } func testUpdateLoadBalancerAddProxyProtocol(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + nodes := []*v1.Node{ { Status: v1.NodeStatus{ @@ -1285,7 +1348,10 @@ func testUpdateLoadBalancerAddProxyProtocol(t *testing.T, client *linodego.Clien }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1375,6 +1441,8 @@ func testUpdateLoadBalancerAddProxyProtocol(t *testing.T, client *linodego.Clien } func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1408,7 +1476,10 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client, }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1473,6 +1544,8 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client, // This will also test the firewall with >255 IPs func testUpdateLoadBalancerAddNewFirewallACL(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1503,7 +1576,10 @@ func testUpdateLoadBalancerAddNewFirewallACL(t *testing.T, client *linodego.Clie }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1541,7 +1617,7 @@ func testUpdateLoadBalancerAddNewFirewallACL(t *testing.T, client *linodego.Clie i = 0 for i < 300 { ip := make([]byte, 16) - if _, err := cryptoRand.Read(ip); err != nil { + if _, err = cryptoRand.Read(ip); err != nil { t.Fatalf("unable to read random bytes") } ipv6s = append(ipv6s, fmt.Sprintf("%s:%s:%s:%s:%s:%s:%s:%s", @@ -1599,6 +1675,8 @@ func testUpdateLoadBalancerAddNewFirewallACL(t *testing.T, client *linodego.Clie } func testUpdateLoadBalancerDeleteFirewallRemoveACL(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1629,7 +1707,10 @@ func testUpdateLoadBalancerDeleteFirewallRemoveACL(t *testing.T, client *linodeg }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1692,6 +1773,8 @@ func testUpdateLoadBalancerDeleteFirewallRemoveACL(t *testing.T, client *linodeg } func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1722,7 +1805,10 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1826,6 +1912,8 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li } func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1856,7 +1944,10 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -1959,6 +2050,8 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li } func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -1996,7 +2089,10 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -2181,6 +2277,8 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie } func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + firewallCreateOpts := linodego.FirewallCreateOptions{ Label: "test", Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ @@ -2228,7 +2326,10 @@ func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client, }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -2311,6 +2412,8 @@ func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client, } func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + firewallCreateOpts := linodego.FirewallCreateOptions{ Label: "test", Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ @@ -2355,7 +2458,10 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset @@ -2419,6 +2525,8 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego } func testUpdateLoadBalancerAddNodeBalancerID(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -2450,7 +2558,10 @@ func testUpdateLoadBalancerAddNodeBalancerID(t *testing.T, client *linodego.Clie }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } defer func() { _ = lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) }() @@ -2744,12 +2855,12 @@ func Test_getPortConfig(t *testing.T) { for _, test := range testcases { t.Run(test.name, func(t *testing.T) { testPort := 443 - portConfig, err := getPortConfig(test.service, testPort) + portConfigResult, err := getPortConfig(test.service, testPort) - if !reflect.DeepEqual(portConfig, test.expectedPortConfig) { + if !reflect.DeepEqual(portConfigResult, test.expectedPortConfig) { t.Error("unexpected port config") t.Logf("expected: %q", test.expectedPortConfig) - t.Logf("actual: %q", portConfig) + t.Logf("actual: %q", portConfigResult) } if !reflect.DeepEqual(err, test.err) { @@ -2920,6 +3031,8 @@ func Test_getNodePrivateIP(t *testing.T) { } func testBuildLoadBalancerRequest(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "test", @@ -2957,7 +3070,10 @@ func testBuildLoadBalancerRequest(t *testing.T, client *linodego.Client, _ *fake }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } nb, err := lb.buildLoadBalancerRequest(context.TODO(), "linodelb", svc, nodes) if err != nil { t.Fatal(err) @@ -2993,6 +3109,8 @@ func testBuildLoadBalancerRequest(t *testing.T, client *linodego.Client, _ *fake } func testEnsureLoadBalancerPreserveAnnotation(t *testing.T, client *linodego.Client, fake *fakeAPI) { + t.Helper() + testServiceSpec := v1.ServiceSpec{ Ports: []v1.ServicePort{ { @@ -3004,7 +3122,10 @@ func testEnsureLoadBalancerPreserveAnnotation(t *testing.T, client *linodego.Cli }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } for _, test := range []struct { name string deleted bool @@ -3059,6 +3180,8 @@ func testEnsureLoadBalancerPreserveAnnotation(t *testing.T, client *linodego.Cli } func testEnsureLoadBalancerDeleted(t *testing.T, client *linodego.Client, fake *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "test", @@ -3116,7 +3239,10 @@ func testEnsureLoadBalancerDeleted(t *testing.T, client *linodego.Client, fake * }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } configs := []*linodego.NodeBalancerConfigCreateOptions{} _, err := lb.createNodeBalancer(context.TODO(), "linodelb", svc, configs) if err != nil { @@ -3137,6 +3263,8 @@ func testEnsureLoadBalancerDeleted(t *testing.T, client *linodego.Client, fake * } func testEnsureExistingLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "testensure", @@ -3164,7 +3292,10 @@ func testEnsureExistingLoadBalancer(t *testing.T, client *linodego.Client, _ *fa }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } lb.kubeClient = fake.NewSimpleClientset() addTLSSecret(t, lb.kubeClient) @@ -3263,6 +3394,8 @@ func testEnsureExistingLoadBalancer(t *testing.T, client *linodego.Client, _ *fa } func testMakeLoadBalancerStatus(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + ipv4 := "192.168.0.1" hostname := "nb-192-168-0-1.newark.nodebalancer.linode.com" nb := &linodego.NodeBalancer{ @@ -3297,6 +3430,8 @@ func testMakeLoadBalancerStatus(t *testing.T, client *linodego.Client, _ *fakeAP } func testMakeLoadBalancerStatusWithIPv6(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + ipv4 := "192.168.0.1" ipv6 := "2600:3c00::f03c:91ff:fe24:3a2f" hostname := "nb-192-168-0-1.newark.nodebalancer.linode.com" @@ -3362,6 +3497,8 @@ func testMakeLoadBalancerStatusWithIPv6(t *testing.T, client *linodego.Client, _ } func testMakeLoadBalancerStatusEnvVar(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + ipv4 := "192.168.0.1" hostname := "nb-192-168-0-1.newark.nodebalancer.linode.com" nb := &linodego.NodeBalancer{ @@ -3411,6 +3548,8 @@ func testMakeLoadBalancerStatusEnvVar(t *testing.T, client *linodego.Client, _ * } func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) { + t.Helper() + region := "us-west" nb1, err := client.CreateNodeBalancer(context.TODO(), linodego.NodeBalancerCreateOptions{Region: region}) if err != nil { @@ -3430,7 +3569,10 @@ func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeA } svc.Status.LoadBalancer = *makeLoadBalancerStatus(svc, nb1) svcAnn.Status.LoadBalancer = *makeLoadBalancerStatus(svcAnn, nb1) - lb := newLoadbalancers(client, region).(*loadbalancers) + lb, assertion := newLoadbalancers(client, region).(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } fakeAPI.ResetRequests() t.Run("non-annotated service shouldn't call the API during cleanup", func(t *testing.T) { @@ -3459,6 +3601,8 @@ func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeA } func testUpdateLoadBalancerNoNodes(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: randString(), @@ -3477,7 +3621,10 @@ func testUpdateLoadBalancerNoNodes(t *testing.T, client *linodego.Client, _ *fak }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } defer func() { _ = lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) }() @@ -3510,7 +3657,12 @@ func testUpdateLoadBalancerNoNodes(t *testing.T, client *linodego.Client, _ *fak } func testGetNodeBalancerForServiceIDDoesNotExist(t *testing.T, client *linodego.Client, _ *fakeAPI) { - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + t.Helper() + + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } bogusNodeBalancerID := "123456" svc := &v1.Service{ @@ -3549,7 +3701,12 @@ func testGetNodeBalancerForServiceIDDoesNotExist(t *testing.T, client *linodego. } func testEnsureNewLoadBalancerWithNodeBalancerID(t *testing.T, client *linodego.Client, _ *fakeAPI) { - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + t.Helper() + + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } nodeBalancer, err := client.CreateNodeBalancer(context.TODO(), linodego.NodeBalancerCreateOptions{ Region: lb.zone, }) @@ -3601,6 +3758,8 @@ func testEnsureNewLoadBalancerWithNodeBalancerID(t *testing.T, client *linodego. } func testEnsureNewLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { + t.Helper() + svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "testensure", @@ -3643,7 +3802,10 @@ func testEnsureNewLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI }, }, } - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } lb.kubeClient = fake.NewSimpleClientset() addTLSSecret(t, lb.kubeClient) @@ -3656,7 +3818,12 @@ func testEnsureNewLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI } func testGetLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { - lb := newLoadbalancers(client, "us-west").(*loadbalancers) + t.Helper() + + lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } svc := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "test", @@ -3903,6 +4070,8 @@ func Test_getTLSCertInfo(t *testing.T) { } func addTLSSecret(t *testing.T, kubeClient kubernetes.Interface) { + t.Helper() + _, err := kubeClient.CoreV1().Secrets("").Create(context.TODO(), &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "tls-secret", diff --git a/cloud/linode/service_controller_test.go b/cloud/linode/service_controller_test.go index 2bf04001..4a2ddd1c 100644 --- a/cloud/linode/service_controller_test.go +++ b/cloud/linode/service_controller_test.go @@ -24,7 +24,10 @@ func Test_serviceController_Run(t *testing.T) { informer := informers.NewSharedInformerFactory(kubeClient, 0).Core().V1().Services() mockQueue := workqueue.NewTypedDelayingQueueWithConfig(workqueue.TypedDelayingQueueConfig[any]{Name: "test"}) - loadbalancers := newLoadbalancers(client, "us-east").(*loadbalancers) + loadbalancers, assertion := newLoadbalancers(client, "us-east").(*loadbalancers) + if !assertion { + t.Error("type assertion failed") + } svcCtrl := newServiceController(loadbalancers, informer) svcCtrl.queue = mockQueue diff --git a/cloud/linode/vpc.go b/cloud/linode/vpc.go index 472306bd..81c73a9e 100644 --- a/cloud/linode/vpc.go +++ b/cloud/linode/vpc.go @@ -118,7 +118,8 @@ func GetVPCIPAddresses(ctx context.Context, client client.Client, vpcName string for _, name := range subnetNames { // For caching - subnetID, err := GetSubnetID(ctx, client, vpcID, name) + var subnetID int + subnetID, err = GetSubnetID(ctx, client, vpcID, name) // Don't filter subnets we can't find if err != nil { klog.Errorf("subnet %s not found due to error: %v. Skipping.", name, err) @@ -130,7 +131,8 @@ func GetVPCIPAddresses(ctx context.Context, client client.Client, vpcName string } // Assign the list of IDs to a stringified JSON filter - filter, err := json.Marshal(subnetFilter{SubnetID: strings.Join(subnetIDList, ",")}) + var filter []byte + filter, err = json.Marshal(subnetFilter{SubnetID: strings.Join(subnetIDList, ",")}) if err != nil { klog.Error("could not create JSON filter for subnet_id") }