@@ -31,6 +31,7 @@ import (
31
31
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
32
32
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
33
33
"sigs.k8s.io/cluster-api/util/conditions"
34
+ "sigs.k8s.io/cluster-api/util/patch"
34
35
"sigs.k8s.io/controller-runtime/pkg/client"
35
36
36
37
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
@@ -200,7 +201,7 @@ func TestConfigSecretChangesAreAppliedToTheDeployment(t *testing.T) {
200
201
201
202
g .Eventually (
202
203
testDeploymentLabelValueGetter (ns .Name , testDeploymentName ),
203
- 30 * time . Second ,
204
+ timeout ,
204
205
).Should (BeEquivalentTo ("initial-value" ))
205
206
206
207
t .Log ("Provider deployment deployed" )
@@ -213,7 +214,7 @@ func TestConfigSecretChangesAreAppliedToTheDeployment(t *testing.T) {
213
214
214
215
g .Eventually (
215
216
testDeploymentLabelValueGetter (ns .Name , testDeploymentName ),
216
- 30 * time . Second ,
217
+ timeout ,
217
218
).Should (BeEquivalentTo ("updated-value" ))
218
219
}
219
220
@@ -293,6 +294,17 @@ func TestReconcilerPreflightConditions(t *testing.T) {
293
294
g .Expect (env .CreateAndWait (ctx , p )).To (Succeed ())
294
295
}
295
296
297
+ defer func () {
298
+ objs := []client.Object {
299
+ dummyConfigMap (tc .namespace ),
300
+ }
301
+ for _ , p := range tc .providers {
302
+ objs = append (objs , p )
303
+ }
304
+
305
+ g .Expect (env .CleanupAndWait (ctx , objs ... )).To (Succeed ())
306
+ }()
307
+
296
308
g .Eventually (func () bool {
297
309
for _ , p := range tc .providers {
298
310
if err := env .Get (ctx , client .ObjectKeyFromObject (p ), p ); err != nil {
@@ -306,20 +318,6 @@ func TestReconcilerPreflightConditions(t *testing.T) {
306
318
307
319
return false
308
320
}, timeout ).Should (BeEquivalentTo (true ))
309
-
310
- objs := []client.Object {}
311
- for _ , p := range tc .providers {
312
- objs = append (objs , p )
313
- }
314
-
315
- objs = append (objs , & corev1.ConfigMap {
316
- ObjectMeta : metav1.ObjectMeta {
317
- Name : testCurrentVersion ,
318
- Namespace : tc .namespace ,
319
- },
320
- })
321
-
322
- g .Expect (env .CleanupAndWait (ctx , objs ... )).To (Succeed ())
323
321
})
324
322
}
325
323
}
@@ -395,6 +393,11 @@ releaseSeries:
395
393
t .Log ("creating test provider" , provider .GetName ())
396
394
g .Expect (env .CreateAndWait (ctx , provider )).To (Succeed ())
397
395
396
+ defer func () {
397
+ // Clean up
398
+ g .Expect (env .CleanupAndWait (ctx , []client.Object {provider , dummyFutureConfigMap (namespace , currentVersion ), dummyFutureConfigMap (namespace , tc .newVersion )}... )).To (Succeed ())
399
+ }()
400
+
398
401
g .Eventually (func () bool {
399
402
if err := env .Get (ctx , client .ObjectKeyFromObject (provider ), provider ); err != nil {
400
403
return false
@@ -509,24 +512,6 @@ releaseSeries:
509
512
510
513
return allSet
511
514
}, 2 * time .Second ).Should (BeTrue ())
512
-
513
- // Clean up
514
- objs := []client.Object {provider }
515
- objs = append (objs , & corev1.ConfigMap {
516
- ObjectMeta : metav1.ObjectMeta {
517
- Name : currentVersion ,
518
- Namespace : namespace ,
519
- },
520
- })
521
-
522
- objs = append (objs , & corev1.ConfigMap {
523
- ObjectMeta : metav1.ObjectMeta {
524
- Name : tc .newVersion ,
525
- Namespace : namespace ,
526
- },
527
- })
528
-
529
- g .Expect (env .CleanupAndWait (ctx , objs ... )).To (Succeed ())
530
515
})
531
516
}
532
517
}
@@ -573,9 +558,7 @@ func TestProviderShouldNotBeInstalledWhenCoreProviderNotReady(t *testing.T) {
573
558
return false
574
559
}
575
560
576
- providerInstalled := conditions .Get (coreProvider , operatorv1 .ProviderInstalledCondition )
577
-
578
- return providerInstalled != nil && providerInstalled .Status == corev1 .ConditionFalse
561
+ return conditions .Has (coreProvider , operatorv1 .ProviderInstalledCondition ) && conditions .IsFalse (coreProvider , operatorv1 .ProviderInstalledCondition )
579
562
}, timeout ).Should (BeEquivalentTo (true ))
580
563
581
564
g .Consistently (func () bool {
@@ -589,6 +572,88 @@ func TestProviderShouldNotBeInstalledWhenCoreProviderNotReady(t *testing.T) {
589
572
}, timeout / 3 ).Should (BeEquivalentTo (true ))
590
573
}
591
574
575
+ func TestReconcilerPreflightConditionsFromCoreProviderEvents (t * testing.T ) {
576
+ namespace := "test-core-provider-events"
577
+ coreProvider := & operatorv1.CoreProvider {
578
+ ObjectMeta : metav1.ObjectMeta {
579
+ Name : "cluster-api" ,
580
+ },
581
+ Spec : operatorv1.CoreProviderSpec {
582
+ ProviderSpec : operatorv1.ProviderSpec {
583
+ Version : testCurrentVersion ,
584
+ },
585
+ },
586
+ }
587
+ infrastructureProvider := & operatorv1.InfrastructureProvider {
588
+ ObjectMeta : metav1.ObjectMeta {
589
+ Name : "vsphere" ,
590
+ },
591
+ Spec : operatorv1.InfrastructureProviderSpec {
592
+ ProviderSpec : operatorv1.ProviderSpec {
593
+ Version : testCurrentVersion ,
594
+ },
595
+ },
596
+ }
597
+
598
+ g := NewWithT (t )
599
+ t .Log ("Ensure namespace exists" , namespace )
600
+ g .Expect (env .EnsureNamespaceExists (ctx , namespace )).To (Succeed ())
601
+
602
+ g .Expect (env .CreateAndWait (ctx , dummyConfigMap (namespace ))).To (Succeed ())
603
+
604
+ for _ , p := range []genericprovider.GenericProvider {coreProvider , infrastructureProvider } {
605
+ insertDummyConfig (p )
606
+ p .SetNamespace (namespace )
607
+ t .Log ("creating test provider" , p .GetName ())
608
+ g .Expect (env .CreateAndWait (ctx , p )).To (Succeed ())
609
+ }
610
+
611
+ defer func () {
612
+ g .Expect (env .CleanupAndWait (ctx , []client.Object {coreProvider , infrastructureProvider , dummyConfigMap (namespace )}... )).To (Succeed ())
613
+ }()
614
+
615
+ g .Eventually (func () bool {
616
+ if err := env .Get (ctx , client .ObjectKeyFromObject (infrastructureProvider ), infrastructureProvider ); err != nil {
617
+ return false
618
+ }
619
+
620
+ if conditions .Has (infrastructureProvider , operatorv1 .PreflightCheckCondition ) && conditions .IsFalse (infrastructureProvider , operatorv1 .PreflightCheckCondition ) {
621
+ return true
622
+ }
623
+
624
+ return false
625
+ }, timeout ).Should (BeEquivalentTo (true ))
626
+
627
+ g .Eventually (func () bool {
628
+ if err := env .Get (ctx , client .ObjectKeyFromObject (coreProvider ), coreProvider ); err != nil {
629
+ return false
630
+ }
631
+
632
+ if conditions .IsTrue (coreProvider , operatorv1 .PreflightCheckCondition ) && conditions .IsTrue (coreProvider , operatorv1 .ProviderInstalledCondition ) {
633
+ return true
634
+ }
635
+
636
+ return false
637
+ }, timeout ).Should (BeEquivalentTo (true ))
638
+
639
+ patchHelper , err := patch .NewHelper (coreProvider , env )
640
+ g .Expect (err ).ToNot (HaveOccurred ())
641
+ conditions .MarkTrue (coreProvider , clusterv1 .ReadyCondition )
642
+ g .Expect (patchHelper .Patch (ctx , coreProvider )).To (Succeed ())
643
+
644
+ g .Eventually (func () bool {
645
+ if err := env .Get (ctx , client .ObjectKeyFromObject (infrastructureProvider ), infrastructureProvider ); err != nil {
646
+ return false
647
+ }
648
+
649
+ if conditions .IsTrue (infrastructureProvider , operatorv1 .PreflightCheckCondition ) {
650
+ return true
651
+ }
652
+
653
+ return false
654
+ }, timeout ).Should (BeEquivalentTo (true ))
655
+ }
656
+
592
657
func TestProviderConfigSecretChanges (t * testing.T ) {
593
658
testCases := []struct {
594
659
name string
@@ -859,6 +924,11 @@ func TestProviderSpecChanges(t *testing.T) {
859
924
t .Log ("creating test provider" , provider .GetName ())
860
925
g .Expect (env .CreateAndWait (ctx , provider .DeepCopy ())).To (Succeed ())
861
926
927
+ defer func () {
928
+ // Clean up
929
+ g .Expect (env .Cleanup (ctx , provider , dummyConfigMap (namespace ))).To (Succeed ())
930
+ }()
931
+
862
932
g .Eventually (generateExpectedResultChecker (provider , specHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
863
933
864
934
g .Eventually (func () error {
@@ -886,9 +956,6 @@ func TestProviderSpecChanges(t *testing.T) {
886
956
} else {
887
957
g .Eventually (generateExpectedResultChecker (provider , "" , corev1 .ConditionFalse ), timeout ).Should (BeEquivalentTo (true ))
888
958
}
889
-
890
- // Clean up
891
- g .Expect (env .Cleanup (ctx , provider , ns )).To (Succeed ())
892
959
})
893
960
}
894
961
}
0 commit comments