Skip to content

Commit 00b8722

Browse files
Merge pull request #5422 from isabella-janssen/ocpbugs-64825
OCPBUGS-64825: Add MachineConfigNode informer to trigger MCP machine count syncs
2 parents a90949c + f1e38a6 commit 00b8722

6 files changed

Lines changed: 734 additions & 12 deletions

File tree

cmd/machine-config-controller/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
259259
ctx.KubeInformerFactory.Core().V1().Pods(),
260260
ctx.OCLInformerFactory.Machineconfiguration().V1().MachineOSConfigs(),
261261
ctx.OCLInformerFactory.Machineconfiguration().V1().MachineOSBuilds(),
262+
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigNodes(),
262263
ctx.ConfigInformerFactory.Config().V1().Schedulers(),
263264
ctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
264265
ctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),

pkg/controller/node/node_controller.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Controller struct {
9494
mosbLister mcfglistersv1.MachineOSBuildLister
9595
nodeLister corelisterv1.NodeLister
9696
podLister corelisterv1.PodLister
97+
mcnLister mcfglistersv1.MachineConfigNodeLister
9798

9899
ccListerSynced cache.InformerSynced
99100
mcListerSynced cache.InformerSynced
@@ -123,6 +124,7 @@ func New(
123124
podInformer coreinformersv1.PodInformer,
124125
moscInformer mcfginformersv1.MachineOSConfigInformer,
125126
mosbInformer mcfginformersv1.MachineOSBuildInformer,
127+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
126128
schedulerInformer cligoinformersv1.SchedulerInformer,
127129
kubeClient clientset.Interface,
128130
mcfgClient mcfgclientset.Interface,
@@ -136,6 +138,7 @@ func New(
136138
mosbInformer,
137139
nodeInformer,
138140
podInformer,
141+
mcnInformer,
139142
schedulerInformer,
140143
kubeClient,
141144
mcfgClient,
@@ -152,6 +155,7 @@ func NewWithCustomUpdateDelay(
152155
podInformer coreinformersv1.PodInformer,
153156
moscInformer mcfginformersv1.MachineOSConfigInformer,
154157
mosbInformer mcfginformersv1.MachineOSBuildInformer,
158+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
155159
schedulerInformer cligoinformersv1.SchedulerInformer,
156160
kubeClient clientset.Interface,
157161
mcfgClient mcfgclientset.Interface,
@@ -166,6 +170,7 @@ func NewWithCustomUpdateDelay(
166170
mosbInformer,
167171
nodeInformer,
168172
podInformer,
173+
mcnInformer,
169174
schedulerInformer,
170175
kubeClient,
171176
mcfgClient,
@@ -183,6 +188,7 @@ func newController(
183188
mosbInformer mcfginformersv1.MachineOSBuildInformer,
184189
nodeInformer coreinformersv1.NodeInformer,
185190
podInformer coreinformersv1.PodInformer,
191+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
186192
schedulerInformer cligoinformersv1.SchedulerInformer,
187193
kubeClient clientset.Interface,
188194
mcfgClient mcfgclientset.Interface,
@@ -228,6 +234,11 @@ func newController(
228234
UpdateFunc: ctrl.checkMasterNodesOnUpdate,
229235
DeleteFunc: ctrl.checkMasterNodesOnDelete,
230236
})
237+
mcnInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
238+
AddFunc: ctrl.addMachineConfigNode,
239+
UpdateFunc: ctrl.updateMachineConfigNode,
240+
DeleteFunc: ctrl.deleteMachineConfigNode,
241+
})
231242

232243
ctrl.syncHandler = ctrl.syncMachineConfigPool
233244
ctrl.enqueueMachineConfigPool = ctrl.enqueueDefault
@@ -239,12 +250,14 @@ func newController(
239250
ctrl.mosbLister = mosbInformer.Lister()
240251
ctrl.nodeLister = nodeInformer.Lister()
241252
ctrl.podLister = podInformer.Lister()
253+
ctrl.mcnLister = mcnInformer.Lister()
242254
ctrl.ccListerSynced = ccInformer.Informer().HasSynced
243255
ctrl.mcListerSynced = mcInformer.Informer().HasSynced
244256
ctrl.mcpListerSynced = mcpInformer.Informer().HasSynced
245257
ctrl.moscListerSynced = moscInformer.Informer().HasSynced
246258
ctrl.mosbListerSynced = mosbInformer.Informer().HasSynced
247259
ctrl.nodeListerSynced = nodeInformer.Informer().HasSynced
260+
ctrl.mcnListerSynced = mcnInformer.Informer().HasSynced
248261

249262
ctrl.schedulerList = schedulerInformer.Lister()
250263
ctrl.schedulerListerSynced = schedulerInformer.Informer().HasSynced
@@ -536,6 +549,81 @@ func (ctrl *Controller) updateMachineOSBuild(old, cur interface{}) {
536549
ctrl.enqueueMachineConfigPool(mcp)
537550
}
538551

552+
func (ctrl *Controller) addMachineConfigNode(obj interface{}) {
553+
curMCN := obj.(*mcfgv1.MachineConfigNode)
554+
klog.V(4).Infof("Adding MachineConfigNode %s", curMCN.Name)
555+
556+
// Find the associated MachineConfigPool from the MachineConfigNode. If the pool value is
557+
// "not-yet-set" it means that the MCN does not have an associated MCP yet.
558+
poolName := curMCN.Spec.Pool.Name
559+
if poolName == upgrademonitor.NotYetSet {
560+
return
561+
}
562+
563+
mcp, err := ctrl.mcpLister.Get(poolName)
564+
if err != nil {
565+
utilruntime.HandleError(fmt.Errorf("Couldn't get MachineConfigPool from MachineConfigNode %v: %v", curMCN, err))
566+
return
567+
}
568+
klog.V(4).Infof("MachineConfigNode %s affects MachineConfigPool %s", curMCN.Name, mcp.Name)
569+
ctrl.enqueueMachineConfigPool(mcp)
570+
}
571+
572+
func (ctrl *Controller) updateMachineConfigNode(old, cur interface{}) {
573+
oldMCN := old.(*mcfgv1.MachineConfigNode)
574+
curMCN := cur.(*mcfgv1.MachineConfigNode)
575+
576+
// Only process if the MCN conditions, desired config, or pool association has changed. If the
577+
// pool name value is "not-yet-set" it means that the MCN does not have an associated MCP yet,
578+
// which is also a condition we should skip on.
579+
curPoolName := curMCN.Spec.Pool.Name
580+
if curPoolName == upgrademonitor.NotYetSet || (oldMCN.Spec.Pool.Name == curPoolName &&
581+
oldMCN.Spec.ConfigVersion.Desired == curMCN.Spec.ConfigVersion.Desired &&
582+
equality.Semantic.DeepEqual(oldMCN.Status.Conditions, curMCN.Status.Conditions)) {
583+
return
584+
}
585+
586+
klog.V(4).Infof("Updating MachineConfigNode %s", curMCN.Name)
587+
588+
mcp, err := ctrl.mcpLister.Get(curPoolName)
589+
if err != nil {
590+
utilruntime.HandleError(fmt.Errorf("Couldn't get MachineConfigPool from MachineConfigNode %v: %v", curMCN.Name, err))
591+
return
592+
}
593+
klog.V(4).Infof("MachineConfigNode %s status changed for MachineConfigPool %s", curMCN.Name, mcp.Name)
594+
ctrl.enqueueMachineConfigPool(mcp)
595+
}
596+
597+
func (ctrl *Controller) deleteMachineConfigNode(obj interface{}) {
598+
curMCN, ok := obj.(*mcfgv1.MachineConfigNode)
599+
if !ok {
600+
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
601+
if !ok {
602+
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", obj))
603+
return
604+
}
605+
curMCN, ok = tombstone.Obj.(*mcfgv1.MachineConfigNode)
606+
if !ok {
607+
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a MCN %#v", obj))
608+
return
609+
}
610+
}
611+
klog.V(4).Infof("Deleting MachineConfigNode %s", curMCN.Name)
612+
613+
// Find the associated MachineConfigPool from the MachineConfigNode. If the pool value is
614+
// "not-yet-set" it means that the MCN does not have an associated MCP yet.
615+
mcpName := curMCN.Spec.Pool.Name
616+
if mcpName == upgrademonitor.NotYetSet {
617+
return
618+
}
619+
mcp, err := ctrl.mcpLister.Get(mcpName)
620+
if err != nil {
621+
utilruntime.HandleError(fmt.Errorf("Couldn't get MachineConfigPool from MachineConfigNode %v", curMCN.Name))
622+
return
623+
}
624+
ctrl.enqueueMachineConfigPool(mcp)
625+
}
626+
539627
func (ctrl *Controller) addMachineConfigPool(obj interface{}) {
540628
pool := obj.(*mcfgv1.MachineConfigPool)
541629
klog.V(4).Infof("Adding MachineConfigPool %s", pool.Name)

pkg/controller/node/node_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (f *fixture) newControllerWithStopChan(stopCh <-chan struct{}) *Controller
107107
k8sI := kubeinformers.NewSharedInformerFactory(f.kubeclient, noResyncPeriodFunc())
108108
ci := configv1informer.NewSharedInformerFactory(f.schedulerClient, noResyncPeriodFunc())
109109
c := NewWithCustomUpdateDelay(i.Machineconfiguration().V1().ControllerConfigs(), i.Machineconfiguration().V1().MachineConfigs(), i.Machineconfiguration().V1().MachineConfigPools(), k8sI.Core().V1().Nodes(),
110-
k8sI.Core().V1().Pods(), i.Machineconfiguration().V1().MachineOSConfigs(), i.Machineconfiguration().V1().MachineOSBuilds(), ci.Config().V1().Schedulers(), f.kubeclient, f.client, time.Millisecond, f.fgHandler)
110+
k8sI.Core().V1().Pods(), i.Machineconfiguration().V1().MachineOSConfigs(), i.Machineconfiguration().V1().MachineOSBuilds(), i.Machineconfiguration().V1().MachineConfigNodes(), ci.Config().V1().Schedulers(), f.kubeclient, f.client, time.Millisecond, f.fgHandler)
111111

112112
c.ccListerSynced = alwaysReady
113113
c.mcpListerSynced = alwaysReady
@@ -264,7 +264,9 @@ func filterInformerActions(actions []core.Action) []core.Action {
264264
action.Matches("list", "machineosbuilds") ||
265265
action.Matches("watch", "machineosbuilds") ||
266266
action.Matches("list", "machineosconfigs") ||
267-
action.Matches("watch", "machineosconfigs")) {
267+
action.Matches("watch", "machineosconfigs") ||
268+
action.Matches("list", "machineconfignodes") ||
269+
action.Matches("watch", "machineconfignodes")) {
268270
continue
269271
}
270272
ret = append(ret, action)

0 commit comments

Comments
 (0)