Skip to content

Commit fb2ff34

Browse files
authored
Bug fix - retry binding reconcile when instance is not found (#382)
1 parent db12d7e commit fb2ff34

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

controllers/servicebinding_controller.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,30 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
8686
}
8787
}
8888

89-
serviceInstance, err := r.getServiceInstanceForBinding(ctx, serviceBinding)
90-
if client.IgnoreNotFound(err) != nil {
91-
log.Error(err, "failed to get service instance for binding")
92-
return ctrl.Result{}, err
89+
serviceInstance, instanceErr := r.getServiceInstanceForBinding(ctx, serviceBinding)
90+
if instanceErr != nil {
91+
if !apierrors.IsNotFound(instanceErr) {
92+
log.Error(instanceErr, "failed to get service instance for binding")
93+
return ctrl.Result{}, instanceErr
94+
} else if !isMarkedForDeletion(serviceBinding.ObjectMeta) {
95+
//instance is not found and binding is not marked for deletion
96+
instanceNamespace := serviceBinding.Namespace
97+
if len(serviceBinding.Spec.ServiceInstanceNamespace) > 0 {
98+
instanceNamespace = serviceBinding.Spec.ServiceInstanceNamespace
99+
}
100+
errMsg := fmt.Sprintf("couldn't find the service instance '%s' in namespace '%s'", serviceBinding.Spec.ServiceInstanceName, instanceNamespace)
101+
setBlockedCondition(ctx, errMsg, serviceBinding)
102+
if updateErr := r.updateStatus(ctx, serviceBinding); updateErr != nil {
103+
return ctrl.Result{}, updateErr
104+
}
105+
return ctrl.Result{}, instanceErr
106+
}
93107
}
94108

95109
if isMarkedForDeletion(serviceBinding.ObjectMeta) {
96110
return r.delete(ctx, serviceBinding, serviceInstance.Spec.BTPAccessCredentialsSecret)
97111
}
98112

99-
if err != nil { // instance not found
100-
instanceNamespace := serviceBinding.Namespace
101-
if len(serviceBinding.Spec.ServiceInstanceNamespace) > 0 {
102-
instanceNamespace = serviceBinding.Spec.ServiceInstanceNamespace
103-
}
104-
errMsg := fmt.Sprintf("couldn't find the service instance '%s' in namespace '%s'", serviceBinding.Spec.ServiceInstanceName, instanceNamespace)
105-
setBlockedCondition(ctx, errMsg, serviceBinding)
106-
return ctrl.Result{}, r.updateStatus(ctx, serviceBinding)
107-
}
108-
109113
if len(serviceBinding.Status.OperationURL) > 0 {
110114
// ongoing operation - poll status from SM
111115
return r.poll(ctx, serviceBinding, serviceInstance.Spec.BTPAccessCredentialsSecret)

0 commit comments

Comments
 (0)