@@ -241,6 +241,61 @@ func TestPreflightChecks(t *testing.T) {
241241 },
242242 providerList : & operatorv1.InfrastructureProviderList {},
243243 },
244+ {
245+ name : "only one infra provider exists but core provider is not ready, preflight check failed" ,
246+ expectedError : true ,
247+ providers : []operatorv1.GenericProvider {
248+ & operatorv1.InfrastructureProvider {
249+ ObjectMeta : metav1.ObjectMeta {
250+ Name : "aws" ,
251+ Namespace : namespaceName1 ,
252+ },
253+ TypeMeta : metav1.TypeMeta {
254+ Kind : "InfrastructureProvider" ,
255+ APIVersion : "operator.cluster.x-k8s.io/v1alpha1" ,
256+ },
257+ Spec : operatorv1.InfrastructureProviderSpec {
258+ ProviderSpec : operatorv1.ProviderSpec {
259+ Version : "v1.0.0" ,
260+ },
261+ },
262+ },
263+ & operatorv1.CoreProvider {
264+ ObjectMeta : metav1.ObjectMeta {
265+ Name : "cluster-api" ,
266+ Namespace : namespaceName2 ,
267+ },
268+ TypeMeta : metav1.TypeMeta {
269+ Kind : "CoreProvider" ,
270+ APIVersion : "operator.cluster.x-k8s.io/v1alpha4" ,
271+ },
272+ Spec : operatorv1.CoreProviderSpec {
273+ ProviderSpec : operatorv1.ProviderSpec {
274+ Version : "v1.0.0" ,
275+ },
276+ },
277+ Status : operatorv1.CoreProviderStatus {
278+ ProviderStatus : operatorv1.ProviderStatus {
279+ Conditions : []clusterv1.Condition {
280+ {
281+ Type : clusterv1 .ReadyCondition ,
282+ Status : corev1 .ConditionFalse ,
283+ LastTransitionTime : metav1 .Now (),
284+ },
285+ },
286+ },
287+ },
288+ },
289+ },
290+ expectedCondition : clusterv1.Condition {
291+ Type : operatorv1 .PreflightCheckCondition ,
292+ Status : corev1 .ConditionFalse ,
293+ Reason : operatorv1 .WaitingForCoreProviderReadyReason ,
294+ Severity : clusterv1 .ConditionSeverityInfo ,
295+ Message : "Waiting for the CoreProvider to be installed." ,
296+ },
297+ providerList : & operatorv1.InfrastructureProviderList {},
298+ },
244299 {
245300 name : "two different infra providers exist in same namespaces, preflight check passed" ,
246301 providers : []operatorv1.GenericProvider {
@@ -509,7 +564,7 @@ func TestPreflightChecks(t *testing.T) {
509564 providerList : & operatorv1.InfrastructureProviderList {},
510565 },
511566 {
512- name : "predefined Core Provider without fetch config, preflight check passed" ,
567+ name : "predefined core provider without fetch config, preflight check passed" ,
513568 providers : []operatorv1.GenericProvider {
514569 & operatorv1.CoreProvider {
515570 ObjectMeta : metav1.ObjectMeta {
@@ -601,13 +656,13 @@ func TestPreflightChecks(t *testing.T) {
601656 t .Run (tc .name , func (t * testing.T ) {
602657 gs := NewWithT (t )
603658
604- fakeclient := fake .NewClientBuilder ().WithObjects ().Build ()
659+ fakeClient := fake .NewClientBuilder ().WithObjects ().Build ()
605660
606661 for _ , c := range tc .providers {
607- gs .Expect (fakeclient .Create (ctx , c )).To (Succeed ())
662+ gs .Expect (fakeClient .Create (ctx , c )).To (Succeed ())
608663 }
609664
610- err := preflightChecks (context .Background (), fakeclient , tc .providers [0 ], tc .providerList )
665+ err := preflightChecks (context .Background (), fakeClient , tc .providers [0 ], tc .providerList )
611666 if tc .expectedError {
612667 gs .Expect (err ).To (HaveOccurred ())
613668 } else {
@@ -700,11 +755,11 @@ func TestPreflightChecksUpgradesDowngrades(t *testing.T) {
700755 },
701756 }
702757
703- fakeclient := fake .NewClientBuilder ().WithObjects ().Build ()
758+ fakeClient := fake .NewClientBuilder ().WithObjects ().Build ()
704759
705- gs .Expect (fakeclient .Create (ctx , provider )).To (Succeed ())
760+ gs .Expect (fakeClient .Create (ctx , provider )).To (Succeed ())
706761
707- err := preflightChecks (context .Background (), fakeclient , provider , & operatorv1.CoreProviderList {})
762+ err := preflightChecks (context .Background (), fakeClient , provider , & operatorv1.CoreProviderList {})
708763 if tc .expectedError {
709764 gs .Expect (err ).To (HaveOccurred ())
710765 } else {
0 commit comments