@@ -23,6 +23,11 @@ import (
23
23
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
24
24
)
25
25
26
+ const (
27
+ informerResyncPeriod = 1 * time .Minute
28
+ defaultMetadataTTL = 300 * time .Second
29
+ )
30
+
26
31
type nodeController struct {
27
32
sync.RWMutex
28
33
@@ -38,10 +43,10 @@ type nodeController struct {
38
43
}
39
44
40
45
func newNodeController (kubeclient kubernetes.Interface , client client.Client , informer v1informers.NodeInformer ) * nodeController {
41
- timeout := 300
46
+ timeout := defaultMetadataTTL
42
47
if raw , ok := os .LookupEnv ("LINODE_METADATA_TTL" ); ok {
43
48
if t , _ := strconv .Atoi (raw ); t > 0 {
44
- timeout = t
49
+ timeout = time . Duration ( t ) * time . Second
45
50
}
46
51
}
47
52
@@ -50,24 +55,36 @@ func newNodeController(kubeclient kubernetes.Interface, client client.Client, in
50
55
instances : newInstances (client ),
51
56
kubeclient : kubeclient ,
52
57
informer : informer ,
53
- ttl : time . Duration ( timeout ) * time . Second ,
58
+ ttl : timeout ,
54
59
metadataLastUpdate : make (map [string ]time.Time ),
55
60
queue : workqueue .NewDelayingQueue (),
56
61
}
57
62
}
58
63
59
64
func (s * nodeController ) Run (stopCh <- chan struct {}) {
60
- if _ , err := s .informer .Informer ().AddEventHandler (cache.ResourceEventHandlerFuncs {
61
- AddFunc : func (obj interface {}) {
62
- node , ok := obj .(* v1.Node )
63
- if ! ok {
64
- return
65
- }
66
-
67
- klog .Infof ("NodeController will handle newly created node (%s) metadata" , node .Name )
68
- s .queue .Add (node )
65
+ if _ , err := s .informer .Informer ().AddEventHandlerWithResyncPeriod (
66
+ cache.ResourceEventHandlerFuncs {
67
+ AddFunc : func (obj interface {}) {
68
+ node , ok := obj .(* v1.Node )
69
+ if ! ok {
70
+ return
71
+ }
72
+
73
+ klog .Infof ("NodeController will handle newly created node (%s) metadata" , node .Name )
74
+ s .queue .Add (node )
75
+ },
76
+ UpdateFunc : func (oldObj , newObj interface {}) {
77
+ node , ok := newObj .(* v1.Node )
78
+ if ! ok {
79
+ return
80
+ }
81
+
82
+ klog .Infof ("NodeController will handle newly updated node (%s) metadata" , node .Name )
83
+ s .queue .Add (node )
84
+ },
69
85
},
70
- }); err != nil {
86
+ informerResyncPeriod ,
87
+ ); err != nil {
71
88
klog .Errorf ("NodeController can't handle newly created node's metadata. %s" , err )
72
89
}
73
90
@@ -125,19 +142,27 @@ func (s *nodeController) SetLastMetadataUpdate(nodeName string) {
125
142
}
126
143
127
144
func (s * nodeController ) handleNode (ctx context.Context , node * v1.Node ) error {
128
- klog .Infof ("NodeController handling node (%s) metadata" , node .Name )
145
+ klog .V (3 ).InfoS ("NodeController handling node metadata" ,
146
+ "node" , klog .KObj (node ))
129
147
130
148
lastUpdate := s .LastMetadataUpdate (node .Name )
131
149
132
150
uuid , foundLabel := node .Labels [annotations .AnnLinodeHostUUID ]
133
151
configuredPrivateIP , foundAnnotation := node .Annotations [annotations .AnnLinodeNodePrivateIP ]
134
- if foundLabel && foundAnnotation && time .Since (lastUpdate ) < s .ttl {
152
+
153
+ metaAge := time .Since (lastUpdate )
154
+ if foundLabel && foundAnnotation && metaAge < s .ttl {
155
+ klog .V (3 ).InfoS ("Skipping refresh, ttl not reached" ,
156
+ "node" , klog .KObj (node ),
157
+ "ttl" , s .ttl ,
158
+ "metadata_age" , metaAge ,
159
+ )
135
160
return nil
136
161
}
137
162
138
163
linode , err := s .instances .lookupLinode (ctx , node )
139
164
if err != nil {
140
- klog .Infof ( "instance lookup error: %s" , err . Error () )
165
+ klog .V ( 1 ). ErrorS ( err , "Instance lookup error" )
141
166
return err
142
167
}
143
168
@@ -182,7 +207,7 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
182
207
_ , err = s .kubeclient .CoreV1 ().Nodes ().Update (ctx , n , metav1.UpdateOptions {})
183
208
return err
184
209
}); err != nil {
185
- klog .Infof ( "node update error: %s" , err . Error () )
210
+ klog .V ( 1 ). ErrorS ( err , "Node update error" )
186
211
return err
187
212
}
188
213
0 commit comments