@@ -31,6 +31,7 @@ import (
3131 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3232 clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3333 "sigs.k8s.io/cluster-api/util/conditions"
34+ "sigs.k8s.io/cluster-api/util/patch"
3435 "sigs.k8s.io/controller-runtime/pkg/client"
3536
3637 operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
@@ -200,7 +201,7 @@ func TestConfigSecretChangesAreAppliedToTheDeployment(t *testing.T) {
200201
201202 g .Eventually (
202203 testDeploymentLabelValueGetter (ns .Name , testDeploymentName ),
203- 30 * time . Second ,
204+ timeout ,
204205 ).Should (BeEquivalentTo ("initial-value" ))
205206
206207 t .Log ("Provider deployment deployed" )
@@ -213,7 +214,7 @@ func TestConfigSecretChangesAreAppliedToTheDeployment(t *testing.T) {
213214
214215 g .Eventually (
215216 testDeploymentLabelValueGetter (ns .Name , testDeploymentName ),
216- 30 * time . Second ,
217+ timeout ,
217218 ).Should (BeEquivalentTo ("updated-value" ))
218219}
219220
@@ -293,6 +294,17 @@ func TestReconcilerPreflightConditions(t *testing.T) {
293294 g .Expect (env .CreateAndWait (ctx , p )).To (Succeed ())
294295 }
295296
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+
296308 g .Eventually (func () bool {
297309 for _ , p := range tc .providers {
298310 if err := env .Get (ctx , client .ObjectKeyFromObject (p ), p ); err != nil {
@@ -306,20 +318,6 @@ func TestReconcilerPreflightConditions(t *testing.T) {
306318
307319 return false
308320 }, 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 ())
323321 })
324322 }
325323}
@@ -395,6 +393,11 @@ releaseSeries:
395393 t .Log ("creating test provider" , provider .GetName ())
396394 g .Expect (env .CreateAndWait (ctx , provider )).To (Succeed ())
397395
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+
398401 g .Eventually (func () bool {
399402 if err := env .Get (ctx , client .ObjectKeyFromObject (provider ), provider ); err != nil {
400403 return false
@@ -509,24 +512,6 @@ releaseSeries:
509512
510513 return allSet
511514 }, 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 ())
530515 })
531516 }
532517}
@@ -573,9 +558,7 @@ func TestProviderShouldNotBeInstalledWhenCoreProviderNotReady(t *testing.T) {
573558 return false
574559 }
575560
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 )
579562 }, timeout ).Should (BeEquivalentTo (true ))
580563
581564 g .Consistently (func () bool {
@@ -589,6 +572,88 @@ func TestProviderShouldNotBeInstalledWhenCoreProviderNotReady(t *testing.T) {
589572 }, timeout / 3 ).Should (BeEquivalentTo (true ))
590573}
591574
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+
592657func TestProviderConfigSecretChanges (t * testing.T ) {
593658 testCases := []struct {
594659 name string
@@ -859,6 +924,11 @@ func TestProviderSpecChanges(t *testing.T) {
859924 t .Log ("creating test provider" , provider .GetName ())
860925 g .Expect (env .CreateAndWait (ctx , provider .DeepCopy ())).To (Succeed ())
861926
927+ defer func () {
928+ // Clean up
929+ g .Expect (env .Cleanup (ctx , provider , dummyConfigMap (namespace ))).To (Succeed ())
930+ }()
931+
862932 g .Eventually (generateExpectedResultChecker (provider , specHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
863933
864934 g .Eventually (func () error {
@@ -886,9 +956,6 @@ func TestProviderSpecChanges(t *testing.T) {
886956 } else {
887957 g .Eventually (generateExpectedResultChecker (provider , "" , corev1 .ConditionFalse ), timeout ).Should (BeEquivalentTo (true ))
888958 }
889-
890- // Clean up
891- g .Expect (env .Cleanup (ctx , provider , ns )).To (Succeed ())
892959 })
893960 }
894961}
0 commit comments