@@ -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+
540628func (ctrl * Controller ) addMachineConfigPool (obj interface {}) {
541629 pool := obj .(* mcfgv1.MachineConfigPool )
542630 klog .V (4 ).Infof ("Adding MachineConfigPool %s" , pool .Name )
0 commit comments