Skip to content

Commit 960aafd

Browse files
committed
units: debug TestOSBuildController
1 parent 0b5bfc6 commit 960aafd

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/controller/build/osbuildcontroller_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,28 +298,38 @@ func TestOSBuildController(t *testing.T) {
298298
mosb := buildrequest.NewMachineOSBuildFromAPIOrDie(ctx, kubeclient, apiMosc, apiMCP)
299299
buildJobName := utils.GetBuildJobName(mosb)
300300
// After creating the new MachineOSConfig, a MachineOSBuild should be created.
301+
t.Logf("Debug: Checking MachineOSBuildExists for iteration %d, mosb name: %s", i, mosb.Name)
301302
kubeassert.MachineOSBuildExists(mosb, "MachineOSBuild not created for MachineOSConfig %s change, iteration %d", mosc.Name, i)
302303

304+
t.Logf("Debug: Checking assertBuildObjectsAreCreated for iteration %d", i)
303305
assertBuildObjectsAreCreated(ctx, t, kubeassert, mosb)
304306
// After a new MachineOSBuild is created, a job should be created.
307+
t.Logf("Debug: Checking JobExists for iteration %d, job name: %s", i, buildJobName)
305308
kubeassert.JobExists(buildJobName, "Build job did not get created for MachineOSConfig %s change", mosc.Name)
306309
// Set the successful status on the job.
310+
t.Logf("Debug: Setting job status to succeeded for iteration %d", i)
307311
fixtures.SetJobStatus(ctx, t, kubeclient, mosb, fixtures.JobStatus{Succeeded: 1})
308312
// The MachineOSBuild should be successful.
313+
t.Logf("Debug: Checking MachineOSBuildIsSuccessful for iteration %d", i)
309314
kubeassert.MachineOSBuildIsSuccessful(mosb, "Expected the MachineOSBuild %s status to be successful", mosb.Name)
310315
// And the build job should be deleted.
316+
t.Logf("Debug: Checking assertBuildObjectsAreDeleted for iteration %d", i)
311317
assertBuildObjectsAreDeleted(ctx, t, kubeassert, mosb)
318+
t.Logf("Debug: Checking JobDoesNotExist for iteration %d, job name: %s", i, buildJobName)
312319
kubeassert.JobDoesNotExist(buildJobName, "Expected the build job %s to be deleted", buildJobName)
313320

314321
// Ensure that the MachineOSBuild count increases with each successful build.
322+
t.Logf("Debug: Before isMachineOSBuildReachedExpectedCount for iteration %d, expected count: %d", i, i+2)
315323
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, apiMosc, i+2)
316324
}
317325

318326
// Now, we delete the MachineOSConfig and we expect that all
319327
// MachineOSBuilds that were created from it are also deleted.
328+
t.Logf("Debug: Deleting MachineOSConfig %s", mosc.Name)
320329
err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().Delete(ctx, mosc.Name, metav1.DeleteOptions{})
321330
require.NoError(t, err)
322331

332+
t.Logf("Debug: Before final isMachineOSBuildReachedExpectedCount, expected count: 0")
323333
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, mosc, 0)
324334
})
325335

@@ -337,25 +347,33 @@ func TestOSBuildController(t *testing.T) {
337347
mosb := buildrequest.NewMachineOSBuildFromAPIOrDie(ctx, kubeclient, apiMosc, apiMCP)
338348
buildJobName := utils.GetBuildJobName(mosb)
339349
// After updating the MachineConfigPool, a new MachineOSBuild should get created.
350+
t.Logf("Debug: Checking MachineOSBuildExists for iteration %d, mosb name: %s", i, mosb.Name)
340351
kubeassert.MachineOSBuildExists(mosb, "New MachineOSBuild for MachineConfigPool %q update for MachineOSConfig %q never gets created", mcp.Name, mosc.Name)
341352
// After a new MachineOSBuild is created, a job should be created.
353+
t.Logf("Debug: Checking JobExists for iteration %d, job name: %s", i, buildJobName)
342354
kubeassert.JobExists(buildJobName, "Build job did not get created for MachineConfigPool %q change", mcp.Name)
343355
// Set the successful status on the job.
356+
t.Logf("Debug: Setting job status to succeeded for iteration %d", i)
344357
fixtures.SetJobStatus(ctx, t, kubeclient, mosb, fixtures.JobStatus{Succeeded: 1})
345358
// The MachineOSBuild should be successful.
359+
t.Logf("Debug: Checking MachineOSBuildIsSuccessful for iteration %d", i)
346360
kubeassert.MachineOSBuildIsSuccessful(mosb, "Expected the MachineOSBuild %s status to be successful", mosb.Name)
347361
// And the build job should be deleted.
362+
t.Logf("Debug: Checking JobDoesNotExist for iteration %d, job name: %s", i, buildJobName)
348363
kubeassert.JobDoesNotExist(buildJobName, "Expected the build job %s to be deleted", buildJobName)
349364

350365
// Ensure that the MachineOSBuild count increases with each successful build.
366+
t.Logf("Debug: Before isMachineOSBuildReachedExpectedCount for iteration %d, expected count: %d", i, i+2)
351367
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, apiMosc, i+2)
352368
}
353369

354370
// Now, we delete the MachineOSConfig and we expect that all
355371
// MachineOSBuilds that were created from it are also deleted.
372+
t.Logf("Debug: Deleting MachineOSConfig %s", mosc.Name)
356373
err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().Delete(ctx, mosc.Name, metav1.DeleteOptions{})
357374
require.NoError(t, err)
358375

376+
t.Logf("Debug: Before final isMachineOSBuildReachedExpectedCount, expected count: 0")
359377
isMachineOSBuildReachedExpectedCount(ctx, t, mcfgclient, mosc, 0)
360378
})
361379
}
@@ -774,7 +792,7 @@ func insertNewRenderedMachineConfigWithoutImageChange(ctx context.Context, t *te
774792
func isMachineOSBuildReachedExpectedCount(ctx context.Context, t *testing.T, mcfgclient mcfgclientset.Interface, mosc *mcfgv1.MachineOSConfig, expected int) {
775793
t.Helper()
776794

777-
err := wait.PollImmediateInfiniteWithContext(ctx, time.Millisecond, func(ctx context.Context) (bool, error) {
795+
err := wait.PollUntilContextCancel(ctx, time.Millisecond, true, func(ctx context.Context) (bool, error) {
778796
mosbList, err := mcfgclient.MachineconfigurationV1().MachineOSBuilds().List(ctx, metav1.ListOptions{
779797
LabelSelector: utils.MachineOSBuildForPoolSelector(mosc).String(),
780798
})
@@ -793,7 +811,7 @@ func assertMachineOSConfigGetsBuiltImagePushspec(ctx context.Context, t *testing
793811

794812
var foundMosc *mcfgv1.MachineOSConfig
795813

796-
err := wait.PollImmediateInfiniteWithContext(ctx, time.Millisecond, func(ctx context.Context) (bool, error) {
814+
err := wait.PollUntilContextCancel(ctx, time.Millisecond, true, func(ctx context.Context) (bool, error) {
797815
apiMosc, err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().Get(ctx, mosc.Name, metav1.GetOptions{})
798816
if err != nil {
799817
return false, err
@@ -811,7 +829,7 @@ func assertMachineOSConfigGetsBuiltImagePushspec(ctx context.Context, t *testing
811829
func assertMachineOSConfigGetsCurrentBuildAnnotation(ctx context.Context, t *testing.T, mcfgclient mcfgclientset.Interface, mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) {
812830
t.Helper()
813831

814-
err := wait.PollImmediateInfiniteWithContext(ctx, time.Millisecond, func(ctx context.Context) (bool, error) {
832+
err := wait.PollUntilContextCancel(ctx, time.Millisecond, true, func(ctx context.Context) (bool, error) {
815833
apiMosc, err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().Get(ctx, mosc.Name, metav1.GetOptions{})
816834
if err != nil {
817835
return false, err

0 commit comments

Comments
 (0)