@@ -92,6 +92,13 @@ func newNodeInformerController(
92
92
return controller
93
93
}
94
94
95
+ // sync is called for any controller event. There are two kinds of them:
96
+ // - standard Kubernetes informer events on watched resources such as nodes, machineConfigs, and machineConfigPools
97
+ // - synthetic events such as eventNameReconcileAllNodes. They are generated for reconciling when handling events
98
+ // of the first kind.
99
+ //
100
+ // A changed node resource produces insights that are sent to the update status controller.
101
+ // A changed mc/mcp may produce the synthetic event eventNameReconcileAllNodes which triggers the reconciliation of all nodes.
95
102
func (c * nodeInformerController ) sync (ctx context.Context , syncCtx factory.SyncContext ) error {
96
103
// Warm up controller's caches.
97
104
// This has to be called after informers caches have been synced and before the first event comes in.
@@ -117,11 +124,8 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
117
124
118
125
var msg informerMsg
119
126
switch t {
120
- case eventKindName :
121
- if name != eventNameReconcileAllNodes {
122
- return fmt .Errorf ("invalid name in queue key %s with type %s" , queueKey , t )
123
- }
124
- return c .reconcileAllNodes (syncCtx .Queue ())
127
+ case syntheticKeyName :
128
+ return c .syncSyntheticKey (name , syncCtx .Queue ())
125
129
case nodeKindName :
126
130
msgP , err := c .syncNode (ctx , name )
127
131
if err != nil {
@@ -260,7 +264,7 @@ func (c *machineConfigPoolSelectorCache) forget(mcpName string) bool {
260
264
}
261
265
262
266
func queueKeyFoReconcileAllNodes (queue workqueue.TypedRateLimitingInterface [any ]) {
263
- queue .Add (queueKeyFor (eventKindName , eventNameReconcileAllNodes ))
267
+ queue .Add (queueKeyFor (syntheticKeyName , eventNameReconcileAllNodes ))
264
268
}
265
269
266
270
func (c * nodeInformerController ) reconcileAllNodes (queue workqueue.TypedRateLimitingInterface [any ]) error {
@@ -364,6 +368,14 @@ func (c *nodeInformerController) syncNode(ctx context.Context, name string) (*in
364
368
return & msg , nil
365
369
}
366
370
371
+ func (c * nodeInformerController ) syncSyntheticKey (name string , q workqueue.TypedRateLimitingInterface [any ]) error {
372
+ if name == eventNameReconcileAllNodes {
373
+ return c .reconcileAllNodes (q )
374
+ }
375
+ klog .Errorf ("Got an invalid synthetic key %s" , name )
376
+ return nil
377
+ }
378
+
367
379
func makeInsightMsgForNode (nodeInsight * updatestatus.NodeStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
368
380
insight := updatestatus.WorkerPoolInsight {
369
381
UID : fmt .Sprintf ("node-%s" , nodeInsight .Resource .Name ),
@@ -576,10 +588,13 @@ func assessNode(node *corev1.Node, mcp *machineconfigv1.MachineConfigPool, machi
576
588
}
577
589
578
590
const (
579
- nodeKindName = "Node"
580
- machineConfigKindName = "MachineConfig"
581
- machineConfigPoolKindName = "MachineConfigPool"
582
- eventKindName = "Event"
591
+ nodeKindName = "Node"
592
+ machineConfigKindName = "MachineConfig"
593
+ machineConfigPoolKindName = "MachineConfigPool"
594
+
595
+ syntheticKeyName = "synthetic"
596
+ // eventNameReconcileAllNodes presents a synthetic event that is used when nodeInformerController should reconcile
597
+ // all nodes.
583
598
eventNameReconcileAllNodes = "reconcileAllNodes"
584
599
585
600
nodesInformerName = "ni"
@@ -598,11 +613,6 @@ func nodeInformerControllerQueueKeys(object runtime.Object) []string {
598
613
return nil
599
614
}
600
615
switch o := object .(type ) {
601
- case * corev1.Event :
602
- if o .Name != eventNameReconcileAllNodes {
603
- panic (fmt .Sprintf ("USC :: Unknown object %s with type: %T" , o .Name , object ))
604
- }
605
- return []string {queueKeyFor (eventKindName , o .Name )}
606
616
case * corev1.Node :
607
617
return []string {queueKeyFor (nodeKindName , o .Name )}
608
618
case * machineconfigv1.MachineConfig :
0 commit comments