@@ -36,7 +36,8 @@ import (
36
36
37
37
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
38
38
"sigs.k8s.io/cluster-api/util"
39
- v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions" //nolint:staticcheck
39
+ v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions" //nolint:staticcheck
40
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2" //nolint:staticcheck
40
41
41
42
infrav1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
42
43
"sigs.k8s.io/cluster-api-provider-ibmcloud/cloud/scope"
@@ -89,12 +90,12 @@ func TestIBMPowerVSImageReconciler_Reconcile(t *testing.T) {
89
90
90
91
if tc .powervsImage != nil {
91
92
g .Eventually (func () bool {
92
- machine := & infrav1.IBMPowerVSImage {}
93
+ image := & infrav1.IBMPowerVSImage {}
93
94
key := client.ObjectKey {
94
95
Name : tc .powervsImage .Name ,
95
96
Namespace : ns .Name ,
96
97
}
97
- err = testEnv .Get (ctx , key , machine )
98
+ err = testEnv .Get (ctx , key , image )
98
99
return err == nil
99
100
}, 10 * time .Second ).Should (Equal (true ))
100
101
@@ -413,3 +414,94 @@ func expectConditionsImage(g *WithT, m *infrav1.IBMPowerVSImage, expected []cond
413
414
g .Expect (actual .Reason ).To (Equal (c .reason ))
414
415
}
415
416
}
417
+
418
+ func TestIBMPowerVSImageReconciler_Reconcile_Conditions (t * testing.T ) {
419
+ testCases := []struct {
420
+ name string
421
+ powervsCluster * infrav1.IBMPowerVSCluster
422
+ powervsImage * infrav1.IBMPowerVSImage
423
+ expectError bool
424
+ }{
425
+
426
+ {
427
+ name : "Conditions should be set after reconcile" ,
428
+ powervsCluster : & infrav1.IBMPowerVSCluster {
429
+ ObjectMeta : metav1.ObjectMeta {
430
+ Name : "capi-powervs-cluster" },
431
+ },
432
+ powervsImage : & infrav1.IBMPowerVSImage {
433
+ ObjectMeta : metav1.ObjectMeta {
434
+ Name : "capi-image" ,
435
+ Finalizers : []string {infrav1 .IBMPowerVSImageFinalizer },
436
+ },
437
+ Spec : infrav1.IBMPowerVSImageSpec {
438
+ ClusterName : "capi-powervs-cluster" ,
439
+ Object : ptr .To ("capi-image.ova.gz" ),
440
+ Region : ptr .To ("us-south" ),
441
+ Bucket : ptr .To ("capi-bucket" ),
442
+ },
443
+ },
444
+ expectError : true ,
445
+ },
446
+ }
447
+
448
+ for _ , tc := range testCases {
449
+ t .Run (tc .name , func (t * testing.T ) {
450
+ g := NewWithT (t )
451
+ reconciler := & IBMPowerVSImageReconciler {
452
+ Client : testEnv .Client ,
453
+ }
454
+
455
+ ns , err := testEnv .CreateNamespace (ctx , fmt .Sprintf ("namespace-%s" , util .RandomString (5 )))
456
+ g .Expect (err ).To (BeNil ())
457
+
458
+ createObject (g , tc .powervsImage , ns .Name )
459
+ createCluster (g , tc .powervsCluster , ns .Name )
460
+ defer cleanupObject (g , tc .powervsImage )
461
+ defer cleanupCluster (g , tc .powervsCluster , ns )
462
+
463
+ if tc .powervsImage != nil {
464
+ g .Eventually (func () bool {
465
+ image := & infrav1.IBMPowerVSImage {}
466
+ key := client.ObjectKey {
467
+ Name : tc .powervsImage .Name ,
468
+ Namespace : ns .Name ,
469
+ }
470
+ err = testEnv .Get (ctx , key , image )
471
+ return err == nil
472
+ }, 10 * time .Second ).Should (Equal (true ))
473
+
474
+ _ , err := reconciler .Reconcile (ctx , ctrl.Request {
475
+ NamespacedName : client.ObjectKey {
476
+ Namespace : tc .powervsImage .Namespace ,
477
+ Name : tc .powervsImage .Name ,
478
+ },
479
+ })
480
+ if tc .expectError {
481
+ g .Expect (err ).ToNot (BeNil ())
482
+ image := & infrav1.IBMPowerVSImage {}
483
+ key := client.ObjectKey {
484
+ Namespace : tc .powervsImage .Namespace ,
485
+ Name : tc .powervsImage .Name ,
486
+ }
487
+ err = testEnv .Get (ctx , key , image )
488
+ g .Expect (err ).To (BeNil ())
489
+ expectConditionsImagev1beta2 (g , image , []metav1.Condition {{Type : infrav1 .IBMPowerVSImageReadyV1Beta2Condition , Status : metav1 .ConditionFalse , Reason : infrav1 .IBMPowerVSImageNotReadyV1Beta2Reason }})
490
+ } else {
491
+ g .Expect (err ).To (BeNil ())
492
+ }
493
+ }
494
+ })
495
+ }
496
+ }
497
+
498
+ func expectConditionsImagev1beta2 (g * WithT , m * infrav1.IBMPowerVSImage , expected []metav1.Condition ) {
499
+ g .Expect (len (m .Status .V1Beta2 .Conditions )).To (BeNumerically (">=" , len (expected )))
500
+ for _ , c := range expected {
501
+ actual := v1beta2conditions .Get (m , infrav1 .IBMPowerVSImageReadyV1Beta2Condition )
502
+ g .Expect (actual ).To (Not (BeNil ()))
503
+ g .Expect (actual .Type ).To (Equal (c .Type ))
504
+ g .Expect (actual .Status ).To (Equal (c .Status ))
505
+ g .Expect (actual .Reason ).To (Equal (c .Reason ))
506
+ }
507
+ }
0 commit comments