Skip to content

Commit ff3d9f0

Browse files
committed
make package for linode services
1 parent b64ad42 commit ff3d9f0

16 files changed

+86
-87
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fmt:
8080
.PHONY: test
8181
# we say code is not worth testing unless it's formatted
8282
test: fmt codegen
83-
go test -v -coverpkg=./sentry,./cloud/linode/client,./cloud/linode/firewall,./cloud/linode,./cloud/linode/utils,./cloud/linode/cache,./cloud/nodeipam,./cloud/nodeipam/ipam -coverprofile ./coverage.out -cover ./sentry/... ./cloud/... $(TEST_ARGS)
83+
go test -v -coverpkg=./sentry,./cloud/linode/client,./cloud/linode,./cloud/linode/utils,./cloud/linode/services,./cloud/nodeipam,./cloud/nodeipam/ipam -coverprofile ./coverage.out -cover ./sentry/... ./cloud/... $(TEST_ARGS)
8484

8585
.PHONY: build-linux
8686
build-linux: codegen

cloud/linode/cloud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
cloudprovider "k8s.io/cloud-provider"
1515
"k8s.io/klog/v2"
1616

17-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
1817
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
1918
"github.com/linode/linode-cloud-controller-manager/cloud/linode/options"
19+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
2020
)
2121

2222
const (
@@ -40,7 +40,7 @@ type linodeCloud struct {
4040
}
4141

4242
var (
43-
instanceCache *cache.Instances
43+
instanceCache *services.Instances
4444
ipHolderCharLimit int = 23
4545
NodeBalancerPrefixCharLimit int = 19
4646
)

cloud/linode/cloud_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/stretchr/testify/require"
1111
cloudprovider "k8s.io/cloud-provider"
1212

13-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
1413
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
1514
"github.com/linode/linode-cloud-controller-manager/cloud/linode/options"
15+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
1616
)
1717

1818
func TestNewCloudRouteControllerDisabled(t *testing.T) {
@@ -82,16 +82,16 @@ func TestNewCloud(t *testing.T) {
8282
options.Options.LoadBalancerType = "test"
8383
options.Options.VPCNames = []string{"vpc-test1", "vpc-test2"}
8484
options.Options.NodeBalancerBackendIPv4SubnetName = "t1"
85-
cache.VpcIDs = map[string]int{"vpc-test1": 1, "vpc-test2": 2, "vpc-test3": 3}
86-
cache.SubnetIDs = map[string]int{"t1": 1, "t2": 2, "t3": 3}
85+
services.VpcIDs = map[string]int{"vpc-test1": 1, "vpc-test2": 2, "vpc-test3": 3}
86+
services.SubnetIDs = map[string]int{"t1": 1, "t2": 2, "t3": 3}
8787
defer func() {
8888
options.Options.LoadBalancerType = ""
8989
options.Options.EnableRouteController = rtEnabled
9090
options.Options.VPCNames = []string{}
9191
options.Options.NodeBalancerBackendIPv4SubnetID = 0
9292
options.Options.NodeBalancerBackendIPv4SubnetName = ""
93-
cache.VpcIDs = map[string]int{}
94-
cache.SubnetIDs = map[string]int{}
93+
services.VpcIDs = map[string]int{}
94+
services.SubnetIDs = map[string]int{}
9595
}()
9696
_, err := newCloud()
9797
assert.Error(t, err, "expected error if incorrect loadbalancertype is set")
@@ -182,7 +182,7 @@ func Test_linodeCloud_LoadBalancer(t *testing.T) {
182182
name: "should return loadbalancer interface",
183183
fields: fields{
184184
client: client,
185-
instances: cache.NewInstances(client),
185+
instances: services.NewInstances(client),
186186
loadbalancers: newLoadbalancers(client, "us-east"),
187187
routes: nil,
188188
},
@@ -229,11 +229,11 @@ func Test_linodeCloud_InstancesV2(t *testing.T) {
229229
name: "should return instances interface",
230230
fields: fields{
231231
client: client,
232-
instances: cache.NewInstances(client),
232+
instances: services.NewInstances(client),
233233
loadbalancers: newLoadbalancers(client, "us-east"),
234234
routes: nil,
235235
},
236-
want: cache.NewInstances(client),
236+
want: services.NewInstances(client),
237237
want1: true,
238238
},
239239
}
@@ -276,7 +276,7 @@ func Test_linodeCloud_Instances(t *testing.T) {
276276
name: "should return nil",
277277
fields: fields{
278278
client: client,
279-
instances: cache.NewInstances(client),
279+
instances: services.NewInstances(client),
280280
loadbalancers: newLoadbalancers(client, "us-east"),
281281
routes: nil,
282282
},
@@ -323,7 +323,7 @@ func Test_linodeCloud_Zones(t *testing.T) {
323323
name: "should return nil",
324324
fields: fields{
325325
client: client,
326-
instances: cache.NewInstances(client),
326+
instances: services.NewInstances(client),
327327
loadbalancers: newLoadbalancers(client, "us-east"),
328328
routes: nil,
329329
},
@@ -370,7 +370,7 @@ func Test_linodeCloud_Clusters(t *testing.T) {
370370
name: "should return nil",
371371
fields: fields{
372372
client: client,
373-
instances: cache.NewInstances(client),
373+
instances: services.NewInstances(client),
374374
loadbalancers: newLoadbalancers(client, "us-east"),
375375
routes: nil,
376376
},
@@ -419,7 +419,7 @@ func Test_linodeCloud_Routes(t *testing.T) {
419419
name: "should return nil",
420420
fields: fields{
421421
client: client,
422-
instances: cache.NewInstances(client),
422+
instances: services.NewInstances(client),
423423
loadbalancers: newLoadbalancers(client, "us-east"),
424424
routes: r,
425425
EnableRouteController: false,
@@ -431,7 +431,7 @@ func Test_linodeCloud_Routes(t *testing.T) {
431431
name: "should return routes interface",
432432
fields: fields{
433433
client: client,
434-
instances: cache.NewInstances(client),
434+
instances: services.NewInstances(client),
435435
loadbalancers: newLoadbalancers(client, "us-east"),
436436
routes: r,
437437
EnableRouteController: true,

cloud/linode/loadbalancers.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import (
2727
"k8s.io/klog/v2"
2828

2929
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
30-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
3130
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
32-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/firewall"
3331
"github.com/linode/linode-cloud-controller-manager/cloud/linode/options"
32+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
3433
"github.com/linode/linode-cloud-controller-manager/sentry"
3534
)
3635

@@ -396,7 +395,7 @@ func (l *loadbalancers) updateNodeBalancer(
396395
}
397396
}
398397

399-
fwClient := firewall.LinodeClient{Client: l.client}
398+
fwClient := services.LinodeClient{Client: l.client}
400399
err = fwClient.UpdateNodeBalancerFirewall(ctx, l.GetLoadBalancerName(ctx, clusterName, service), tags, service, nb)
401400
if err != nil {
402401
return err
@@ -652,7 +651,7 @@ func (l *loadbalancers) EnsureLoadBalancerDeleted(ctx context.Context, clusterNa
652651
return nil
653652
}
654653

655-
fwClient := firewall.LinodeClient{Client: l.client}
654+
fwClient := services.LinodeClient{Client: l.client}
656655
if err = fwClient.DeleteNodeBalancerFirewall(ctx, service, nb); err != nil {
657656
return err
658657
}
@@ -851,7 +850,7 @@ func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName stri
851850
// There's no firewallID already set, see if we need to create a new fw, look for the acl annotation.
852851
_, ok := service.GetAnnotations()[annotations.AnnLinodeCloudFirewallACL]
853852
if ok {
854-
fwcreateOpts, err := firewall.CreateFirewallOptsForSvc(label, tags, service)
853+
fwcreateOpts, err := services.CreateFirewallOptsForSvc(label, tags, service)
855854
if err != nil {
856855
return nil, err
857856
}
@@ -998,7 +997,7 @@ func (l *loadbalancers) getSubnetIDForSVC(ctx context.Context, service *v1.Servi
998997
if vpcOk {
999998
vpcName = specifiedVPCName
1000999
}
1001-
vpcID, err := cache.GetVPCID(ctx, l.client, vpcName)
1000+
vpcID, err := services.GetVPCID(ctx, l.client, vpcName)
10021001
if err != nil {
10031002
return 0, err
10041003
}
@@ -1009,7 +1008,7 @@ func (l *loadbalancers) getSubnetIDForSVC(ctx context.Context, service *v1.Servi
10091008
}
10101009

10111010
// Use the VPC ID and Subnet Name to get the subnet ID
1012-
return cache.GetSubnetID(ctx, l.client, vpcID, subnetName)
1011+
return services.GetSubnetID(ctx, l.client, vpcID, subnetName)
10131012
}
10141013

10151014
// buildLoadBalancerRequest returns a linodego.NodeBalancer

cloud/linode/node_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"k8s.io/klog/v2"
2222

2323
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
24-
ccmCache "github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
2524
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
2625
"github.com/linode/linode-cloud-controller-manager/cloud/linode/options"
26+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
2727
ccmUtils "github.com/linode/linode-cloud-controller-manager/cloud/linode/utils"
2828
)
2929

@@ -45,7 +45,7 @@ type nodeController struct {
4545
sync.RWMutex
4646

4747
client client.Client
48-
instances *ccmCache.Instances
48+
instances *services.Instances
4949
kubeclient kubernetes.Interface
5050
informer v1informers.NodeInformer
5151

@@ -157,7 +157,7 @@ func newK8sNodeCache() *k8sNodeCache {
157157
}
158158
}
159159

160-
func newNodeController(kubeclient kubernetes.Interface, client client.Client, informer v1informers.NodeInformer, instanceCache *ccmCache.Instances) *nodeController {
160+
func newNodeController(kubeclient kubernetes.Interface, client client.Client, informer v1informers.NodeInformer, instanceCache *services.Instances) *nodeController {
161161
timeout := defaultMetadataTTL
162162
if raw, ok := os.LookupEnv("LINODE_METADATA_TTL"); ok {
163163
if t, err := strconv.Atoi(raw); t > 0 && err == nil {

cloud/linode/node_controller_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"k8s.io/client-go/util/workqueue"
1919

2020
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
21-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
2221
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
22+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
2323
)
2424

2525
func TestNodeController_Run(t *testing.T) {
@@ -31,7 +31,7 @@ func TestNodeController_Run(t *testing.T) {
3131
informer := informers.NewSharedInformerFactory(kubeClient, 0).Core().V1().Nodes()
3232
mockQueue := workqueue.NewTypedDelayingQueueWithConfig(workqueue.TypedDelayingQueueConfig[nodeRequest]{Name: "test"})
3333

34-
nodeCtrl := newNodeController(kubeClient, client, informer, cache.NewInstances(client))
34+
nodeCtrl := newNodeController(kubeClient, client, informer, services.NewInstances(client))
3535
nodeCtrl.queue = mockQueue
3636
nodeCtrl.ttl = 1 * time.Second
3737

@@ -84,7 +84,7 @@ func TestNodeController_processNext(t *testing.T) {
8484

8585
controller := &nodeController{
8686
kubeclient: kubeClient,
87-
instances: cache.NewInstances(client),
87+
instances: services.NewInstances(client),
8888
queue: queue,
8989
metadataLastUpdate: make(map[string]time.Time),
9090
ttl: defaultMetadataTTL,
@@ -138,7 +138,7 @@ func TestNodeController_processNext(t *testing.T) {
138138
defer func() {
139139
controller.instances = currInstances
140140
}()
141-
controller.instances = cache.NewInstances(client)
141+
controller.instances = services.NewInstances(client)
142142
registeredK8sNodeCache.lastUpdate = time.Now().Add(-15 * time.Minute)
143143
controller.addNodeToQueue(node2)
144144
publicIP := net.ParseIP("172.234.31.123")
@@ -169,7 +169,7 @@ func TestNodeController_processNext(t *testing.T) {
169169
controller.queue = queue
170170
controller.addNodeToQueue(node)
171171
client := mocks.NewMockClient(ctrl)
172-
controller.instances = cache.NewInstances(client)
172+
controller.instances = services.NewInstances(client)
173173
retryInterval = 1 * time.Nanosecond
174174
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusTooManyRequests, Message: "Too many requests"})
175175
result := controller.processNext()
@@ -185,7 +185,7 @@ func TestNodeController_processNext(t *testing.T) {
185185
controller.queue = queue
186186
controller.addNodeToQueue(node)
187187
client := mocks.NewMockClient(ctrl)
188-
controller.instances = cache.NewInstances(client)
188+
controller.instances = services.NewInstances(client)
189189
retryInterval = 1 * time.Nanosecond
190190
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusInternalServerError, Message: "Too many requests"})
191191
result := controller.processNext()
@@ -214,7 +214,7 @@ func TestNodeController_handleNode(t *testing.T) {
214214
_, err := kubeClient.CoreV1().Nodes().Create(t.Context(), node, metav1.CreateOptions{})
215215
require.NoError(t, err, "expected no error during node creation")
216216

217-
instCache := cache.NewInstances(client)
217+
instCache := services.NewInstances(client)
218218

219219
t.Setenv("LINODE_METADATA_TTL", "30")
220220
nodeCtrl := newNodeController(kubeClient, client, nil, instCache)
@@ -249,15 +249,15 @@ func TestNodeController_handleNode(t *testing.T) {
249249

250250
// Lookup failure for linode instance
251251
client = mocks.NewMockClient(ctrl)
252-
nodeCtrl.instances = cache.NewInstances(client)
252+
nodeCtrl.instances = services.NewInstances(client)
253253
nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl)
254254
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, errors.New("lookup failed"))
255255
err = nodeCtrl.handleNode(t.Context(), node)
256256
require.Error(t, err, "expected error during handleNode, got nil")
257257

258258
// All fields already set
259259
client = mocks.NewMockClient(ctrl)
260-
nodeCtrl.instances = cache.NewInstances(client)
260+
nodeCtrl.instances = services.NewInstances(client)
261261
nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl)
262262
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
263263
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"},

cloud/linode/route_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
cloudprovider "k8s.io/cloud-provider"
1818
"k8s.io/klog/v2"
1919

20-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/cache"
2120
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
2221
"github.com/linode/linode-cloud-controller-manager/cloud/linode/options"
22+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
2323
ccmUtils "github.com/linode/linode-cloud-controller-manager/cloud/linode/utils"
2424
)
2525

@@ -47,7 +47,7 @@ func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) {
4747
if vpcName == "" {
4848
continue
4949
}
50-
resp, err := cache.GetVPCIPAddresses(ctx, client, vpcName)
50+
resp, err := services.GetVPCIPAddresses(ctx, client, vpcName)
5151
if err != nil {
5252
klog.Errorf("failed updating cache for VPC %s. Error: %s", vpcName, err.Error())
5353
continue
@@ -63,11 +63,11 @@ func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) {
6363

6464
type routes struct {
6565
client client.Client
66-
instances *cache.Instances
66+
instances *services.Instances
6767
routeCache *routeCache
6868
}
6969

70-
func newRoutes(client client.Client, instanceCache *cache.Instances) (cloudprovider.Routes, error) {
70+
func newRoutes(client client.Client, instanceCache *services.Instances) (cloudprovider.Routes, error) {
7171
timeout := 60
7272
if raw, ok := os.LookupEnv("LINODE_ROUTES_CACHE_TTL_SECONDS"); ok {
7373
if t, err := strconv.Atoi(raw); t > 0 && err == nil {
@@ -159,7 +159,7 @@ func (r *routes) CreateRoute(ctx context.Context, clusterName string, nameHint s
159159
intfRoutes := []string{}
160160
intfVPCIP := linodego.VPCIP{}
161161

162-
for _, vpcid := range cache.GetAllVPCIDs() {
162+
for _, vpcid := range services.GetAllVPCIDs() {
163163
for _, ir := range instanceRoutes {
164164
if ir.VPCID != vpcid {
165165
continue
@@ -212,7 +212,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
212212
intfRoutes := []string{}
213213
intfVPCIP := linodego.VPCIP{}
214214

215-
for _, vpcid := range cache.GetAllVPCIDs() {
215+
for _, vpcid := range services.GetAllVPCIDs() {
216216
for _, ir := range instanceRoutes {
217217
if ir.VPCID != vpcid {
218218
continue
@@ -272,7 +272,7 @@ func (r *routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudpr
272272
}
273273

274274
// check for configured routes
275-
for _, vpcid := range cache.GetAllVPCIDs() {
275+
for _, vpcid := range services.GetAllVPCIDs() {
276276
for _, ir := range instanceRoutes {
277277
if ir.Address != nil || ir.VPCID != vpcid {
278278
continue

0 commit comments

Comments
 (0)