Skip to content

Commit 5cb4d18

Browse files
authored
Merge pull request #195 from linode/revert-route-controller
revert PR 184, PR 190 and PR 182
2 parents 9b6ebcf + 1b6fb3b commit 5cb4d18

File tree

12 files changed

+27
-611
lines changed

12 files changed

+27
-611
lines changed

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,6 @@ Users can create CloudFirewall instances, supply their own rules and attach them
126126
**Note**<br/>
127127
If the user supplies a firewall-id, and later switches to using an ACL, the CCM will take over the CloudFirewall Instance. To avoid this, delete the service, and re-create it so the original CloudFirewall is left undisturbed.
128128

129-
#### Routes
130-
When running k8s clusters within VPC, node specific podCIDRs need to be allowed on the VPC interface. Linode CCM comes with route-controller functionality which can be enabled for automatically adding/deleting routes on VPC interfaces. When installing CCM with helm, make sure to specify routeController settings.
131-
132-
##### Example usage in values.yaml
133-
```yaml
134-
routeController:
135-
vpcName: <name of VPC>
136-
clusterCIDR: 10.0.0.0/8
137-
configureCloudRoutes: true
138-
```
139-
140129
### Nodes
141130
Kubernetes Nodes can be configured with the following annotations.
142131

cloud/linode/client/client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ type Client interface {
1616
ListInstances(context.Context, *linodego.ListOptions) ([]linodego.Instance, error)
1717
GetInstanceIPAddresses(context.Context, int) (*linodego.InstanceIPAddressResponse, error)
1818

19-
ListInstanceConfigs(context.Context, int, *linodego.ListOptions) ([]linodego.InstanceConfig, error)
20-
UpdateInstanceConfigInterface(context.Context, int, int, int, linodego.InstanceConfigInterfaceUpdateOptions) (*linodego.InstanceConfigInterface, error)
21-
22-
ListVPCs(context.Context, *linodego.ListOptions) ([]linodego.VPC, error)
23-
2419
CreateNodeBalancer(context.Context, linodego.NodeBalancerCreateOptions) (*linodego.NodeBalancer, error)
2520
GetNodeBalancer(context.Context, int) (*linodego.NodeBalancer, error)
2621
UpdateNodeBalancer(context.Context, int, linodego.NodeBalancerUpdateOptions) (*linodego.NodeBalancer, error)

cloud/linode/client/mock_client_test.go

Lines changed: 0 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/linode/cloud.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@ const (
2525
// We expect it to be initialized with flags external to this package, likely in
2626
// main.go
2727
var Options struct {
28-
KubeconfigFlag *pflag.Flag
29-
LinodeGoDebug bool
30-
EnableRouteController bool
31-
VPCName string
28+
KubeconfigFlag *pflag.Flag
29+
LinodeGoDebug bool
3230
}
3331

3432
type linodeCloud struct {
3533
client client.Client
3634
instances cloudprovider.InstancesV2
3735
loadbalancers cloudprovider.LoadBalancer
38-
routes cloudprovider.Routes
3936
}
4037

4138
func init() {
@@ -70,19 +67,12 @@ func newCloud() (cloudprovider.Interface, error) {
7067
linodeClient.SetDebug(true)
7168
}
7269

73-
routes, err := newRoutes(linodeClient)
74-
if err != nil {
75-
return nil, fmt.Errorf("routes client was not created successfully: %w", err)
76-
}
77-
78-
// create struct that satisfies cloudprovider.Interface
79-
lcloud := &linodeCloud{
70+
// Return struct that satisfies cloudprovider.Interface
71+
return &linodeCloud{
8072
client: linodeClient,
8173
instances: newInstances(linodeClient),
8274
loadbalancers: newLoadbalancers(linodeClient, region),
83-
routes: routes,
84-
}
85-
return lcloud, nil
75+
}, nil
8676
}
8777

8878
func (c *linodeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stopCh <-chan struct{}) {
@@ -119,9 +109,6 @@ func (c *linodeCloud) Clusters() (cloudprovider.Clusters, bool) {
119109
}
120110

121111
func (c *linodeCloud) Routes() (cloudprovider.Routes, bool) {
122-
if Options.EnableRouteController {
123-
return c.routes, true
124-
}
125112
return nil, false
126113
}
127114

cloud/linode/instances.go

Lines changed: 15 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,21 @@ import (
99
"time"
1010

1111
"github.com/linode/linodego"
12-
"golang.org/x/sync/errgroup"
1312
v1 "k8s.io/api/core/v1"
1413
"k8s.io/apimachinery/pkg/types"
1514
cloudprovider "k8s.io/cloud-provider"
16-
"k8s.io/klog/v2"
1715

1816
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
1917
"github.com/linode/linode-cloud-controller-manager/sentry"
2018
)
2119

22-
type nodeIP struct {
23-
ip string
24-
ipType v1.NodeAddressType
25-
}
26-
27-
type linodeInstance struct {
28-
instance *linodego.Instance
29-
ips []nodeIP
30-
}
31-
3220
type nodeCache struct {
3321
sync.RWMutex
34-
nodes map[int]linodeInstance
22+
nodes map[int]*linodego.Instance
3523
lastUpdate time.Time
3624
ttl time.Duration
3725
}
3826

39-
// getInstanceIPv4Addresses returns all ipv4 addresses configured on a linode.
40-
func (nc *nodeCache) getInstanceIPv4Addresses(ctx context.Context, id int, client client.Client) ([]nodeIP, error) {
41-
// Retrieve ipaddresses for the linode
42-
addresses, err := client.GetInstanceIPAddresses(ctx, id)
43-
if err != nil {
44-
return nil, err
45-
}
46-
47-
var ips []nodeIP
48-
if len(addresses.IPv4.Public) != 0 {
49-
for _, ip := range addresses.IPv4.Public {
50-
ips = append(ips, nodeIP{ip: ip.Address, ipType: v1.NodeExternalIP})
51-
}
52-
}
53-
54-
// Retrieve instance configs for the linode
55-
configs, err := client.ListInstanceConfigs(ctx, id, &linodego.ListOptions{})
56-
if err != nil || len(configs) == 0 {
57-
return nil, err
58-
}
59-
60-
// Iterate over interfaces in config and find VPC specific ips
61-
for _, iface := range configs[0].Interfaces {
62-
if iface.VPCID != nil && iface.IPv4.VPC != "" {
63-
ips = append(ips, nodeIP{ip: iface.IPv4.VPC, ipType: v1.NodeInternalIP})
64-
}
65-
}
66-
67-
// NOTE: We specifically store VPC ips first so that if they exist, they are
68-
// used as internal ip for the nodes than the private ip
69-
if len(addresses.IPv4.Private) != 0 {
70-
for _, ip := range addresses.IPv4.Private {
71-
ips = append(ips, nodeIP{ip: ip.Address, ipType: v1.NodeInternalIP})
72-
}
73-
}
74-
75-
return ips, nil
76-
}
77-
7827
// refreshInstances conditionally loads all instances from the Linode API and caches them.
7928
// It does not refresh if the last update happened less than `nodeCache.ttl` ago.
8029
func (nc *nodeCache) refreshInstances(ctx context.Context, client client.Client) error {
@@ -90,29 +39,11 @@ func (nc *nodeCache) refreshInstances(ctx context.Context, client client.Client)
9039
return err
9140
}
9241

93-
nc.nodes = make(map[int]linodeInstance, len(instances))
42+
nc.nodes = make(map[int]*linodego.Instance)
9443

95-
mtx := sync.Mutex{}
96-
g := new(errgroup.Group)
9744
for _, instance := range instances {
9845
instance := instance
99-
g.Go(func() error {
100-
addresses, err := nc.getInstanceIPv4Addresses(ctx, instance.ID, client)
101-
if err != nil {
102-
klog.Errorf("Failed fetching ip addresses for instance id %d. Error: %s", instance.ID, err.Error())
103-
return err
104-
}
105-
// take lock on map so that concurrent writes are safe
106-
mtx.Lock()
107-
defer mtx.Unlock()
108-
node := linodeInstance{instance: &instance, ips: addresses}
109-
nc.nodes[instance.ID] = node
110-
return nil
111-
})
112-
}
113-
114-
if err := g.Wait(); err != nil {
115-
return err
46+
nc.nodes[instance.ID] = &instance
11647
}
11748

11849
nc.lastUpdate = time.Now()
@@ -133,10 +64,9 @@ func newInstances(client client.Client) *instances {
13364
timeout = t
13465
}
13566
}
136-
klog.V(3).Infof("TTL for nodeCache set to %d", timeout)
13767

13868
return &instances{client, &nodeCache{
139-
nodes: make(map[int]linodeInstance, 0),
69+
nodes: make(map[int]*linodego.Instance),
14070
ttl: time.Duration(timeout) * time.Second,
14171
}}
14272
}
@@ -153,8 +83,8 @@ func (i *instances) linodeByName(nodeName types.NodeName) (*linodego.Instance, e
15383
i.nodeCache.RLock()
15484
defer i.nodeCache.RUnlock()
15585
for _, node := range i.nodeCache.nodes {
156-
if node.instance.Label == string(nodeName) {
157-
return node.instance, nil
86+
if node.Label == string(nodeName) {
87+
return node, nil
15888
}
15989
}
16090

@@ -164,24 +94,11 @@ func (i *instances) linodeByName(nodeName types.NodeName) (*linodego.Instance, e
16494
func (i *instances) linodeByID(id int) (*linodego.Instance, error) {
16595
i.nodeCache.RLock()
16696
defer i.nodeCache.RUnlock()
167-
linodeInstance, ok := i.nodeCache.nodes[id]
97+
instance, ok := i.nodeCache.nodes[id]
16898
if !ok {
16999
return nil, cloudprovider.InstanceNotFound
170100
}
171-
return linodeInstance.instance, nil
172-
}
173-
174-
// listAllInstances returns all instances in nodeCache
175-
func (i *instances) listAllInstances(ctx context.Context) ([]linodego.Instance, error) {
176-
if err := i.nodeCache.refreshInstances(ctx, i.client); err != nil {
177-
return nil, err
178-
}
179-
180-
instances := []linodego.Instance{}
181-
for _, linodeInstance := range i.nodeCache.nodes {
182-
instances = append(instances, *linodeInstance.instance)
183-
}
184-
return instances, nil
101+
return instance, nil
185102
}
186103

187104
func (i *instances) lookupLinode(ctx context.Context, node *v1.Node) (*linodego.Instance, error) {
@@ -248,22 +165,20 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
248165
return nil, err
249166
}
250167

251-
ips, err := i.getLinodeIPv4Addresses(ctx, node)
252-
if err != nil {
253-
sentry.CaptureError(ctx, err)
254-
return nil, err
255-
}
256-
257-
if len(ips) == 0 {
168+
if len(linode.IPv4) == 0 {
258169
err := instanceNoIPAddressesError{linode.ID}
259170
sentry.CaptureError(ctx, err)
260171
return nil, err
261172
}
262173

263174
addresses := []v1.NodeAddress{{Type: v1.NodeHostName, Address: linode.Label}}
264175

265-
for _, ip := range ips {
266-
addresses = append(addresses, v1.NodeAddress{Type: ip.ipType, Address: ip.ip})
176+
for _, ip := range linode.IPv4 {
177+
ipType := v1.NodeExternalIP
178+
if ip.IsPrivate() {
179+
ipType = v1.NodeInternalIP
180+
}
181+
addresses = append(addresses, v1.NodeAddress{Type: ipType, Address: ip.String()})
267182
}
268183

269184
// note that Zone is omitted as it's not a thing in Linode
@@ -276,23 +191,3 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
276191

277192
return meta, nil
278193
}
279-
280-
func (i *instances) getLinodeIPv4Addresses(ctx context.Context, node *v1.Node) ([]nodeIP, error) {
281-
ctx = sentry.SetHubOnContext(ctx)
282-
instance, err := i.lookupLinode(ctx, node)
283-
if err != nil {
284-
sentry.CaptureError(ctx, err)
285-
return nil, err
286-
}
287-
288-
i.nodeCache.RLock()
289-
defer i.nodeCache.RUnlock()
290-
linodeInstance, ok := i.nodeCache.nodes[instance.ID]
291-
if !ok || len(linodeInstance.ips) == 0 {
292-
err := instanceNoIPAddressesError{instance.ID}
293-
sentry.CaptureError(ctx, err)
294-
return nil, err
295-
}
296-
297-
return linodeInstance.ips, nil
298-
}

0 commit comments

Comments
 (0)