-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 handle error in case ownerRef is not set on crs binding #5969
🐛 handle error in case ownerRef is not set on crs binding #5969
Conversation
Hi @AartiJivrajani. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @AartiJivrajani! I've taken a quick look and I'll come back to it on Monday.
@@ -80,7 +80,12 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req | |||
if err != nil && !apierrors.IsNotFound(err) { | |||
return ctrl.Result{}, err | |||
} | |||
|
|||
// On a backup, the clusterResourceSetBinding will not have an ownerRef set | |||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be if cluster == nil ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right @killianmuldoon. My bad.
When the ownerRef is not set, cluster
and err
would both be nil
.
@@ -80,7 +80,12 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req | |||
if err != nil && !apierrors.IsNotFound(err) { | |||
return ctrl.Result{}, err | |||
} | |||
|
|||
// On a backup, the clusterResourceSetBinding will not have an ownerRef set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
No need to specify this is a check for the backup case - it's a check we should be doing in all cases.
|
||
// On a backup, the clusterResourceSetBinding will not have an ownerRef set | ||
if err == nil { | ||
log.Info("ownerRef not found for the clusterResourceSetBinding") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Info("ownerRef not found for the clusterResourceSetBinding") | |
log.Info("ownerRef not found for the ClusterResourceSetBinding") |
/ok-to-test |
/cherry-pick release-1.1 |
@sbueringer: once the present PR merges, I will cherry-pick it on top of release-1.1 in a new PR and assign it to you. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
2deb9ec
to
95a64be
Compare
95a64be
to
8b8cbe3
Compare
@@ -80,7 +80,11 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req | |||
if err != nil && !apierrors.IsNotFound(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AartiJivrajani What do you think about restructuring the whole block?
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 cluster == nil {
log.Info("ownerRef not found for the ClusterResourceSetBinding")
return ctrl.Result{}, nil
}
// If the owner cluster is in the 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
It just seems easier to me to reason through the various states err
and cluster
could have when separating the handling for different values of err
and cluster
like this
P.S. I dropped the // requeue the request
comment as we're not requeuing in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improves readability a lot, thank you @sbueringer :)
8b8cbe3
to
8e16429
Compare
@AartiJivrajani Thank you! |
/lgtm |
/assign @fabriziopandini |
Thanks for taking this on @AartiJivrajani /lgtm |
@AartiJivrajani I've noticed that there's a similar missing nil-check at cluster-api/test/infrastructure/docker/internal/controllers/dockermachine_controller.go Line 397 in c6e3049
|
If we want to include this fix (cherry-pick) in v1.1 I would prefer a follow-up PR as the current PR already fixes an issue which can occur in production. |
I have created a new issue for this @sbueringer @killianmuldoon - |
/lgtm /cherry-pick release-1.1 |
@fabriziopandini: once the present PR merges, I will cherry-pick it on top of release-1.1 in a new PR and assign it to you. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@sbueringer: new pull request created: #5996 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What this PR does / why we need it:
In case of a backup, the CRS Binding does have a Cluster set in the
ownerRef
. This leads to a nil pointer exception.This PR adds a check around the presence of this
ownerRef
.Which issue(s) this PR fixes:
Fixes #5961