Skip to content

Commit

Permalink
Bug fix - retry binding reconcile when instance is not found (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
kerenlahav authored Dec 25, 2023
1 parent db12d7e commit fb2ff34
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,30 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
}

serviceInstance, err := r.getServiceInstanceForBinding(ctx, serviceBinding)
if client.IgnoreNotFound(err) != nil {
log.Error(err, "failed to get service instance for binding")
return ctrl.Result{}, err
serviceInstance, instanceErr := r.getServiceInstanceForBinding(ctx, serviceBinding)
if instanceErr != nil {
if !apierrors.IsNotFound(instanceErr) {
log.Error(instanceErr, "failed to get service instance for binding")
return ctrl.Result{}, instanceErr
} else if !isMarkedForDeletion(serviceBinding.ObjectMeta) {
//instance is not found and binding is not marked for deletion
instanceNamespace := serviceBinding.Namespace
if len(serviceBinding.Spec.ServiceInstanceNamespace) > 0 {
instanceNamespace = serviceBinding.Spec.ServiceInstanceNamespace
}
errMsg := fmt.Sprintf("couldn't find the service instance '%s' in namespace '%s'", serviceBinding.Spec.ServiceInstanceName, instanceNamespace)
setBlockedCondition(ctx, errMsg, serviceBinding)
if updateErr := r.updateStatus(ctx, serviceBinding); updateErr != nil {
return ctrl.Result{}, updateErr
}
return ctrl.Result{}, instanceErr
}
}

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

if err != nil { // instance not found
instanceNamespace := serviceBinding.Namespace
if len(serviceBinding.Spec.ServiceInstanceNamespace) > 0 {
instanceNamespace = serviceBinding.Spec.ServiceInstanceNamespace
}
errMsg := fmt.Sprintf("couldn't find the service instance '%s' in namespace '%s'", serviceBinding.Spec.ServiceInstanceName, instanceNamespace)
setBlockedCondition(ctx, errMsg, serviceBinding)
return ctrl.Result{}, r.updateStatus(ctx, serviceBinding)
}

if len(serviceBinding.Status.OperationURL) > 0 {
// ongoing operation - poll status from SM
return r.poll(ctx, serviceBinding, serviceInstance.Spec.BTPAccessCredentialsSecret)
Expand Down

0 comments on commit fb2ff34

Please sign in to comment.