Skip to content

Commit 32555ad

Browse files
no reboot working, getting reboot to work now
1 parent 76ac40e commit 32555ad

File tree

2 files changed

+89
-100
lines changed

2 files changed

+89
-100
lines changed

pkg/controller/build/reconciler.go

+88-100
Original file line numberDiff line numberDiff line change
@@ -378,49 +378,32 @@ func (b *buildReconciler) updateMachineConfigPool(ctx context.Context, oldMCP, c
378378
return err
379379
}
380380

381-
/////////// REMOVE JUST FOR LOGS ///////////
382-
// Get current and desired MachineConfigs
383-
curMC, err := b.machineConfigLister.Get(oldMCP.Spec.Configuration.Name)
384-
if err != nil {
385-
return fmt.Errorf("error getting current MachineConfig %s: %w", oldMCP.Spec.Configuration.Name, err)
386-
}
387-
388-
desMC, err := b.machineConfigLister.Get(curMCP.Spec.Configuration.Name)
389-
if err != nil {
390-
return fmt.Errorf("error getting desired MachineConfig %s: %w", curMCP.Spec.Configuration.Name, err)
391-
}
392-
393-
klog.Infof("desMC is %s", desMC.Name)
394-
klog.Infof("currMC is %s", curMC.Name)
395-
/////////// REMOVE JUST FOR LOGS ///////////
396-
397381
mosc, err := utils.GetMachineOSConfigForMachineConfigPool(curMCP, b.utilListers())
398382
if err != nil {
399383
return fmt.Errorf("could not find MachineOSConfig for pool %q: %w", curMCP.Name, err)
400384
}
385+
401386
existingName := mosc.Annotations[constants.CurrentMachineOSBuildAnnotationKey]
402387
if existingName == "" {
403-
return fmt.Errorf("no current build annotation on MachineOSConfig %q", mosc.Name)
388+
klog.Infof("existing name is empty, creating a new MOSB")
389+
return b.createNewMachineOSBuildOrReuseExistingForPoolChange(ctx, curMCP)
404390
}
391+
405392
existingMosb, err := b.machineOSBuildLister.Get(existingName)
406393
if err != nil {
407394
return fmt.Errorf("could not fetch existing MachineOSBuild %q: %w", existingName, err)
408395
}
409-
if !needsImageRebuild && existingMosb != nil {
410-
if err := b.deleteMachineOSBuild(ctx, existingMosb); err != nil {
411-
return err
412-
}
413-
return b.createNewMachineOSBuildOrReuseExisting(ctx, mosc, true)
414-
} else {
396+
klog.Infof("[syncmachineconfigpool] existing MOSB is %s", existingMosb.Name)
397+
398+
if needsImageRebuild || existingName == "" {
399+
klog.Info("rebuild required, creating fresh MOSB")
415400
return b.createNewMachineOSBuildOrReuseExistingForPoolChange(ctx, curMCP)
416401
}
417-
}
418402

419-
func (b *buildReconciler) patchMOSBLabels(ctx context.Context, mosb *mcfgv1.MachineOSBuild, newMCName string) error {
420-
mosbCopy := mosb.DeepCopy()
421-
mosbCopy.Labels[constants.RenderedMachineConfigLabelKey] = newMCName
422-
_, err := b.mcfgclient.MachineconfigurationV1().MachineOSBuilds().Update(ctx, mosbCopy, metav1.UpdateOptions{})
423-
return err
403+
klog.Infof("[syncmachineconfigpool] old mc is %s", oldMCP.Spec.Configuration.Name)
404+
klog.Infof("[syncmachineconfigpool] new mc is %s", curMCP.Spec.Configuration.Name)
405+
406+
return b.createNewMOSBAndReuseImage(ctx, mosc, existingMosb, curMCP)
424407
}
425408

426409
// Adds a MachineOSBuild.
@@ -647,6 +630,7 @@ func (b *buildReconciler) getCerts() error {
647630

648631
// Determines if a preexising MachineOSBuild can be reused and if possible, does it.
649632
func (b *buildReconciler) reuseExistingMachineOSBuildIfPossible(ctx context.Context, mosc *mcfgv1.MachineOSConfig, existingMosb *mcfgv1.MachineOSBuild, mcp *mcfgv1.MachineConfigPool) error {
633+
klog.Info("[reuseExistingMachineOSBuildIfPossible]")
650634
existingMosbState := ctrlcommon.NewMachineOSBuildState(existingMosb)
651635

652636
canBeReused := false
@@ -702,10 +686,6 @@ func (b *buildReconciler) reuseExistingMachineOSBuildIfPossible(ctx context.Cont
702686
if err := b.updateMachineOSConfigStatus(ctx, mosc, existingMosb); err != nil {
703687
return fmt.Errorf("could not update MachineOSConfig %q status to reuse preexisting MachineOSBuild %q: %w", mosc.Name, existingMosb.Name, err)
704688
}
705-
706-
if err := b.patchMOSBLabels(ctx, existingMosb, mcp.Spec.Configuration.Name); err != nil {
707-
return fmt.Errorf("could not patch MOSB labels")
708-
}
709689
}
710690

711691
return imageNeedsRebuild, nil
@@ -1236,57 +1216,6 @@ func (b *buildReconciler) syncMachineOSBuild(ctx context.Context, mosb *mcfgv1.M
12361216
return nil
12371217
}
12381218

1239-
// desiredMC, err := b.machineConfigLister.Get(mcp.Spec.Configuration.Name)
1240-
// if err != nil {
1241-
// return fmt.Errorf("error getting desired MC: %w", err)
1242-
// }
1243-
1244-
// // existing MC labels
1245-
// currentWithImage := mosb.Labels[constants.RenderedMCWithImageLabel]
1246-
// currMC := mosb.Labels[constants.RenderedMachineConfigLabelKey]
1247-
1248-
// oldMC, err := b.machineConfigLister.Get(currMC)
1249-
// if err != nil {
1250-
// return fmt.Errorf("could not fetch old MachineConfig %q: %w", currMC, err)
1251-
// }
1252-
1253-
// // new MC labels
1254-
// desMC := desiredMC.Name
1255-
// newWithImage := currentWithImage
1256-
1257-
// mosbCopy := mosb.DeepCopy()
1258-
// updateLabels := false
1259-
1260-
// if currMC != desMC {
1261-
// klog.Info("Current MC does not equal the new MC, we need to update our labels to reflect that")
1262-
// mosbCopy.Labels[constants.RenderedMachineConfigLabelKey] = desMC
1263-
// updateLabels = true
1264-
// }
1265-
1266-
// if ctrlcommon.RequiresRebuild(oldMC, desiredMC) && currentWithImage != newWithImage {
1267-
// mosbCopy.Labels[constants.RenderedMCWithImageLabel] = newWithImage
1268-
// updateLabels = true
1269-
// }
1270-
1271-
// if updateLabels {
1272-
// klog.Infof("syncMachineOSBuild: Updating labels for MOSB %q (currentNoImage=%s, desiredMCName=%s, desiredWithImage=%s, currentWithImage=%s)",
1273-
// mosb.Name, currMC, desMC, newWithImage, currentWithImage)
1274-
1275-
// mosbCopy.Labels[constants.RenderedMachineConfigLabelKey] = desMC
1276-
// mosbCopy.Labels[constants.RenderedMCWithImageLabel] = newWithImage
1277-
1278-
// // Update the MOSB object
1279-
// _, err := b.mcfgclient.MachineconfigurationV1().MachineOSBuilds().Update(ctx, mosbCopy, metav1.UpdateOptions{})
1280-
// if err != nil {
1281-
// klog.Errorf("syncMachineOSBuild: Failed to update MOSB %q labels: %v", mosb.Name, err)
1282-
1283-
// return fmt.Errorf("failed to sync labels: %v", err)
1284-
// }
1285-
// klog.Infof("syncMachineOSBuild: Updated MOSB %q labels to RenderedMCNoImageLabel=%s, RenderedMCWithImageLabel=%s",
1286-
// mosb.Name, desiredMC.Name, newWithImage)
1287-
// return nil
1288-
// }
1289-
12901219
mosbState := ctrlcommon.NewMachineOSBuildState(mosb)
12911220

12921221
if mosbState.IsInTerminalState() {
@@ -1426,6 +1355,14 @@ func (b *buildReconciler) syncMachineConfigPool(ctx context.Context, mcp *mcfgv1
14261355
klog.V(4).Infof("buildReconciler: no MachineOSConfig for pool %q, skipping", mcp.Name)
14271356
return nil
14281357
}
1358+
1359+
// mosc, mosb, err := utils.GetMachineOSConfigAndMachineOSBuildForMachineConfigPool(mcp, b.utilListers())
1360+
// if err != nil {
1361+
// // Not opted in yet, so nothing for us to do.
1362+
// klog.V(4).Infof("buildReconciler: no MachineOSConfig or MachineOSBuild for pool %q, skipping", mcp.Name)
1363+
// return nil
1364+
// }
1365+
14291366
// old pool
14301367
old := mcp.DeepCopy()
14311368
old.Spec.Configuration.Name = mcp.Status.Configuration.Name
@@ -1438,34 +1375,32 @@ func (b *buildReconciler) syncMachineConfigPool(ctx context.Context, mcp *mcfgv1
14381375

14391376
existingName := mosc.Annotations[constants.CurrentMachineOSBuildAnnotationKey]
14401377
if existingName == "" {
1441-
return fmt.Errorf("no current build annotation on MachineOSConfig %q", mosc.Name)
1378+
klog.Infof("existing name is empty, creating a new MOSB")
1379+
return b.createNewMachineOSBuildOrReuseExistingForPoolChange(ctx, mcp)
14421380
}
14431381

1444-
existingMosb, err := b.machineOSBuildLister.Get(existingName)
1382+
mosb, err := b.machineOSBuildLister.Get(existingName)
14451383
if err != nil {
14461384
return fmt.Errorf("could not fetch existing MachineOSBuild %q: %w", existingName, err)
14471385
}
1448-
klog.Infof("existing MOSB is %s", existingMosb.Name)
1386+
klog.Infof("[syncmachineconfigpool] existing MOSB is %s", mosb.Name)
14491387

1450-
if !needsImageRebuild && existingMosb != nil {
1451-
if err := b.deleteMachineOSBuild(ctx, existingMosb); err != nil {
1452-
return err
1453-
}
1454-
return b.createNewMachineOSBuildOrReuseExisting(ctx, mosc, true)
1388+
if needsImageRebuild || existingName == "" {
1389+
klog.Info("rebuild required, creating fresh MOSB")
1390+
return b.createNewMachineOSBuildOrReuseExistingForPoolChange(ctx, mcp)
14551391
}
1456-
return b.createNewMachineOSBuildOrReuseExistingForPoolChange(ctx, mcp)
14571392

1393+
// if isMachineOSBuildCurrentForMachineOSConfigWithPullspec(mosc, mosb) || isMachineOSBuildCurrentForMachineOSConfig(mosc, mosb) {
1394+
// klog.Infof("[syncmachineconfigpool] MachineOSConfig %q has current build annotation and current image pullspec %q for MachineOSBuild %q", mosc.Name, mosc.Status.CurrentImagePullSpec, mosb.Name)
1395+
// return nil
1396+
// }
1397+
1398+
klog.Infof("[syncmachineconfigpool] creating new mosb and reusing image")
1399+
return b.createNewMOSBAndReuseImage(ctx, mosc, mosb, mcp)
14581400
}
14591401

14601402
// reconcilePoolChange returns (annotateRebuild bool, reuseOnly bool, err error)
14611403
func (b *buildReconciler) reconcilePoolChange(oldMCP, curMCP *mcfgv1.MachineConfigPool) (bool, error) {
1462-
1463-
// // if the old mc is the same as the new mc, no updates needed
1464-
// if oldMCP.Spec.Configuration.Name == curMCP.Spec.Configuration.Name {
1465-
// klog.Info("old mc is the same as the new mc")
1466-
// return false, true, nil
1467-
// }
1468-
14691404
curr, err := b.machineConfigLister.Get(oldMCP.Spec.Configuration.Name)
14701405
if err != nil {
14711406
return false, err
@@ -1484,3 +1419,56 @@ func (b *buildReconciler) reconcilePoolChange(oldMCP, curMCP *mcfgv1.MachineConf
14841419
klog.Info("reconciled pool change, no rebuild needed")
14851420
return false, nil
14861421
}
1422+
1423+
func (b *buildReconciler) createNewMOSBAndReuseImage(ctx context.Context,
1424+
mosc *mcfgv1.MachineOSConfig,
1425+
oldMosb *mcfgv1.MachineOSBuild,
1426+
mcp *mcfgv1.MachineConfigPool,
1427+
) error {
1428+
klog.Infof("[createNewMOSBAndReuseImage]")
1429+
// 1) new in-memory object for the NEW rendered-MC
1430+
osImageURLs, err := ctrlcommon.GetOSImageURLConfig(ctx, b.kubeclient)
1431+
if err != nil {
1432+
return err
1433+
}
1434+
mosb, err := buildrequest.NewMachineOSBuild(buildrequest.MachineOSBuildOpts{
1435+
MachineOSConfig: mosc,
1436+
MachineConfigPool: mcp,
1437+
OSImageURLConfig: osImageURLs,
1438+
})
1439+
if err != nil {
1440+
return err
1441+
}
1442+
oref := metav1.NewControllerRef(mosc, mcfgv1.SchemeGroupVersion.WithKind("MachineOSConfig"))
1443+
mosb.SetOwnerReferences([]metav1.OwnerReference{*oref})
1444+
1445+
// 2) create it if it doesn’t already exist
1446+
if _, err := b.machineOSBuildLister.Get(mosb.Name); k8serrors.IsNotFound(err) {
1447+
if mosb, err = b.mcfgclient.MachineconfigurationV1().
1448+
MachineOSBuilds().
1449+
Create(ctx, mosb, metav1.CreateOptions{}); err != nil {
1450+
return err
1451+
}
1452+
} else if err != nil {
1453+
return err
1454+
}
1455+
1456+
newMosb, err := b.getMachineOSBuildForUpdate(mosb)
1457+
if err != nil {
1458+
return err
1459+
}
1460+
1461+
// 3) copy status from oldMosb → newMosb
1462+
newMosb.Status.DigestedImagePushSpec = oldMosb.Status.DigestedImagePushSpec
1463+
newMosb.Status.Conditions = oldMosb.Status.Conditions
1464+
// 4) write back the status
1465+
if _, err := b.mcfgclient.MachineconfigurationV1().
1466+
MachineOSBuilds().
1467+
UpdateStatus(ctx, newMosb, metav1.UpdateOptions{}); err != nil {
1468+
return err
1469+
}
1470+
klog.Info("[createNewMOSBAndReuseImage]updating statuses")
1471+
1472+
// 5) update our MachineOSConfig to point at the new build
1473+
return b.updateMachineOSConfigStatus(ctx, mosc, mosb)
1474+
}

pkg/controller/node/node_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ func (ctrl *Controller) getConfigAndBuild(pool *mcfgv1.MachineConfigPool) (*mcfg
936936
return nil, nil, err
937937
}
938938

939+
// looking at the build whose .Spec.MachineConfig.Name matches the current rendered MC
939940
for _, build := range buildList.Items {
940941
build := build
941942
if build.Spec.MachineOSConfig.Name == ourConfig.Name && build.Spec.MachineConfig.Name == pool.Spec.Configuration.Name {

0 commit comments

Comments
 (0)