-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Helper methods dealing with ControllerRef #48319
Helper methods dealing with ControllerRef #48319
Conversation
Hi @nilebox. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with 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. I understand the commands that are listed here. |
/cc @caesarxuchao @pmorie |
bcd887b
to
f86dd45
Compare
} | ||
} | ||
return 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.
I understand that this is a copy of existing code. I'm wondering why it is written that way? I'd simplify it:
func GetControllerOf(controllee meta_v1.Object) *meta_v1.OwnerReference {
for _, ref := range controllee.GetOwnerReferences() {
if ref.Controller != nil && *ref.Controller {
return &ref
}
}
return 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.
That's a difficult to debug bug in golang. &ref is different from &ownerRefs[i]. ref is a local variable. It took me quite a while to figure it out when i wrote the code initially.
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.
Yes, I understand what you mean :)
The difference is that my version returns a pointer to a copy (as you correctly pointed out) and the original version returns a pointer to the value stored in the slice. However in this case it does not matter in practice - there are only four implementations of GetOwnerReferences()
- all of them return copies of the internal owner references slice. So the code that called GetControllerOf()
cannot mutate the in-object owner references in any case because it will gat a pointer to a copy.
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.
Yes, both should work. Maybe at first i intended to return the original ref, but its not the intention now.
I think your version is better, it's always returning a pointer to a copy, no matter how GetOwnerReferences
is implemented.
Maybe we can update the comment to "GetControllerOf returns a pointer to a copy of the controllerRef if controllee has a 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.
@caesarxuchao done
/sig api-machinery |
Are you going to refactor all places where the original methods used in separate PR(s)/commits? |
@ash2k definitely as a separate PR(s), as it will touch a lot of files, and will be harder to get reviewed and merged. |
/ok-to-test |
@spiffxp I don't have any special permissions on this repo so I think I cannot use mentions. Tried once - it didn't work. |
@ash2k ah, cool... FWIW, I believe the bot now repeats sig mentions if it notices you're not a member, so they'll notify... if that's still not working for you, it's a bug to be filed against kubernetes/test-infra |
Looks like there is some flakiness in Kube tests:
The same tests currently fail in other pull requests I looked at, for example #48689 |
a7d0993
to
efce172
Compare
@nilebox 1 is fixed in master |
@nilebox which docker image times out and how can I reproduce this locally? |
@sttts rebased onto latest master, let's see if anything gets fixed.
|
One more failure https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/48319/pull-kubernetes-federation-e2e-gce/13803/
nice... |
/retest |
@sttts the Docker image build is still timing out, as well as in other pull requests (for example, #48726 (comment) and #48750 (comment)). |
/test pull-kubernetes-e2e-kops-aws |
/lgtm Please squash. @caesarxuchao approved? |
7cf78ce
to
e86faca
Compare
Squashed, ready to be merged. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nilebox, sttts Associated issue: 979 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 48279, 48566, 48319, 48794, 47952) |
Automatic merge from submit-queue Migrate to controller references helpers in meta/v1 **What this PR does / why we need it**: This is a follow up for #48319 that migrates all method usages to new methods in meta/v1. **Special notes for your reviewer**: Looking at each commit individually might be easier. **Release note**: ```release-note NONE ``` /sig api-machinery /kind cleanup
What this PR does / why we need it:
Adds helper methods for working with controllerRef (controller's
OwnerReference
).It is based on the existing code from Kubernetes plus extracting some common logic:
NewControllerRef
is based on examples from daemon controller, deployment controller, job controllerGetControllerOf
is copied from controller_ref_manager.goIsControlledBy
is a common logic extracted from resource controllers: deployment_util.go#L568, history.go#L276 and many others.It will also be useful for writing custom resource controllers, for example service-catalog#979