Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#5969 from AartiJivrajani/fix-crbin…
Browse files Browse the repository at this point in the history
…ding-condition

🐛 handle error in case ownerRef is not set on crs binding
  • Loading branch information
k8s-ci-robot authored Jan 26, 2022
2 parents 5d126b1 + 8e16429 commit 992a83c
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req
}

cluster, err := util.GetOwnerCluster(ctx, r.Client, binding.ObjectMeta)
if err != nil && !apierrors.IsNotFound(err) {
if err != nil {
if apierrors.IsNotFound(err) {
// If the owner cluster is already deleted, delete its ClusterResourceSetBinding
log.Info("deleting ClusterResourceSetBinding because the owner Cluster no longer exists")
return ctrl.Result{}, r.Client.Delete(ctx, binding)
}
return ctrl.Result{}, err
}

// If the owner cluster is already deleted or in deletion process, delete its ClusterResourceSetBinding
if apierrors.IsNotFound(err) || !cluster.DeletionTimestamp.IsZero() {
log.Info("deleting ClusterResourceSetBinding because the owner Cluster no longer exists")
err := r.Client.Delete(ctx, binding)
return ctrl.Result{}, err
if cluster == nil {
log.Info("ownerRef not found for the ClusterResourceSetBinding")
return ctrl.Result{}, nil
}
// If the owner cluster is in deletion process, delete its ClusterResourceSetBinding
if !cluster.DeletionTimestamp.IsZero() {
log.Info("deleting ClusterResourceSetBinding because the owner Cluster is currently being deleted")
return ctrl.Result{}, r.Client.Delete(ctx, binding)
}

return ctrl.Result{}, nil
Expand Down

0 comments on commit 992a83c

Please # to comment.