Skip to content

Commit df2762b

Browse files
add custom MCP support for MCN feature
1 parent 244bc58 commit df2762b

File tree

13 files changed

+222
-42
lines changed

13 files changed

+222
-42
lines changed

cmd/machine-config-controller/start.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func runStartCmd(_ *cobra.Command, _ []string) {
7979
draincontroller := drain.New(
8080
drain.DefaultConfig(),
8181
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
82+
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
8283
ctrlctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
8384
ctrlctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),
8485
ctrlctx.FeatureGateAccess,

cmd/machine-config-daemon/start.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func runStartCmd(_ *cobra.Command, _ []string) {
186186
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigs(),
187187
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
188188
ctrlctx.InformerFactory.Machineconfiguration().V1().ControllerConfigs(),
189+
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
189190
ctrlctx.ClientBuilder.OperatorClientOrDie(componentName),
190191
startOpts.kubeletHealthzEnabled,
191192
startOpts.kubeletHealthzEndpoint,

pkg/controller/drain/drain_controller.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1414
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
1515
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
16+
"github.com/openshift/machine-config-operator/pkg/helpers"
1617
"github.com/openshift/machine-config-operator/pkg/upgrademonitor"
1718

1819
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -23,6 +24,8 @@ import (
2324
"k8s.io/apimachinery/pkg/util/strategicpatch"
2425
"k8s.io/apimachinery/pkg/util/wait"
2526

27+
mcfginformersv1 "github.com/openshift/client-go/machineconfiguration/informers/externalversions/machineconfiguration/v1"
28+
mcfglistersv1 "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1"
2629
corev1 "k8s.io/api/core/v1"
2730
coreinformersv1 "k8s.io/client-go/informers/core/v1"
2831
clientset "k8s.io/client-go/kubernetes"
@@ -98,6 +101,9 @@ type Controller struct {
98101
nodeLister corelisterv1.NodeLister
99102
nodeListerSynced cache.InformerSynced
100103

104+
mcpLister mcfglistersv1.MachineConfigPoolLister
105+
mcpListerSynced cache.InformerSynced
106+
101107
queue workqueue.TypedRateLimitingInterface[string]
102108
ongoingDrains map[string]time.Time
103109

@@ -110,6 +116,7 @@ type Controller struct {
110116
func New(
111117
cfg Config,
112118
nodeInformer coreinformersv1.NodeInformer,
119+
mcpInformer mcfginformersv1.MachineConfigPoolInformer,
113120
kubeClient clientset.Interface,
114121
mcfgClient mcfgclientset.Interface,
115122
fgAccessor featuregates.FeatureGateAccess,
@@ -140,6 +147,9 @@ func New(
140147
ctrl.nodeLister = nodeInformer.Lister()
141148
ctrl.nodeListerSynced = nodeInformer.Informer().HasSynced
142149

150+
ctrl.mcpLister = mcpInformer.Lister()
151+
ctrl.mcpListerSynced = mcpInformer.Informer().HasSynced
152+
143153
return ctrl
144154
}
145155

@@ -159,7 +169,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) {
159169
defer utilruntime.HandleCrash()
160170
defer ctrl.queue.ShutDown()
161171

162-
if !cache.WaitForCacheSync(stopCh, ctrl.nodeListerSynced) {
172+
if !cache.WaitForCacheSync(stopCh, ctrl.nodeListerSynced, ctrl.mcpListerSynced) {
163173
return
164174
}
165175

@@ -305,6 +315,12 @@ func (ctrl *Controller) syncNode(key string) error {
305315
Ctx: context.TODO(),
306316
}
307317

318+
// Get MCP associated with node
319+
pool, err := helpers.GetPrimaryPoolNameForMCN(ctrl.mcpLister, node)
320+
if err != nil {
321+
return err
322+
}
323+
308324
desiredVerb := strings.Split(desiredState, "-")[0]
309325
switch desiredVerb {
310326
case daemonconsts.DrainerStateUncordon:
@@ -318,6 +334,7 @@ func (ctrl *Controller) syncNode(key string) error {
318334
node,
319335
ctrl.client,
320336
ctrl.featureGatesAccessor,
337+
pool,
321338
)
322339
if nErr != nil {
323340
klog.Errorf("Error making MCN for Uncordon failure: %v", err)
@@ -333,6 +350,7 @@ func (ctrl *Controller) syncNode(key string) error {
333350
node,
334351
ctrl.client,
335352
ctrl.featureGatesAccessor,
353+
pool,
336354
)
337355
if err != nil {
338356
klog.Errorf("Error making MCN for UnCordon success: %v", err)
@@ -387,6 +405,12 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
387405
break
388406
}
389407

408+
// Get MCP associated with node
409+
pool, err := helpers.GetPrimaryPoolNameForMCN(ctrl.mcpLister, node)
410+
if err != nil {
411+
return err
412+
}
413+
390414
if !isOngoingDrain {
391415
ctrl.logNode(node, "cordoning")
392416
// perform cordon
@@ -398,6 +422,7 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
398422
node,
399423
ctrl.client,
400424
ctrl.featureGatesAccessor,
425+
pool,
401426
)
402427
if Nerr != nil {
403428
klog.Errorf("Error making MCN for Cordon Failure: %v", Nerr)
@@ -412,6 +437,7 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
412437
node,
413438
ctrl.client,
414439
ctrl.featureGatesAccessor,
440+
pool,
415441
)
416442
if err != nil {
417443
klog.Errorf("Error making MCN for Cordon Success: %v", err)
@@ -420,14 +446,15 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
420446

421447
// Attempt drain
422448
ctrl.logNode(node, "initiating drain")
423-
err := upgrademonitor.GenerateAndApplyMachineConfigNodes(
449+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
424450
&upgrademonitor.Condition{State: v1alpha1.MachineConfigNodeUpdateExecuted, Reason: string(v1alpha1.MachineConfigNodeUpdateDrained), Message: "Draining Node as part of update executed phase"},
425451
&upgrademonitor.Condition{State: v1alpha1.MachineConfigNodeUpdateDrained, Reason: fmt.Sprintf("%s%s", string(v1alpha1.MachineConfigNodeUpdateExecuted), string(v1alpha1.MachineConfigNodeUpdateDrained)), Message: fmt.Sprintf("Draining node. The drain will not be complete until desired drainer %s matches current drainer %s", node.Annotations[daemonconsts.DesiredDrainerAnnotationKey], node.Annotations[daemonconsts.LastAppliedDrainerAnnotationKey])},
426452
metav1.ConditionUnknown,
427453
metav1.ConditionUnknown,
428454
node,
429455
ctrl.client,
430456
ctrl.featureGatesAccessor,
457+
pool,
431458
)
432459
if err != nil {
433460
klog.Errorf("Error making MCN for Drain beginning: %v", err)
@@ -457,6 +484,7 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
457484
node,
458485
ctrl.client,
459486
ctrl.featureGatesAccessor,
487+
pool,
460488
)
461489
if nErr != nil {
462490
klog.Errorf("Error making MCN for Drain failure: %v", nErr)
@@ -473,6 +501,7 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro
473501
node,
474502
ctrl.client,
475503
ctrl.featureGatesAccessor,
504+
pool,
476505
)
477506
if err != nil {
478507
klog.Errorf("Error making MCN for Drain success: %v", err)

pkg/daemon/daemon.go

+27-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ import (
5151
mcoResourceRead "github.com/openshift/machine-config-operator/lib/resourceread"
5252
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
5353
"github.com/openshift/machine-config-operator/pkg/daemon/constants"
54-
"github.com/openshift/machine-config-operator/pkg/upgrademonitor"
55-
5654
"github.com/openshift/machine-config-operator/pkg/daemon/osrelease"
55+
"github.com/openshift/machine-config-operator/pkg/helpers"
56+
"github.com/openshift/machine-config-operator/pkg/upgrademonitor"
5757
)
5858

5959
// Daemon is the dispatch point for the functions of the agent on the
@@ -100,6 +100,9 @@ type Daemon struct {
100100
mcLister mcfglistersv1.MachineConfigLister
101101
mcListerSynced cache.InformerSynced
102102

103+
mcpLister mcfglistersv1.MachineConfigPoolLister
104+
mcpListerSynced cache.InformerSynced
105+
103106
ccLister mcfglistersv1.ControllerConfigLister
104107
ccListerSynced cache.InformerSynced
105108

@@ -362,6 +365,7 @@ func (dn *Daemon) ClusterConnect(
362365
mcInformer mcfginformersv1.MachineConfigInformer,
363366
nodeInformer coreinformersv1.NodeInformer,
364367
ccInformer mcfginformersv1.ControllerConfigInformer,
368+
mcpInformer mcfginformersv1.MachineConfigPoolInformer,
365369
mcopClient mcopclientset.Interface,
366370
kubeletHealthzEnabled bool,
367371
kubeletHealthzEndpoint string,
@@ -396,6 +400,8 @@ func (dn *Daemon) ClusterConnect(
396400
})
397401
dn.ccLister = ccInformer.Lister()
398402
dn.ccListerSynced = ccInformer.Informer().HasSynced
403+
dn.mcpLister = mcpInformer.Lister()
404+
dn.mcpListerSynced = mcpInformer.Informer().HasSynced
399405

400406
nw, err := newNodeWriter(dn.name, dn.stopCh)
401407
if err != nil {
@@ -705,6 +711,12 @@ func (dn *Daemon) syncNode(key string) error {
705711
return nil
706712
}
707713

714+
// Get MCP associated with node
715+
pool, err := helpers.GetPrimaryPoolNameForMCN(dn.mcpLister, node)
716+
if err != nil {
717+
return err
718+
}
719+
708720
if node.Annotations[constants.MachineConfigDaemonPostConfigAction] == constants.MachineConfigDaemonStateRebooting {
709721
klog.Info("Detected Rebooting Annotation, applying MCN.")
710722
err := upgrademonitor.GenerateAndApplyMachineConfigNodes(
@@ -715,6 +727,7 @@ func (dn *Daemon) syncNode(key string) error {
715727
node,
716728
dn.mcfgClient,
717729
dn.featureGatesAccessor,
730+
pool,
718731
)
719732
if err != nil {
720733
klog.Errorf("Error making MCN for Rebooted: %v", err)
@@ -790,6 +803,7 @@ func (dn *Daemon) syncNode(key string) error {
790803
node,
791804
dn.mcfgClient,
792805
dn.featureGatesAccessor,
806+
pool,
793807
)
794808
if err != nil {
795809
klog.Errorf("Error making MCN for Resumed true: %v", err)
@@ -828,6 +842,7 @@ func (dn *Daemon) syncNode(key string) error {
828842
dn.node,
829843
dn.mcfgClient,
830844
dn.featureGatesAccessor,
845+
pool,
831846
)
832847
if err != nil {
833848
klog.Errorf("Error making MCN for Updated false: %v", err)
@@ -852,6 +867,7 @@ func (dn *Daemon) syncNode(key string) error {
852867
dn.node,
853868
dn.mcfgClient,
854869
dn.featureGatesAccessor,
870+
pool,
855871
)
856872
if err != nil {
857873
klog.Errorf("Error making MCN for Updated: %v", err)
@@ -1379,7 +1395,7 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error, errCh chan er
13791395
defer dn.ccQueue.ShutDown()
13801396
defer dn.preserveDaemonLogs()
13811397

1382-
if !cache.WaitForCacheSync(stopCh, dn.nodeListerSynced, dn.mcListerSynced, dn.ccListerSynced) {
1398+
if !cache.WaitForCacheSync(stopCh, dn.nodeListerSynced, dn.mcListerSynced, dn.ccListerSynced, dn.mcpListerSynced) {
13831399
return fmt.Errorf("failed to sync initial listers cache")
13841400
}
13851401

@@ -2300,6 +2316,13 @@ func (dn *Daemon) updateConfigAndState(state *stateAndConfigs) (bool, bool, erro
23002316
if inDesiredConfig {
23012317
// Great, we've successfully rebooted for the desired config,
23022318
// let's mark it done!
2319+
2320+
// Get MCP associated with node
2321+
pool, err := helpers.GetPrimaryPoolNameForMCN(dn.mcpLister, dn.node)
2322+
if err != nil {
2323+
return missingODC, inDesiredConfig, err
2324+
}
2325+
23032326
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
23042327
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeResumed, Reason: string(mcfgalphav1.MachineConfigNodeResumed), Message: fmt.Sprintf("In desired config %s. Resumed normal operations. Applying proper annotations.", state.currentConfig.Name)},
23052328
nil,
@@ -2308,6 +2331,7 @@ func (dn *Daemon) updateConfigAndState(state *stateAndConfigs) (bool, bool, erro
23082331
dn.node,
23092332
dn.mcfgClient,
23102333
dn.featureGatesAccessor,
2334+
pool,
23112335
)
23122336
if err != nil {
23132337
klog.Errorf("Error making MCN for Resumed true: %v", err)

pkg/daemon/daemon_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (f *fixture) newController() *Daemon {
161161
i.Machineconfiguration().V1().MachineConfigs(),
162162
k8sI.Core().V1().Nodes(),
163163
i.Machineconfiguration().V1().ControllerConfigs(),
164+
i.Machineconfiguration().V1().MachineConfigPools(),
164165
f.oclient,
165166
false,
166167
"",
@@ -169,6 +170,7 @@ func (f *fixture) newController() *Daemon {
169170

170171
d.mcListerSynced = alwaysReady
171172
d.nodeListerSynced = alwaysReady
173+
d.mcpListerSynced = alwaysReady
172174

173175
stopCh := make(chan struct{})
174176
defer close(stopCh)

pkg/daemon/drain.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/openshift/machine-config-operator/pkg/apihelpers"
1616
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
1717
"github.com/openshift/machine-config-operator/pkg/daemon/constants"
18+
19+
"github.com/openshift/machine-config-operator/pkg/helpers"
1820
"github.com/openshift/machine-config-operator/pkg/upgrademonitor"
1921
corev1 "k8s.io/api/core/v1"
2022
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -39,14 +41,22 @@ func (dn *Daemon) performDrain() error {
3941

4042
if !dn.drainRequired() {
4143
logSystem("Drain not required, skipping")
42-
err := upgrademonitor.GenerateAndApplyMachineConfigNodes(
44+
45+
// Get MCP associated with node
46+
pool, err := helpers.GetPrimaryPoolNameForMCN(dn.mcpLister, dn.node)
47+
if err != nil {
48+
return err
49+
}
50+
51+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
4352
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgalphav1.MachineConfigNodeUpdateDrained), Message: "Node Drain Not required for this update."},
4453
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateDrained, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdateExecuted), string(mcfgalphav1.MachineConfigNodeUpdateDrained)), Message: "Node Drain Not required for this update."},
4554
metav1.ConditionUnknown,
4655
metav1.ConditionFalse,
4756
dn.node,
4857
dn.mcfgClient,
4958
dn.featureGatesAccessor,
59+
pool,
5060
)
5161
if err != nil {
5262
klog.Errorf("Error making MCN for Drain not required: %v", err)

pkg/daemon/pinned_image_set.go

+22
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ func (p *PinnedImageSetManager) updateStatusProgressing(pools []*mcfgv1.MachineC
544544
}
545545
imageSetSpec := getPinnedImageSetSpecForPools(pools)
546546

547+
// Get MCP associated with node
548+
pool, err := helpers.GetPrimaryPoolNameForMCN(p.mcpLister, node)
549+
if err != nil {
550+
return err
551+
}
552+
547553
return upgrademonitor.UpdateMachineConfigNodeStatus(
548554
&upgrademonitor.Condition{
549555
State: mcfgv1alpha1.MachineConfigNodePinnedImageSetsProgressing,
@@ -558,6 +564,7 @@ func (p *PinnedImageSetManager) updateStatusProgressing(pools []*mcfgv1.MachineC
558564
applyCfg,
559565
imageSetSpec,
560566
p.featureGatesAccessor,
567+
pool,
561568
)
562569
}
563570

@@ -574,6 +581,12 @@ func (p *PinnedImageSetManager) updateStatusProgressingComplete(pools []*mcfgv1.
574581
}
575582
imageSetSpec := getPinnedImageSetSpecForPools(pools)
576583

584+
// Get MCP associated with node
585+
pool, err := helpers.GetPrimaryPoolNameForMCN(p.mcpLister, node)
586+
if err != nil {
587+
return err
588+
}
589+
577590
err = upgrademonitor.UpdateMachineConfigNodeStatus(
578591
&upgrademonitor.Condition{
579592
State: mcfgv1alpha1.MachineConfigNodePinnedImageSetsProgressing,
@@ -588,6 +601,7 @@ func (p *PinnedImageSetManager) updateStatusProgressingComplete(pools []*mcfgv1.
588601
applyCfg,
589602
imageSetSpec,
590603
p.featureGatesAccessor,
604+
pool,
591605
)
592606
if err != nil {
593607
klog.Errorf("Failed to updated machine config node: %v", err)
@@ -608,6 +622,7 @@ func (p *PinnedImageSetManager) updateStatusProgressingComplete(pools []*mcfgv1.
608622
nil,
609623
nil,
610624
p.featureGatesAccessor,
625+
pool,
611626
)
612627
}
613628

@@ -632,6 +647,12 @@ func (p *PinnedImageSetManager) updateStatusError(pools []*mcfgv1.MachineConfigP
632647
errMsg = statusErr.Error()
633648
}
634649

650+
// Get MCP associated with node
651+
pool, err := helpers.GetPrimaryPoolNameForMCN(p.mcpLister, node)
652+
if err != nil {
653+
return err
654+
}
655+
635656
return upgrademonitor.UpdateMachineConfigNodeStatus(
636657
&upgrademonitor.Condition{
637658
State: mcfgv1alpha1.MachineConfigNodePinnedImageSetsDegraded,
@@ -646,6 +667,7 @@ func (p *PinnedImageSetManager) updateStatusError(pools []*mcfgv1.MachineConfigP
646667
applyCfg,
647668
imageSetSpec,
648669
p.featureGatesAccessor,
670+
pool,
649671
)
650672
}
651673

0 commit comments

Comments
 (0)