@@ -41,7 +41,7 @@ func TestOSBuildControllerDoesNothing(t *testing.T) {
41
41
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
42
42
t .Cleanup (cancel )
43
43
44
- _ , mcfgclient , _ , _ := setupOSBuildControllerForTest (ctx , t )
44
+ _ , mcfgclient , _ , _ , _ := setupOSBuildControllerForTest (ctx , t )
45
45
46
46
// i needs to be set to 2 because rendered-worker-1 already exists.
47
47
for i := 2 ; i <= 10 ; i ++ {
@@ -67,7 +67,7 @@ func TestOSBuildControllerDeletesRunningBuildBeforeStartingANewOne(t *testing.T)
67
67
t .Run ("MachineOSConfig change" , func (t * testing.T ) {
68
68
t .Parallel ()
69
69
70
- kubeclient , mcfgclient , mosc , initialMosb , mcp , kubeassert := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
70
+ kubeclient , mcfgclient , mosc , initialMosb , mcp , kubeassert , _ := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
71
71
72
72
// Now that the build is in the running state, we update the MachineOSConfig.
73
73
apiMosc := testhelpers .SetContainerfileContentsOnMachineOSConfig (ctx , t , mcfgclient , mosc , "FROM configs AS final\n RUN echo 'helloworld' > /etc/helloworld" )
@@ -99,7 +99,7 @@ func TestOSBuildControllerDeletesRunningBuildBeforeStartingANewOne(t *testing.T)
99
99
t .Run ("MachineConfig change" , func (t * testing.T ) {
100
100
t .Parallel ()
101
101
102
- kubeclient , mcfgclient , mosc , initialMosb , mcp , kubeassert := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
102
+ kubeclient , mcfgclient , mosc , initialMosb , mcp , kubeassert , _ := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
103
103
104
104
apiMCP := insertNewRenderedMachineConfigAndUpdatePool (ctx , t , mcfgclient , mosc .Spec .MachineConfigPool .Name , "rendered-worker-2" )
105
105
@@ -461,6 +461,77 @@ func TestOSBuildControllerRebuildAnnotation(t *testing.T) {
461
461
462
462
}
463
463
464
+ func TestOSBuildControllerBuildFailedDoesNotCascade (t * testing.T ) {
465
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
466
+ t .Cleanup (cancel )
467
+
468
+ poolName := "worker"
469
+ faultyMC := "rendered-undesiredFaultyMC"
470
+
471
+ // Create a MOSC to enable OCL and let it produce a new MOSB in Running State
472
+ _ , mcfgclient , mosc , mosb , mcp , _ , ctrl := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
473
+ assertMachineOSConfigGetsCurrentBuildAnnotation (ctx , t , mcfgclient , mosc , mosb )
474
+
475
+ found := func (item * mcfgv1alpha1.MachineOSBuild , list []mcfgv1alpha1.MachineOSBuild ) bool {
476
+ for _ , m := range list {
477
+ if m .Name == item .Name {
478
+ return true
479
+ }
480
+ }
481
+ return false
482
+ }
483
+
484
+ mosbList , err := mcfgclient .MachineconfigurationV1alpha1 ().MachineOSBuilds ().List (ctx , metav1.ListOptions {})
485
+ require .NoError (t , err )
486
+ if ! found (mosb , mosbList .Items ) {
487
+ t .Errorf ("Expected %v to be in the list %v" , mosb .Name , mosbList .Items )
488
+ }
489
+
490
+ // This faultyMC represents an older Machine config that passed through API validation checks but if a MOSB (name oldMOSB) were to be built, it would fail to start a job. Hence over here a MC is added but the MCP is not targetting this MCP.
491
+ insertNewRenderedMachineConfig (ctx , t , mcfgclient , poolName , faultyMC )
492
+ now := metav1 .Now ()
493
+ oldMosb := & mcfgv1alpha1.MachineOSBuild {
494
+ TypeMeta : metav1.TypeMeta {
495
+ Kind : "MachineOSBuild" ,
496
+ APIVersion : "machineconfiguration.openshift.io/v1alpha1" ,
497
+ },
498
+ ObjectMeta : metav1.ObjectMeta {
499
+ Name : "undesiredAndForgottenMOSB" ,
500
+ Labels : map [string ]string {
501
+ constants .TargetMachineConfigPoolLabelKey : mcp .Name ,
502
+ constants .RenderedMachineConfigLabelKey : faultyMC ,
503
+ constants .MachineOSConfigNameLabelKey : mosc .Name ,
504
+ },
505
+ },
506
+ Spec : mcfgv1alpha1.MachineOSBuildSpec {
507
+ RenderedImagePushspec : "randRef" ,
508
+ Version : 1 ,
509
+ ConfigGeneration : 1 ,
510
+ DesiredConfig : mcfgv1alpha1.RenderedMachineConfigReference {
511
+ Name : faultyMC ,
512
+ },
513
+ MachineOSConfig : mcfgv1alpha1.MachineOSConfigReference {
514
+ Name : mosc .Name ,
515
+ },
516
+ },
517
+ Status : mcfgv1alpha1.MachineOSBuildStatus {
518
+ BuildStart : & now ,
519
+ },
520
+ }
521
+
522
+ // Enqueue another old and un-targeted MOSB to the osbuildcontroller
523
+ _ , err = mcfgclient .MachineconfigurationV1alpha1 ().MachineOSBuilds ().Create (ctx , oldMosb , metav1.CreateOptions {})
524
+ require .NoError (t , err )
525
+ ctrl .buildReconciler .AddMachineOSBuild (ctx , oldMosb )
526
+
527
+ // Assert that the original MOSB which is derived from the current rendered MC that the MCP targets is still building and untouched
528
+ mosbList , err = mcfgclient .MachineconfigurationV1alpha1 ().MachineOSBuilds ().List (ctx , metav1.ListOptions {})
529
+ require .NoError (t , err )
530
+ if ! found (mosb , mosbList .Items ) {
531
+ t .Errorf ("Expected %v to be in the list %v" , mosb .Name , mosbList .Items )
532
+ }
533
+ }
534
+
464
535
func assertBuildObjectsAreCreated (ctx context.Context , t * testing.T , kubeassert * testhelpers.Assertions , mosb * mcfgv1alpha1.MachineOSBuild ) {
465
536
t .Helper ()
466
537
@@ -481,7 +552,7 @@ func assertBuildObjectsAreDeleted(ctx context.Context, t *testing.T, kubeassert
481
552
kubeassert .SecretDoesNotExist (utils .GetFinalPushSecretName (mosb ))
482
553
}
483
554
484
- func setupOSBuildControllerForTest (ctx context.Context , t * testing.T ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * testhelpers.Assertions , * fixtures.ObjectsForTest ) {
555
+ func setupOSBuildControllerForTest (ctx context.Context , t * testing.T ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * testhelpers.Assertions , * fixtures.ObjectsForTest , * OSBuildController ) {
485
556
kubeclient , mcfgclient , lobj , kubeassert := fixtures .GetClientsForTest (t )
486
557
487
558
cfg := Config {
@@ -498,11 +569,11 @@ func setupOSBuildControllerForTest(ctx context.Context, t *testing.T) (*fakecore
498
569
499
570
kubeassert = kubeassert .Eventually ().WithContext (ctx ).WithPollInterval (time .Millisecond )
500
571
501
- return kubeclient , mcfgclient , kubeassert , lobj
572
+ return kubeclient , mcfgclient , kubeassert , lobj , ctrl
502
573
}
503
574
504
- func setupOSBuildControllerForTestWithBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions ) {
505
- kubeclient , mcfgclient , kubeassert , lobj := setupOSBuildControllerForTest (ctx , t )
575
+ func setupOSBuildControllerForTestWithBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions , * OSBuildController ) {
576
+ kubeclient , mcfgclient , kubeassert , lobj , ctrl := setupOSBuildControllerForTest (ctx , t )
506
577
507
578
mcp := lobj .MachineConfigPool
508
579
mosc := lobj .MachineOSConfig
@@ -513,13 +584,13 @@ func setupOSBuildControllerForTestWithBuild(ctx context.Context, t *testing.T, p
513
584
514
585
mosb := buildrequest .NewMachineOSBuildFromAPIOrDie (ctx , kubeclient , mosc , mcp )
515
586
516
- return kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert .WithPollInterval (time .Millisecond * 10 ).WithContext (ctx ).Eventually ()
587
+ return kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert .WithPollInterval (time .Millisecond * 10 ).WithContext (ctx ).Eventually (), ctrl
517
588
}
518
589
519
- func setupOSBuildControllerForTestWithRunningBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions ) {
590
+ func setupOSBuildControllerForTestWithRunningBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions , * OSBuildController ) {
520
591
t .Helper ()
521
592
522
- kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert := setupOSBuildControllerForTestWithBuild (ctx , t , poolName )
593
+ kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert , ctrl := setupOSBuildControllerForTestWithBuild (ctx , t , poolName )
523
594
524
595
initialBuildJobName := utils .GetBuildJobName (mosb )
525
596
@@ -535,13 +606,13 @@ func setupOSBuildControllerForTestWithRunningBuild(ctx context.Context, t *testi
535
606
// The MachineOSBuild should be running.
536
607
kubeassert .Eventually ().WithContext (ctx ).MachineOSBuildIsRunning (mosb , "Expected the MachineOSBuild %s status to be running" , mosb .Name )
537
608
538
- return kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert
609
+ return kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert , ctrl
539
610
}
540
611
541
612
func setupOSBuildControllerForTestWithSuccessfulBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions ) {
542
613
t .Helper ()
543
614
544
- kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
615
+ kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert , _ := setupOSBuildControllerForTestWithRunningBuild (ctx , t , poolName )
545
616
546
617
kubeassert .MachineOSBuildExists (mosb )
547
618
kubeassert .JobExists (utils .GetBuildJobName (mosb ))
@@ -555,7 +626,7 @@ func setupOSBuildControllerForTestWithSuccessfulBuild(ctx context.Context, t *te
555
626
func setupOSBuildControllerForTestWithFailedBuild (ctx context.Context , t * testing.T , poolName string ) (* fakecorev1client.Clientset , * fakeclientmachineconfigv1.Clientset , * mcfgv1alpha1.MachineOSConfig , * mcfgv1alpha1.MachineOSBuild , * mcfgv1.MachineConfigPool , * testhelpers.Assertions ) {
556
627
t .Helper ()
557
628
558
- kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert := setupOSBuildControllerForTestWithBuild (ctx , t , poolName )
629
+ kubeclient , mcfgclient , mosc , mosb , mcp , kubeassert , _ := setupOSBuildControllerForTestWithBuild (ctx , t , poolName )
559
630
560
631
initialBuildJobName := utils .GetBuildJobName (mosb )
561
632
0 commit comments