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

Helper methods dealing with ControllerRef #48319

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

nilebox
Copy link

@nilebox nilebox commented Jun 30, 2017

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:

It will also be useful for writing custom resource controllers, for example service-catalog#979

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 30, 2017
@k8s-ci-robot
Copy link
Contributor

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 /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.

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.

@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 Jun 30, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Jun 30, 2017
@nilebox
Copy link
Author

nilebox commented Jun 30, 2017

/cc @caesarxuchao @pmorie

}
}
return nil
}
Copy link
Member

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
}

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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"?

Copy link
Author

Choose a reason for hiding this comment

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

@ash2k
Copy link
Member

ash2k commented Jun 30, 2017

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 30, 2017
@ash2k
Copy link
Member

ash2k commented Jun 30, 2017

Are you going to refactor all places where the original methods used in separate PR(s)/commits?

@nilebox
Copy link
Author

nilebox commented Jun 30, 2017

@ash2k definitely as a separate PR(s), as it will touch a lot of files, and will be harder to get reviewed and merged.

@spiffxp
Copy link
Member

spiffxp commented Jun 30, 2017

/ok-to-test
@kubernetes/sig-api-machinery-pr-reviews PTAL (@ash2k I'm using the github team to notify instead of just applying the label)

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 30, 2017
@david-mcmahon david-mcmahon removed their assignment Jun 30, 2017
@ash2k
Copy link
Member

ash2k commented Jul 1, 2017

@spiffxp I don't have any special permissions on this repo so I think I cannot use mentions. Tried once - it didn't work.

@spiffxp
Copy link
Member

spiffxp commented Jul 5, 2017

@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

@nilebox
Copy link
Author

nilebox commented Jul 10, 2017

Looks like there is some flakiness in Kube tests:

  1. pull-kubernetes-unit - reports on kubefed TLS test failing (completely unrelated to the change), passes locally:
❯ go test -v k8s.io/kubernetes/federation/pkg/kubefed/init -run TestCertsTLS$

=== RUN   TestCertsTLS
--- PASS: TestCertsTLS (1.56s)
PASS
ok  	k8s.io/kubernetes/federation/pkg/kubefed/init	1.646s
  1. pull-kubernetes-e2e-kops-aws - Building Docker image times out (90 minutes), I have the same issue locally.

The same tests currently fail in other pull requests I looked at, for example #48689

@sttts
Copy link
Contributor

sttts commented Jul 10, 2017

@nilebox 1 is fixed in master

@sttts
Copy link
Contributor

sttts commented Jul 10, 2017

@nilebox which docker image times out and how can I reproduce this locally?

@nilebox
Copy link
Author

nilebox commented Jul 10, 2017

@sttts rebased onto latest master, let's see if anything gets fixed.

which docker image times out and how can I reproduce this locally?

make release (as per https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/48319/pull-kubernetes-e2e-kops-aws/33930/)

❯ make release
+++ [0710 13:55:21] Verifying Prerequisites....
+++ [0710 13:55:21] Using Docker for MacOS
+++ [0710 13:55:21] Building Docker image kube-build:build-0cbf19789f-5-v1.8.3-1

@nilebox
Copy link
Author

nilebox commented Jul 10, 2017

One more failure https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/48319/pull-kubernetes-federation-e2e-gce/13803/

IOError: [Errno 28] No space left on device

nice...

@nilebox
Copy link
Author

nilebox commented Jul 11, 2017

/retest

@nilebox
Copy link
Author

nilebox commented Jul 11, 2017

@sttts the Docker image build is still timing out, as well as in other pull requests (for example, #48726 (comment) and #48750 (comment)).

@fejta
Copy link
Contributor

fejta commented Jul 11, 2017

/test pull-kubernetes-e2e-kops-aws

@sttts sttts added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jul 12, 2017
@sttts
Copy link
Contributor

sttts commented Jul 12, 2017

/lgtm

Please squash.

@caesarxuchao approved?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 12, 2017
@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 12, 2017
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 12, 2017
@nilebox
Copy link
Author

nilebox commented Jul 12, 2017

Squashed, ready to be merged.

@sttts
Copy link
Contributor

sttts commented Jul 12, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 12, 2017
@k8s-github-robot
Copy link

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

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 48279, 48566, 48319, 48794, 47952)

@k8s-github-robot k8s-github-robot merged commit 9ba5083 into kubernetes:master Jul 12, 2017
k8s-github-robot pushed a commit that referenced this pull request Aug 11, 2017
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
@nilebox nilebox deleted the nilebox/controller-ref branch August 4, 2018 08:49
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. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants