@@ -52,7 +52,8 @@ import (
52
52
"k8s.io/klog/v2"
53
53
)
54
54
55
- type TTLController struct {
55
+ // Controller sets ttl annotations on nodes, based on cluster size.
56
+ type Controller struct {
56
57
kubeClient clientset.Interface
57
58
58
59
// nodeStore is a local cache of nodes.
@@ -76,8 +77,9 @@ type TTLController struct {
76
77
boundaryStep int
77
78
}
78
79
79
- func NewTTLController (nodeInformer informers.NodeInformer , kubeClient clientset.Interface ) * TTLController {
80
- ttlc := & TTLController {
80
+ // NewTTLController creates a new TTLController
81
+ func NewTTLController (nodeInformer informers.NodeInformer , kubeClient clientset.Interface ) * Controller {
82
+ ttlc := & Controller {
81
83
kubeClient : kubeClient ,
82
84
queue : workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), "ttlcontroller" ),
83
85
}
@@ -111,7 +113,8 @@ var (
111
113
}
112
114
)
113
115
114
- func (ttlc * TTLController ) Run (workers int , stopCh <- chan struct {}) {
116
+ // Run begins watching and syncing.
117
+ func (ttlc * Controller ) Run (workers int , stopCh <- chan struct {}) {
115
118
defer utilruntime .HandleCrash ()
116
119
defer ttlc .queue .ShutDown ()
117
120
@@ -129,7 +132,7 @@ func (ttlc *TTLController) Run(workers int, stopCh <-chan struct{}) {
129
132
<- stopCh
130
133
}
131
134
132
- func (ttlc * TTLController ) addNode (obj interface {}) {
135
+ func (ttlc * Controller ) addNode (obj interface {}) {
133
136
node , ok := obj .(* v1.Node )
134
137
if ! ok {
135
138
utilruntime .HandleError (fmt .Errorf ("unexpected object type: %v" , obj ))
@@ -148,7 +151,7 @@ func (ttlc *TTLController) addNode(obj interface{}) {
148
151
ttlc .enqueueNode (node )
149
152
}
150
153
151
- func (ttlc * TTLController ) updateNode (_ , newObj interface {}) {
154
+ func (ttlc * Controller ) updateNode (_ , newObj interface {}) {
152
155
node , ok := newObj .(* v1.Node )
153
156
if ! ok {
154
157
utilruntime .HandleError (fmt .Errorf ("unexpected object type: %v" , newObj ))
@@ -162,7 +165,7 @@ func (ttlc *TTLController) updateNode(_, newObj interface{}) {
162
165
ttlc .enqueueNode (node )
163
166
}
164
167
165
- func (ttlc * TTLController ) deleteNode (obj interface {}) {
168
+ func (ttlc * Controller ) deleteNode (obj interface {}) {
166
169
_ , ok := obj .(* v1.Node )
167
170
if ! ok {
168
171
tombstone , ok := obj .(cache.DeletedFinalStateUnknown )
@@ -189,7 +192,7 @@ func (ttlc *TTLController) deleteNode(obj interface{}) {
189
192
// We are not processing the node, as it no longer exists.
190
193
}
191
194
192
- func (ttlc * TTLController ) enqueueNode (node * v1.Node ) {
195
+ func (ttlc * Controller ) enqueueNode (node * v1.Node ) {
193
196
key , err := controller .KeyFunc (node )
194
197
if err != nil {
195
198
klog .Errorf ("Couldn't get key for object %+v" , node )
@@ -198,12 +201,12 @@ func (ttlc *TTLController) enqueueNode(node *v1.Node) {
198
201
ttlc .queue .Add (key )
199
202
}
200
203
201
- func (ttlc * TTLController ) worker () {
204
+ func (ttlc * Controller ) worker () {
202
205
for ttlc .processItem () {
203
206
}
204
207
}
205
208
206
- func (ttlc * TTLController ) processItem () bool {
209
+ func (ttlc * Controller ) processItem () bool {
207
210
key , quit := ttlc .queue .Get ()
208
211
if quit {
209
212
return false
@@ -221,7 +224,7 @@ func (ttlc *TTLController) processItem() bool {
221
224
return true
222
225
}
223
226
224
- func (ttlc * TTLController ) getDesiredTTLSeconds () int {
227
+ func (ttlc * Controller ) getDesiredTTLSeconds () int {
225
228
ttlc .lock .RLock ()
226
229
defer ttlc .lock .RUnlock ()
227
230
return ttlc .desiredTTLSeconds
@@ -251,7 +254,7 @@ func setIntAnnotation(node *v1.Node, annotationKey string, value int) {
251
254
node .Annotations [annotationKey ] = strconv .Itoa (value )
252
255
}
253
256
254
- func (ttlc * TTLController ) patchNodeWithAnnotation (node * v1.Node , annotationKey string , value int ) error {
257
+ func (ttlc * Controller ) patchNodeWithAnnotation (node * v1.Node , annotationKey string , value int ) error {
255
258
oldData , err := json .Marshal (node )
256
259
if err != nil {
257
260
return err
@@ -274,7 +277,7 @@ func (ttlc *TTLController) patchNodeWithAnnotation(node *v1.Node, annotationKey
274
277
return nil
275
278
}
276
279
277
- func (ttlc * TTLController ) updateNodeIfNeeded (key string ) error {
280
+ func (ttlc * Controller ) updateNodeIfNeeded (key string ) error {
278
281
node , err := ttlc .nodeStore .Get (key )
279
282
if err != nil {
280
283
if apierrors .IsNotFound (err ) {
0 commit comments