-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix duplicate controller references #99
Fix duplicate controller references #99
Conversation
@calind Thanks for the PR. Looks good, Can we add a few tests to verify the behavior. |
Will do. Can you take a look at #100 as well since the tests fail because of that. Thanks! |
@droot, since only one
I think that first option is the one to go. |
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.
Return an error is another OwnerReference is a controller
This looks reasonable to me. Added a comment about the returning error.
@@ -28,6 +28,8 @@ import ( | |||
// SetControllerReference sets owner as a Controller OwnerReference on owned. | |||
// This is used for garbage collection of the owned object and for | |||
// reconciling the owner object on changes to owned (with a Watch + EnqueueRequestForOwner). | |||
// Since only one OwnerRecerence can be a controller, it returns an error if |
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.
s/OwnerRecerence/OwnerReference
if r.Kind == gvk.Kind && r.Name == owner.GetName() && r.UID == owner.GetUID() { | ||
fi = i | ||
} else if r.Controller != nil && *r.Controller { | ||
return fmt.Errorf("Object %s/%s is already owned by another %s controller %s", object.GetNamespace(), object.GetName(), r.Kind, r.Name) |
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.
May be we should consider creating an error-type for this error because users would like to detect this error-type and kick-in some business logic for adopting of these objects (re-parenting to new owner). @DirectXMan12 what do you think ?
9ebc8e2
to
0bc15bd
Compare
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 improving it further. Few nits about the new changes, then good to go.
@@ -25,9 +25,31 @@ import ( | |||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil" | |||
) | |||
|
|||
// AlreadyOwnedError is an error returned if the object you are trying to assign | |||
// an controller reference is already owned by another controller |
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.
s/an/a
} | ||
|
||
// NewAlreadyOwnedError creates a new AlreadyOwnedError | ||
func NewAlreadyOwnedError(Object v1.Object, Owner v1.OwnerReference) *AlreadyOwnedError { |
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 fn doesn't need to be exported so pl. lowercase it.
return nil | ||
} | ||
|
||
// Returns true if a and b point to the same object | ||
func sameOwnerReference(a, b v1.OwnerReference) bool { |
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.
Since its comparing the GVKs, better name should be gvkEquals(a,b)
. Current name reads as a
, b
has same owner ?
I wonder if something like this exists the apimachinery already ?
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.
I've looked trough apimachinery but didn't found a comparison function for OwnerReference objects. As for GVK they are directly comparable since they are just structs made of strings :)
@calind This is good to go. Can you pl. squash the commits ?. Thank you so much for this PR. |
6878ec1
to
ce38862
Compare
@droot done. Thanks for the feedback. |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: calind 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 |
…ference Fix duplicate controller references
Add binary path in testEnvironment for kubebuilder integration test
Fixes #68