Skip to content

Commit 4f19692

Browse files
committed
add service instance conditions
1 parent f70e52e commit 4f19692

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cloud/scope/powervs_image.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ func NewPowerVSImageScope(ctx context.Context, params PowerVSImageScopeParams) (
106106
return nil, fmt.Errorf("service instance %s is not yet created", name)
107107
}
108108
if *serviceInstance.State != string(infrav1.ServiceInstanceStateActive) {
109-
return nil, fmt.Errorf("service instance %s is not in active state", name)
109+
err = errors.New("service instance is not in active state")
110+
return nil, err
110111
}
111112
serviceInstanceID = *serviceInstance.GUID
112113
}

controllers/ibmpowervsimage_controller.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
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

Comments
 (0)