Skip to content
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

Merged
merged 1 commit into from
Jan 26, 2022

Conversation

aartij17
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 21, 2022
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 21, 2022
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 21, 2022
Copy link
Contributor

@killianmuldoon killianmuldoon left a 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 {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Info("ownerRef not found for the clusterResourceSetBinding")
log.Info("ownerRef not found for the ClusterResourceSetBinding")

@vincepri
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 21, 2022
@sbueringer
Copy link
Member

/cherry-pick release-1.1

@k8s-infra-cherrypick-robot

@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:

/cherry-pick release-1.1

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.

@aartij17 aartij17 force-pushed the fix-crbinding-condition branch 2 times, most recently from 2deb9ec to 95a64be Compare January 24, 2022 17:32
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 24, 2022
@aartij17 aartij17 force-pushed the fix-crbinding-condition branch from 95a64be to 8b8cbe3 Compare January 24, 2022 17:34
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 24, 2022
@@ -80,7 +80,11 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req
if err != nil && !apierrors.IsNotFound(err) {
Copy link
Member

@sbueringer sbueringer Jan 24, 2022

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.

Copy link
Contributor Author

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 :)

@aartij17 aartij17 force-pushed the fix-crbinding-condition branch from 8b8cbe3 to 8e16429 Compare January 24, 2022 17:56
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 24, 2022
@sbueringer
Copy link
Member

@AartiJivrajani Thank you!

@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 24, 2022
@sbueringer
Copy link
Member

/assign @fabriziopandini

@killianmuldoon
Copy link
Contributor

Thanks for taking this on @AartiJivrajani

/lgtm

@killianmuldoon
Copy link
Contributor

@AartiJivrajani I've noticed that there's a similar missing nil-check at

cluster, err := util.GetOwnerCluster(context.TODO(), r.Client, c.ObjectMeta)
Do you want to fix it? It can be part of this PR or in a follow-up

@sbueringer
Copy link
Member

@AartiJivrajani I've noticed that there's a similar missing nil-check at

cluster, err := util.GetOwnerCluster(context.TODO(), r.Client, c.ObjectMeta)

** ** Do you want to fix it? It can be part of this PR or in a follow-up

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.

@aartij17
Copy link
Contributor Author

I have created a new issue for this @sbueringer @killianmuldoon -
#5984

@fabriziopandini
Copy link
Member

/lgtm
/approve

/cherry-pick release-1.1

@k8s-infra-cherrypick-robot

@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:

/lgtm
/approve

/cherry-pick release-1.1

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.

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 26, 2022
@k8s-ci-robot k8s-ci-robot merged commit 992a83c into kubernetes-sigs:main Jan 26, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Jan 26, 2022
@k8s-infra-cherrypick-robot

@sbueringer: new pull request created: #5996

In response to this:

/cherry-pick release-1.1

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on startup from ClusterResourceSetBindingController
7 participants