Skip to content

Commit 885c76e

Browse files
committed
address review comments
1 parent aac9194 commit 885c76e

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

cloud/scope/powervs_image.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ import (
3939
// BucketAccess indicates if the bucket has public or private access public access.
4040
const BucketAccess = "public"
4141

42+
var (
43+
// ErrServiceInsanceNotInActiveState indicates error if serviceInstance is inactive.
44+
ErrServiceInsanceNotInActiveState = errors.New("service instance is not in active state")
45+
)
46+
4247
// PowerVSImageScopeParams defines the input parameters used to create a new PowerVSImageScope.
4348
type PowerVSImageScopeParams struct {
4449
Client client.Client
@@ -106,8 +111,7 @@ func NewPowerVSImageScope(ctx context.Context, params PowerVSImageScopeParams) (
106111
return nil, fmt.Errorf("service instance %s is not yet created", name)
107112
}
108113
if *serviceInstance.State != string(infrav1.ServiceInstanceStateActive) {
109-
err = errors.New("service instance is not in active state")
110-
return nil, err
114+
return scope, ErrServiceInsanceNotInActiveState
111115
}
112116
serviceInstanceID = *serviceInstance.GUID
113117
}

controllers/ibmpowervsimage_controller.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
9898
scopeParams.Zone = cluster.Spec.Zone
9999
}
100100

101+
// Create the scope
102+
imageScope, err := scope.NewPowerVSImageScope(ctx, scopeParams)
103+
if err != nil {
104+
if errors.Is(err, scope.ErrServiceInsanceNotInActiveState) {
105+
v1beta2conditions.Set(imageScope.IBMPowerVSImage, metav1.Condition{
106+
Type: infrav1.WorkspaceReadyV1Beta2Condition,
107+
Status: metav1.ConditionFalse,
108+
Reason: infrav1.WorkspaceNotReadyV1Beta2Reason,
109+
})
110+
}
111+
return ctrl.Result{}, fmt.Errorf("failed to create scope: %w", err)
112+
}
113+
101114
// Initialize the patch helper
102115
patchHelper, err := v1beta1patch.NewHelper(ibmPowerVSImage, r.Client)
103116
if err != nil {
@@ -111,19 +124,6 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
111124
}
112125
}()
113126

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-
127127
// Handle deleted clusters.
128128
if !ibmPowerVSImage.DeletionTimestamp.IsZero() {
129129
return r.reconcileDelete(ctx, imageScope)
@@ -311,7 +311,6 @@ func (r *IBMPowerVSImageReconciler) reconcileDelete(ctx context.Context, scope *
311311

312312
if scope.IBMPowerVSImage.Spec.DeletePolicy != string(infrav1.DeletePolicyRetain) {
313313
if err := scope.DeleteImage(); err != nil {
314-
log.Error(err, "Error deleting IBMPowerVSImage")
315314
v1beta1conditions.MarkFalse(scope.IBMPowerVSImage, infrav1.ImageReadyCondition, clusterv1beta1.DeletionFailedReason, clusterv1beta1.ConditionSeverityWarning, "")
316315
v1beta2conditions.Set(scope.IBMPowerVSImage, metav1.Condition{
317316
Type: infrav1.IBMPowerVSImageReadyV1Beta2Condition,

controllers/ibmpowervsimage_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func TestIBMPowerVSImageReconciler_Reconcile_Conditions(t *testing.T) {
424424
}{
425425

426426
{
427-
name: "Conditions should be set after reconcile",
427+
name: "Conditions should be set after first reconcile",
428428
powervsCluster: &infrav1.IBMPowerVSCluster{
429429
ObjectMeta: metav1.ObjectMeta{
430430
Name: "capi-powervs-cluster"},

0 commit comments

Comments
 (0)