@@ -13,6 +13,7 @@ import (
13
13
"k8s.io/apimachinery/pkg/runtime"
14
14
kubeinformers "k8s.io/client-go/informers"
15
15
corelistersv1 "k8s.io/client-go/listers/core/v1"
16
+ "k8s.io/client-go/util/workqueue"
16
17
"k8s.io/klog/v2"
17
18
18
19
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
@@ -63,10 +64,16 @@ func newNodeInformerController(
63
64
}
64
65
65
66
nodeInformer := coreInformers .Core ().V1 ().Nodes ().Informer ()
67
+ mcInformer := machineConfigInformers .Machineconfiguration ().V1 ().MachineConfigs ().Informer ()
68
+ mcpInformer := machineConfigInformers .Machineconfiguration ().V1 ().MachineConfigPools ().Informer ()
66
69
67
70
controller := factory .New ().
68
71
// call sync on node changes
69
72
WithInformersQueueKeysFunc (nodeInformerControllerQueueKeys , nodeInformer ).
73
+ // call sync on machine config changes
74
+ WithInformersQueueKeysFunc (nodeInformerControllerQueueKeys , mcInformer ).
75
+ // call sync on machine config pool changes
76
+ WithInformersQueueKeysFunc (nodeInformerControllerQueueKeys , mcpInformer ).
70
77
WithSync (c .sync ).
71
78
ToController ("NodeInformer" , c .recorder )
72
79
@@ -75,6 +82,7 @@ func newNodeInformerController(
75
82
76
83
func (c * nodeInformerController ) sync (ctx context.Context , syncCtx factory.SyncContext ) error {
77
84
queueKey := syncCtx .QueueKey ()
85
+ klog .V (4 ).Infof ("NI :: Syncing with key %s" , queueKey )
78
86
79
87
t , name , err := parseNodeInformerControllerQueueKey (queueKey )
80
88
if err != nil {
@@ -131,6 +139,10 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
131
139
return nil
132
140
}
133
141
}
142
+ case machineConfigKindName :
143
+ return c .reconcileAllNodes (syncCtx .Queue ())
144
+ case machineConfigPoolKindName :
145
+ return c .reconcileAllNodes (syncCtx .Queue ())
134
146
default :
135
147
return fmt .Errorf ("invalid queue key %s with unexpected type %s" , queueKey , t )
136
148
}
@@ -143,6 +155,17 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
143
155
return nil
144
156
}
145
157
158
+ func (c * nodeInformerController ) reconcileAllNodes (queue workqueue.TypedRateLimitingInterface [any ]) error {
159
+ nodes , err := c .nodes .List (labels .Everything ())
160
+ if err != nil {
161
+ return err
162
+ }
163
+ for _ , node := range nodes {
164
+ queue .Add (kindAndNameToQueueKey (nodeKindName , node .Name ))
165
+ }
166
+ return nil
167
+ }
168
+
146
169
func makeInsightMsgForNode (nodeInsight * updatestatus.NodeStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
147
170
insight := updatestatus.WorkerPoolInsight {
148
171
UID : fmt .Sprintf ("node-%s" , nodeInsight .Resource .Name ),
@@ -374,7 +397,10 @@ func assessNode(node *corev1.Node, mcp *machineconfigv1.MachineConfigPool, machi
374
397
}
375
398
376
399
const (
377
- nodeKindName = "Node"
400
+ nodeKindName = "Node"
401
+ machineConfigKindName = "MachineConfig"
402
+ machineConfigPoolKindName = "MachineConfigPool"
403
+
378
404
nodesInformerName = "ni"
379
405
)
380
406
@@ -392,8 +418,16 @@ func nodeInformerControllerQueueKeys(object runtime.Object) []string {
392
418
}
393
419
switch o := object .(type ) {
394
420
case * corev1.Node :
395
- return []string {fmt .Sprintf ("%s/%s" , nodeKindName , o .Name )}
421
+ return []string {kindAndNameToQueueKey (nodeKindName , o .Name )}
422
+ case * machineconfigv1.MachineConfig :
423
+ return []string {kindAndNameToQueueKey (machineConfigKindName , o .Name )}
424
+ case * machineconfigv1.MachineConfigPool :
425
+ return []string {kindAndNameToQueueKey (machineConfigPoolKindName , o .Name )}
396
426
default :
397
427
panic (fmt .Sprintf ("USC :: Unknown object type: %T" , object ))
398
428
}
399
429
}
430
+
431
+ func kindAndNameToQueueKey (kind , name string ) string {
432
+ return fmt .Sprintf ("%s/%s" , kind , name )
433
+ }
0 commit comments