Skip to content

Commit b148f90

Browse files
author
Rahul Sharma
committed
use single copy of instance cache for node_controller as well
1 parent bc69f45 commit b148f90

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

cloud/linode/cloud.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type linodeCloud struct {
5151
routes cloudprovider.Routes
5252
}
5353

54+
var instanceCache *instances
55+
5456
func init() {
5557
cloudprovider.RegisterCloudProvider(
5658
ProviderName,
@@ -97,9 +99,8 @@ func newCloud() (cloudprovider.Interface, error) {
9799
Options.VPCNames = Options.VPCName
98100
}
99101

100-
instances := newInstances(linodeClient)
101-
102-
routes, err := newRoutes(linodeClient, instances)
102+
instanceCache = newInstances(linodeClient)
103+
routes, err := newRoutes(linodeClient, instanceCache)
103104
if err != nil {
104105
return nil, fmt.Errorf("routes client was not created successfully: %w", err)
105106
}
@@ -125,7 +126,7 @@ func newCloud() (cloudprovider.Interface, error) {
125126
// create struct that satisfies cloudprovider.Interface
126127
lcloud := &linodeCloud{
127128
client: linodeClient,
128-
instances: instances,
129+
instances: instanceCache,
129130
loadbalancers: newLoadbalancers(linodeClient, region),
130131
routes: routes,
131132
}
@@ -141,7 +142,7 @@ func (c *linodeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBui
141142
serviceController := newServiceController(c.loadbalancers.(*loadbalancers), serviceInformer)
142143
go serviceController.Run(stopCh)
143144

144-
nodeController := newNodeController(kubeclient, c.client, nodeInformer)
145+
nodeController := newNodeController(kubeclient, c.client, nodeInformer, instanceCache)
145146
go nodeController.Run(stopCh)
146147
}
147148

cloud/linode/node_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type nodeController struct {
4242
queue workqueue.TypedDelayingInterface[any]
4343
}
4444

45-
func newNodeController(kubeclient kubernetes.Interface, client client.Client, informer v1informers.NodeInformer) *nodeController {
45+
func newNodeController(kubeclient kubernetes.Interface, client client.Client, informer v1informers.NodeInformer, instanceCache *instances) *nodeController {
4646
timeout := defaultMetadataTTL
4747
if raw, ok := os.LookupEnv("LINODE_METADATA_TTL"); ok {
4848
if t, _ := strconv.Atoi(raw); t > 0 {
@@ -52,7 +52,7 @@ func newNodeController(kubeclient kubernetes.Interface, client client.Client, in
5252

5353
return &nodeController{
5454
client: client,
55-
instances: newInstances(client),
55+
instances: instanceCache,
5656
kubeclient: kubeclient,
5757
informer: informer,
5858
ttl: timeout,

cloud/linode/route_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type routes struct {
6262
routeCache *routeCache
6363
}
6464

65-
func newRoutes(client client.Client, instances *instances) (cloudprovider.Routes, error) {
65+
func newRoutes(client client.Client, instanceCache *instances) (cloudprovider.Routes, error) {
6666
timeout := 60
6767
if raw, ok := os.LookupEnv("LINODE_ROUTES_CACHE_TTL_SECONDS"); ok {
6868
if t, _ := strconv.Atoi(raw); t > 0 {
@@ -77,7 +77,7 @@ func newRoutes(client client.Client, instances *instances) (cloudprovider.Routes
7777

7878
return &routes{
7979
client: client,
80-
instances: instances,
80+
instances: instanceCache,
8181
routeCache: &routeCache{
8282
routes: make(map[int][]linodego.VPCIP, 0),
8383
ttl: time.Duration(timeout) * time.Second,

cloud/linode/route_controller_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func TestListRoutes(t *testing.T) {
3333
ctrl := gomock.NewController(t)
3434
defer ctrl.Finish()
3535
client := mocks.NewMockClient(ctrl)
36-
instances := newInstances(client)
37-
routeController, err := newRoutes(client, instances)
36+
instanceCache := newInstances(client)
37+
routeController, err := newRoutes(client, instanceCache)
3838
assert.NoError(t, err)
3939

4040
client.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Times(1).Return([]linodego.Instance{}, nil)
@@ -57,8 +57,8 @@ func TestListRoutes(t *testing.T) {
5757
ctrl := gomock.NewController(t)
5858
defer ctrl.Finish()
5959
client := mocks.NewMockClient(ctrl)
60-
instances := newInstances(client)
61-
routeController, err := newRoutes(client, instances)
60+
instanceCache := newInstances(client)
61+
routeController, err := newRoutes(client, instanceCache)
6262
assert.NoError(t, err)
6363

6464
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -84,8 +84,8 @@ func TestListRoutes(t *testing.T) {
8484
ctrl := gomock.NewController(t)
8585
defer ctrl.Finish()
8686
client := mocks.NewMockClient(ctrl)
87-
instances := newInstances(client)
88-
routeController, err := newRoutes(client, instances)
87+
instanceCache := newInstances(client)
88+
routeController, err := newRoutes(client, instanceCache)
8989
assert.NoError(t, err)
9090

9191
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -126,8 +126,8 @@ func TestListRoutes(t *testing.T) {
126126
ctrl := gomock.NewController(t)
127127
defer ctrl.Finish()
128128
client := mocks.NewMockClient(ctrl)
129-
instances := newInstances(client)
130-
routeController, err := newRoutes(client, instances)
129+
instanceCache := newInstances(client)
130+
routeController, err := newRoutes(client, instanceCache)
131131
assert.NoError(t, err)
132132

133133
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -168,8 +168,8 @@ func TestListRoutes(t *testing.T) {
168168
ctrl := gomock.NewController(t)
169169
defer ctrl.Finish()
170170
client := mocks.NewMockClient(ctrl)
171-
instances := newInstances(client)
172-
routeController, err := newRoutes(client, instances)
171+
instanceCache := newInstances(client)
172+
routeController, err := newRoutes(client, instanceCache)
173173
assert.NoError(t, err)
174174

175175
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -184,8 +184,8 @@ func TestListRoutes(t *testing.T) {
184184
ctrl := gomock.NewController(t)
185185
defer ctrl.Finish()
186186
client := mocks.NewMockClient(ctrl)
187-
instances := newInstances(client)
188-
routeController, err := newRoutes(client, instances)
187+
instanceCache := newInstances(client)
188+
routeController, err := newRoutes(client, instanceCache)
189189
assert.NoError(t, err)
190190

191191
vpcIP2 := "10.0.0.3"
@@ -322,8 +322,8 @@ func TestCreateRoute(t *testing.T) {
322322
ctrl := gomock.NewController(t)
323323
defer ctrl.Finish()
324324
client := mocks.NewMockClient(ctrl)
325-
instances := newInstances(client)
326-
routeController, err := newRoutes(client, instances)
325+
instanceCache := newInstances(client)
326+
routeController, err := newRoutes(client, instanceCache)
327327
assert.NoError(t, err)
328328

329329
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -336,8 +336,8 @@ func TestCreateRoute(t *testing.T) {
336336
ctrl := gomock.NewController(t)
337337
defer ctrl.Finish()
338338
client := mocks.NewMockClient(ctrl)
339-
instances := newInstances(client)
340-
routeController, err := newRoutes(client, instances)
339+
instanceCache := newInstances(client)
340+
routeController, err := newRoutes(client, instanceCache)
341341
assert.NoError(t, err)
342342

343343
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, nil)
@@ -379,8 +379,8 @@ func TestDeleteRoute(t *testing.T) {
379379
ctrl := gomock.NewController(t)
380380
defer ctrl.Finish()
381381
client := mocks.NewMockClient(ctrl)
382-
instances := newInstances(client)
383-
routeController, err := newRoutes(client, instances)
382+
instanceCache := newInstances(client)
383+
routeController, err := newRoutes(client, instanceCache)
384384
assert.NoError(t, err)
385385

386386
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, nil)
@@ -410,8 +410,8 @@ func TestDeleteRoute(t *testing.T) {
410410
ctrl := gomock.NewController(t)
411411
defer ctrl.Finish()
412412
client := mocks.NewMockClient(ctrl)
413-
instances := newInstances(client)
414-
routeController, err := newRoutes(client, instances)
413+
instanceCache := newInstances(client)
414+
routeController, err := newRoutes(client, instanceCache)
415415
assert.NoError(t, err)
416416

417417
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
@@ -442,8 +442,8 @@ func TestDeleteRoute(t *testing.T) {
442442
ctrl := gomock.NewController(t)
443443
defer ctrl.Finish()
444444
client := mocks.NewMockClient(ctrl)
445-
instances := newInstances(client)
446-
routeController, err := newRoutes(client, instances)
445+
instanceCache := newInstances(client)
446+
routeController, err := newRoutes(client, instanceCache)
447447
assert.NoError(t, err)
448448

449449
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)

0 commit comments

Comments
 (0)