Skip to content

Commit 771bc03

Browse files
committed
usc: requeue all Nodes upon MCP/MC events
1 parent 7afbeb0 commit 771bc03

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

pkg/updatestatus/nodeinformer.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/apimachinery/pkg/runtime"
1414
kubeinformers "k8s.io/client-go/informers"
1515
corelistersv1 "k8s.io/client-go/listers/core/v1"
16+
"k8s.io/client-go/util/workqueue"
1617
"k8s.io/klog/v2"
1718

1819
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
@@ -63,10 +64,16 @@ func newNodeInformerController(
6364
}
6465

6566
nodeInformer := coreInformers.Core().V1().Nodes().Informer()
67+
mcInformer := machineConfigInformers.Machineconfiguration().V1().MachineConfigs().Informer()
68+
mcpInformer := machineConfigInformers.Machineconfiguration().V1().MachineConfigPools().Informer()
6669

6770
controller := factory.New().
6871
// call sync on node changes
6972
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).
7077
WithSync(c.sync).
7178
ToController("NodeInformer", c.recorder)
7279

@@ -75,6 +82,7 @@ func newNodeInformerController(
7582

7683
func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncContext) error {
7784
queueKey := syncCtx.QueueKey()
85+
klog.V(4).Infof("NI :: Syncing with key %s", queueKey)
7886

7987
t, name, err := parseNodeInformerControllerQueueKey(queueKey)
8088
if err != nil {
@@ -131,6 +139,10 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
131139
return nil
132140
}
133141
}
142+
case machineConfigKindName:
143+
return c.reconcileAllNodes(syncCtx.Queue())
144+
case machineConfigPoolKindName:
145+
return c.reconcileAllNodes(syncCtx.Queue())
134146
default:
135147
return fmt.Errorf("invalid queue key %s with unexpected type %s", queueKey, t)
136148
}
@@ -143,6 +155,17 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
143155
return nil
144156
}
145157

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+
146169
func makeInsightMsgForNode(nodeInsight *updatestatus.NodeStatusInsight, acquiredAt metav1.Time) (informerMsg, error) {
147170
insight := updatestatus.WorkerPoolInsight{
148171
UID: fmt.Sprintf("node-%s", nodeInsight.Resource.Name),
@@ -374,7 +397,10 @@ func assessNode(node *corev1.Node, mcp *machineconfigv1.MachineConfigPool, machi
374397
}
375398

376399
const (
377-
nodeKindName = "Node"
400+
nodeKindName = "Node"
401+
machineConfigKindName = "MachineConfig"
402+
machineConfigPoolKindName = "MachineConfigPool"
403+
378404
nodesInformerName = "ni"
379405
)
380406

@@ -392,8 +418,16 @@ func nodeInformerControllerQueueKeys(object runtime.Object) []string {
392418
}
393419
switch o := object.(type) {
394420
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)}
396426
default:
397427
panic(fmt.Sprintf("USC :: Unknown object type: %T", object))
398428
}
399429
}
430+
431+
func kindAndNameToQueueKey(kind, name string) string {
432+
return fmt.Sprintf("%s/%s", kind, name)
433+
}

0 commit comments

Comments
 (0)