Skip to content

Commit 0e0599e

Browse files
controller: add MachineConfigNode informer so changes trigger MachineConfigPool syncs
1 parent d151372 commit 0e0599e

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

cmd/machine-config-controller/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
244244
ctx.KubeInformerFactory.Core().V1().Pods(),
245245
ctx.OCLInformerFactory.Machineconfiguration().V1().MachineOSConfigs(),
246246
ctx.OCLInformerFactory.Machineconfiguration().V1().MachineOSBuilds(),
247+
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigNodes(),
247248
ctx.ConfigInformerFactory.Config().V1().Schedulers(),
248249
ctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
249250
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
@@ -95,6 +95,7 @@ type Controller struct {
9595
mosbLister mcfglistersv1.MachineOSBuildLister
9696
nodeLister corelisterv1.NodeLister
9797
podLister corelisterv1.PodLister
98+
mcnLister mcfglistersv1.MachineConfigNodeLister
9899

99100
ccListerSynced cache.InformerSynced
100101
mcListerSynced cache.InformerSynced
@@ -124,6 +125,7 @@ func New(
124125
podInformer coreinformersv1.PodInformer,
125126
moscInformer mcfginformersv1.MachineOSConfigInformer,
126127
mosbInformer mcfginformersv1.MachineOSBuildInformer,
128+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
127129
schedulerInformer cligoinformersv1.SchedulerInformer,
128130
kubeClient clientset.Interface,
129131
mcfgClient mcfgclientset.Interface,
@@ -137,6 +139,7 @@ func New(
137139
mosbInformer,
138140
nodeInformer,
139141
podInformer,
142+
mcnInformer,
140143
schedulerInformer,
141144
kubeClient,
142145
mcfgClient,
@@ -153,6 +156,7 @@ func NewWithCustomUpdateDelay(
153156
podInformer coreinformersv1.PodInformer,
154157
moscInformer mcfginformersv1.MachineOSConfigInformer,
155158
mosbInformer mcfginformersv1.MachineOSBuildInformer,
159+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
156160
schedulerInformer cligoinformersv1.SchedulerInformer,
157161
kubeClient clientset.Interface,
158162
mcfgClient mcfgclientset.Interface,
@@ -167,6 +171,7 @@ func NewWithCustomUpdateDelay(
167171
mosbInformer,
168172
nodeInformer,
169173
podInformer,
174+
mcnInformer,
170175
schedulerInformer,
171176
kubeClient,
172177
mcfgClient,
@@ -184,6 +189,7 @@ func newController(
184189
mosbInformer mcfginformersv1.MachineOSBuildInformer,
185190
nodeInformer coreinformersv1.NodeInformer,
186191
podInformer coreinformersv1.PodInformer,
192+
mcnInformer mcfginformersv1.MachineConfigNodeInformer,
187193
schedulerInformer cligoinformersv1.SchedulerInformer,
188194
kubeClient clientset.Interface,
189195
mcfgClient mcfgclientset.Interface,
@@ -229,6 +235,11 @@ func newController(
229235
UpdateFunc: ctrl.checkMasterNodesOnUpdate,
230236
DeleteFunc: ctrl.checkMasterNodesOnDelete,
231237
})
238+
mcnInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
239+
AddFunc: ctrl.addMachineConfigNode,
240+
UpdateFunc: ctrl.updateMachineConfigNode,
241+
DeleteFunc: ctrl.deleteMachineConfigNode,
242+
})
232243

233244
ctrl.syncHandler = ctrl.syncMachineConfigPool
234245
ctrl.enqueueMachineConfigPool = ctrl.enqueueDefault
@@ -240,12 +251,14 @@ func newController(
240251
ctrl.mosbLister = mosbInformer.Lister()
241252
ctrl.nodeLister = nodeInformer.Lister()
242253
ctrl.podLister = podInformer.Lister()
254+
ctrl.mcnLister = mcnInformer.Lister()
243255
ctrl.ccListerSynced = ccInformer.Informer().HasSynced
244256
ctrl.mcListerSynced = mcInformer.Informer().HasSynced
245257
ctrl.mcpListerSynced = mcpInformer.Informer().HasSynced
246258
ctrl.moscListerSynced = moscInformer.Informer().HasSynced
247259
ctrl.mosbListerSynced = mosbInformer.Informer().HasSynced
248260
ctrl.nodeListerSynced = nodeInformer.Informer().HasSynced
261+
ctrl.mcnListerSynced = mcnInformer.Informer().HasSynced
249262

250263
ctrl.schedulerList = schedulerInformer.Lister()
251264
ctrl.schedulerListerSynced = schedulerInformer.Informer().HasSynced
@@ -537,6 +550,81 @@ func (ctrl *Controller) updateMachineOSBuild(old, cur interface{}) {
537550
ctrl.enqueueMachineConfigPool(mcp)
538551
}
539552

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

test/e2e-bootstrap/bootstrap_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
525525
ctx.KubeInformerFactory.Core().V1().Pods(),
526526
ctx.InformerFactory.Machineconfiguration().V1().MachineOSConfigs(),
527527
ctx.InformerFactory.Machineconfiguration().V1().MachineOSBuilds(),
528+
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigNodes(),
528529
ctx.ConfigInformerFactory.Config().V1().Schedulers(),
529530
ctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
530531
ctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),

0 commit comments

Comments
 (0)