Skip to content

Commit 633afa0

Browse files
added tests
1 parent 621dc6c commit 633afa0

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

pkg/controller/build/osbuildcontroller_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,36 @@ func assertMachineOSConfigGetsCurrentBuildAnnotation(ctx context.Context, t *tes
756756

757757
require.NoError(t, err)
758758
}
759+
760+
// Test that when the MCP’s rendered-MC name changes but the two MCs only differ
761+
// by on-cluster layering, no new MachineOSBuild or Build Job is created.
762+
func TestOSBuildControllerSkipsBuildForLayerOnlyChanges(t *testing.T) {
763+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
764+
t.Cleanup(cancel)
765+
poolName := "worker"
766+
767+
_, mcfgclient, _, _, mosc, firstMosb, mcp, kubeassert := setupOSBuildControllerForTestWithSuccessfulBuild(ctx, t, poolName)
768+
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, mosc, 1)
769+
770+
assertMachineOSConfigGetsCurrentBuildAnnotation(ctx, t, mcfgclient, mosc, firstMosb)
771+
772+
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, mosc, 1)
773+
774+
insertNewRenderedMachineConfigAndUpdatePool(ctx, t, mcfgclient, mcp.Name, "rendered-worker-layer-only")
775+
776+
// Give the controller a moment to (not) kick off a build
777+
time.Sleep(200 * time.Millisecond)
778+
779+
mosbList, err := mcfgclient.MachineconfigurationV1().
780+
MachineOSBuilds().
781+
List(ctx, metav1.ListOptions{LabelSelector: utils.MachineOSBuildForPoolSelector(mosc).String()})
782+
require.NoError(t, err)
783+
require.Len(t, mosbList.Items, 2, "expected a new MOSB to be created for layering-only change")
784+
assert.Equal(t, firstMosb.Name, mosbList.Items[0].Name, "first MOSB should remain unchanged")
785+
786+
layerOnlyMosb := mosbList.Items[1]
787+
788+
jobName := utils.GetBuildJobName(&layerOnlyMosb)
789+
790+
kubeassert.JobDoesNotExist(jobName, "layering-only MOSB should not spawn a build Job")
791+
}

pkg/controller/build/reconciler.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,20 +1195,27 @@ func (b *buildReconciler) syncMachineOSBuild(ctx context.Context, mosb *mcfgv1.M
11951195
oldMCName := mcp.Status.Configuration.Name
11961196
newMCName := mcp.Spec.Configuration.Name
11971197

1198-
oldMC, err := b.machineConfigLister.Get(oldMCName)
1198+
oldRendered, err := b.machineConfigLister.Get(oldMCName)
11991199
if err != nil {
12001200
return err
12011201
}
1202-
newMC, err := b.machineConfigLister.Get(newMCName)
1202+
newRendered, err := b.machineConfigLister.Get(newMCName)
12031203
if err != nil {
12041204
return err
12051205
}
12061206

1207-
if !ctrlcommon.RequiresRebuild(oldMC, newMC) && oldMCName != newMCName {
1207+
old := mcp.DeepCopy()
1208+
old.Spec.Configuration.Name = mcp.Status.Configuration.Name
1209+
1210+
// decide if we annotate or reuse
1211+
needsImageRebuild, err := b.reconcileImageRebuild(old, mcp)
1212+
if err != nil {
1213+
return err
1214+
}
1215+
// need image rebuild = true -> isRebuild = false
1216+
if oldRendered != newRendered && !needsImageRebuild {
12081217
klog.Infof("[syncMachineOSBuild] MachineOSBuild %q: only layering changes → skipping builder", mosb.Name)
12091218
return nil
1210-
} else {
1211-
klog.Infof("[syncMachineOSBuild] MachineOSBuild %q: not skipping builder", mosb.Name)
12121219
}
12131220

12141221
mosbState := ctrlcommon.NewMachineOSBuildState(mosb)

pkg/daemon/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ func (dn *Daemon) triggerUpdate(currentConfig, desiredConfig *mcfgv1.MachineConf
25892589
}
25902590

25912591
// We might be able to drop this method entirely since I'm not sure if it's actually needed.
2592-
func (dn *Daemon) triggerUpdateWithMachineConfig(currentConfig, desiredConfig *mcfgv1.MachineConfig, skipCertificateWrite bool) error {
2592+
func (dn *Daemon) triggerUpdateWithMachineConfig(currentConfig, desiredConfig *mcfgv1.MachineConfig, _ bool) error {
25932593
return dn.triggerUpdate(currentConfig, desiredConfig, "", "")
25942594
}
25952595

0 commit comments

Comments
 (0)