@@ -51,6 +51,7 @@ type nodeController struct {
51
51
nodeLastAdded map [string ]time.Time
52
52
}
53
53
54
+ // k8sNodeCache stores node related info as registered in k8s
54
55
type k8sNodeCache struct {
55
56
sync.RWMutex
56
57
nodes map [string ]* v1.Node
@@ -89,6 +90,7 @@ func (c *k8sNodeCache) updateCache(kubeclient kubernetes.Interface) {
89
90
c .lastUpdate = time .Now ()
90
91
}
91
92
93
+ // addNodeToCache stores the specified node in k8s node cache
92
94
func (c * k8sNodeCache ) addNodeToCache (node * v1.Node ) {
93
95
c .Lock ()
94
96
defer c .Unlock ()
@@ -131,6 +133,7 @@ func (c *k8sNodeCache) getProviderID(nodeName string) (string, bool) {
131
133
return "" , false
132
134
}
133
135
136
+ // newK8sNodeCache returns new k8s node cache instance
134
137
func newK8sNodeCache () * k8sNodeCache {
135
138
timeout := defaultK8sNodeCacheTTL
136
139
if raw , ok := os .LookupEnv ("K8S_NODECACHE_TTL" ); ok {
@@ -285,9 +288,7 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
285
288
286
289
expectedPrivateIP := ""
287
290
// linode API response for linode will contain only one private ip
288
- // if any private ip is configured. If it changes in future or linode
289
- // supports other subnets with nodebalancer, this logic needs to be updated.
290
- // https://www.linode.com/docs/api/linode-instances/#linode-view
291
+ // if any private ip is configured.
291
292
for _ , addr := range linode .IPv4 {
292
293
if isPrivate (addr ) {
293
294
expectedPrivateIP = addr .String ()
@@ -329,7 +330,9 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
329
330
return err
330
331
}
331
332
332
- registeredK8sNodeCache .addNodeToCache (updatedNode )
333
+ if updatedNode != nil {
334
+ registeredK8sNodeCache .addNodeToCache (updatedNode )
335
+ }
333
336
s .SetLastMetadataUpdate (node .Name )
334
337
335
338
return nil
0 commit comments