@@ -18,6 +18,7 @@ package controllers
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "time"
2324
@@ -97,12 +98,6 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
9798 scopeParams .Zone = cluster .Spec .Zone
9899 }
99100
100- // Create the scope
101- imageScope , err := scope .NewPowerVSImageScope (ctx , scopeParams )
102- if err != nil {
103- return ctrl.Result {}, fmt .Errorf ("failed to create scope: %w" , err )
104- }
105-
106101 // Initialize the patch helper
107102 patchHelper , err := v1beta1patch .NewHelper (ibmPowerVSImage , r .Client )
108103 if err != nil {
@@ -116,6 +111,19 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
116111 }
117112 }()
118113
114+ // Create the scope
115+ imageScope , err := scope .NewPowerVSImageScope (ctx , scopeParams )
116+ if err != nil {
117+ if err == errors .New ("service instance is not in active state" ) {
118+ v1beta2conditions .Set (imageScope .IBMPowerVSImage , metav1.Condition {
119+ Type : infrav1 .WorkspaceReadyV1Beta2Condition ,
120+ Status : metav1 .ConditionFalse ,
121+ Reason : infrav1 .WorkspaceNotReadyV1Beta2Reason ,
122+ })
123+ }
124+ return ctrl.Result {}, fmt .Errorf ("failed to create scope: %w" , err )
125+ }
126+
119127 // Handle deleted clusters.
120128 if ! ibmPowerVSImage .DeletionTimestamp .IsZero () {
121129 return r .reconcileDelete (ctx , imageScope )
@@ -147,6 +155,12 @@ func (r *IBMPowerVSImageReconciler) reconcile(ctx context.Context, cluster *infr
147155 return ctrl.Result {}, nil
148156 }
149157
158+ v1beta2conditions .Set (imageScope .IBMPowerVSImage , metav1.Condition {
159+ Type : infrav1 .WorkspaceReadyV1Beta2Condition ,
160+ Status : metav1 .ConditionTrue ,
161+ Reason : infrav1 .WorkspaceReadyV1Beta2Reason ,
162+ })
163+
150164 if jobID := imageScope .GetJobID (); jobID != "" {
151165 job , err := imageScope .IBMPowerVSClient .GetJob (jobID )
152166 if err != nil {
@@ -357,6 +371,7 @@ func patchIBMPowerVSImage(ctx context.Context, patchHelper *v1beta1patch.Helper,
357371 if err := v1beta2conditions .SetSummaryCondition (ibmPowerVSImage , ibmPowerVSImage , infrav1 .IBMPowerVSImageReadyCondition ,
358372 v1beta2conditions.ForConditionTypes {
359373 infrav1 .IBMPowerVSImageReadyV1Beta2Condition ,
374+ infrav1 .WorkspaceReadyV1Beta2Condition ,
360375 },
361376 // Using a custom merge strategy to override reasons applied during merge.
362377 v1beta2conditions.CustomMergeStrategy {
@@ -378,5 +393,6 @@ func patchIBMPowerVSImage(ctx context.Context, patchHelper *v1beta1patch.Helper,
378393 infrav1 .IBMPowerVSImageReadyCondition ,
379394 infrav1 .IBMPowerVSImageReadyV1Beta2Condition ,
380395 clusterv1beta1 .PausedV1Beta2Condition ,
396+ infrav1 .WorkspaceReadyV1Beta2Condition ,
381397 }})
382398}
0 commit comments