@@ -241,6 +241,61 @@ func TestPreflightChecks(t *testing.T) {
241
241
},
242
242
providerList : & operatorv1.InfrastructureProviderList {},
243
243
},
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
+ },
244
299
{
245
300
name : "two different infra providers exist in same namespaces, preflight check passed" ,
246
301
providers : []operatorv1.GenericProvider {
@@ -509,7 +564,7 @@ func TestPreflightChecks(t *testing.T) {
509
564
providerList : & operatorv1.InfrastructureProviderList {},
510
565
},
511
566
{
512
- name : "predefined Core Provider without fetch config, preflight check passed" ,
567
+ name : "predefined core provider without fetch config, preflight check passed" ,
513
568
providers : []operatorv1.GenericProvider {
514
569
& operatorv1.CoreProvider {
515
570
ObjectMeta : metav1.ObjectMeta {
@@ -601,13 +656,13 @@ func TestPreflightChecks(t *testing.T) {
601
656
t .Run (tc .name , func (t * testing.T ) {
602
657
gs := NewWithT (t )
603
658
604
- fakeclient := fake .NewClientBuilder ().WithObjects ().Build ()
659
+ fakeClient := fake .NewClientBuilder ().WithObjects ().Build ()
605
660
606
661
for _ , c := range tc .providers {
607
- gs .Expect (fakeclient .Create (ctx , c )).To (Succeed ())
662
+ gs .Expect (fakeClient .Create (ctx , c )).To (Succeed ())
608
663
}
609
664
610
- err := preflightChecks (context .Background (), fakeclient , tc .providers [0 ], tc .providerList )
665
+ err := preflightChecks (context .Background (), fakeClient , tc .providers [0 ], tc .providerList )
611
666
if tc .expectedError {
612
667
gs .Expect (err ).To (HaveOccurred ())
613
668
} else {
@@ -700,11 +755,11 @@ func TestPreflightChecksUpgradesDowngrades(t *testing.T) {
700
755
},
701
756
}
702
757
703
- fakeclient := fake .NewClientBuilder ().WithObjects ().Build ()
758
+ fakeClient := fake .NewClientBuilder ().WithObjects ().Build ()
704
759
705
- gs .Expect (fakeclient .Create (ctx , provider )).To (Succeed ())
760
+ gs .Expect (fakeClient .Create (ctx , provider )).To (Succeed ())
706
761
707
- err := preflightChecks (context .Background (), fakeclient , provider , & operatorv1.CoreProviderList {})
762
+ err := preflightChecks (context .Background (), fakeClient , provider , & operatorv1.CoreProviderList {})
708
763
if tc .expectedError {
709
764
gs .Expect (err ).To (HaveOccurred ())
710
765
} else {
0 commit comments