Skip to content

cp pointers util from kubernetes/kubernetes #41

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

Merged
merged 2 commits into from
Jul 26, 2018

Conversation

stewart-yu
Copy link
Contributor

We need move the k8s.io/kubernetes/pkg/util/pointer package to k8s.io/utils/ repo, more details please refer to PR in kubernetes repo.

Following the instruction, this PR is the first step

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 18, 2018
@stewart-yu
Copy link
Contributor Author

seems no OWNER file in this repo
/assign @thockin @luxas @sttts
PTAL, related kubernetes repo PR, thanks

README.md Outdated
@@ -1,5 +1,6 @@
# Utils


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why this empty line?

// BoolPtr returns a pointer to a bool
func BoolPtr(b bool) *bool {
return &b
}
Copy link
Contributor

Choose a reason for hiding this comment

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

StringPtr. Don't we have that 1000 times in kube?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, add it now

@stewart-yu stewart-yu force-pushed the stewart-utils-pointers branch from 3f07872 to 3289602 Compare July 18, 2018 08:53
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 18, 2018
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks!

@stewart-yu
Copy link
Contributor Author

/cc @thockin
for review, thanks

@k8s-ci-robot k8s-ci-robot requested a review from thockin July 25, 2018 01:09
README.md Outdated
@@ -45,6 +45,7 @@ an existing package to this repository.

- [Clock](/clock) provides an interface for time-based operations. It allows
mocking time for testing.
- [Pointers](/pointers) provides some functions for pointer-based operations.
Copy link
Member

Choose a reason for hiding this comment

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

For some reason, we've kept an empty line between each module (don't ask me why), but maybe we should keep it consistent?

return true
}

// Int32Ptr returns a pointer to an int32
Copy link
Member

Choose a reason for hiding this comment

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

AFAICR, Tim gave this as an example of what we shouldn't have in this repo (might remember it wrong, I'll look it up)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems Int32Ptr() had been used, if do not put here, which file fo put it?

Copy link
Member

Choose a reason for hiding this comment

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

The problem is not that it's not being used, the problem is that you're trying to share code with very little complexity.

Copy link
Member

Choose a reason for hiding this comment

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

It's gonna be used by many packages, and is generally useful, although very simple.

@apelisse
Copy link
Member

@luxas
Copy link
Member

luxas commented Jul 26, 2018

On the other hand @apelisse kubernetes/kubernetes#66010 (review) :)

This seems fine but why apimachinery and not https://github.com/kubernetes/utils ? I might clean up some of the APIs, if you want to put a little polish into it...

@apelisse
Copy link
Member

I guess I can't argue with that :-)

@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 26, 2018
{(*struct{})(nil), true},
}
for i, tc := range testCases {
if AllPtrFieldsNil(tc.obj) != tc.expected {
Copy link
Member

Choose a reason for hiding this comment

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

This could use t.Run

@luxas
Copy link
Member

luxas commented Jul 26, 2018

Can you merge then to unblock us @apelisse :)?

@apelisse apelisse merged commit 66066c8 into kubernetes:master Jul 26, 2018
@luxas
Copy link
Member

luxas commented Jul 26, 2018

Thanks 🎉!

@stewart-yu
Copy link
Contributor Author

Thanks all

@sttts
Copy link
Contributor

sttts commented Jul 27, 2018

Finally we have a generic pointer package 🎉🚀

}

// StringPtr returns a pointer to the passed string.
func StringPtr(s string) *string {
Copy link
Contributor

Choose a reason for hiding this comment

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

float64 is missing 😱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, little knowledge about it, make be as follow-up
In generic, there are StringSlicePtr StringMapPtr Float32Ptr Float64Ptr , does we need some of them or all to make pointer packages contained all pointer-oprater?

@thockin
Copy link
Member

thockin commented Jul 27, 2018

This is in so I won't be a pain about it, but this is the sort of dependency that causes very interconnected dep graphs. Any tool that uses this now has to vendor this whole repo. Part of the go ethos is that it's better to copy a little code than to take a dependency. Let's please not let this accumulate tons of random crap.

@luxas
Copy link
Member

luxas commented Jul 27, 2018

No agree we shouldn't put "random crap" in this repo, but this exact utilpointer code is referenced by most of our API packages that deal with defaulting, so this is kinda-needed unless we want to start doing stuff like this in our defaulting packages (that will now live in n different repos)

trueVar := true
obj.SomeBoolPointerField = &trueVar

vs

obj.SomeBoolPointerField = utilpointer.BoolVar(true)

Well you know this already, but anyway I've made the argument for this now.

For me this could have moved to k8s.io/apimachinery equally fine but you said in kubernetes/kubernetes#66010 (review)

This seems fine but why apimachinery and not https://github.com/kubernetes/utils ? I might clean up some of the APIs, if you want to put a little polish into it...

So I'm a bit confused.
In any case I'm of the opinion this needs to live somewhere to not be a pain for the defaulting code for the ComponentConfigs.

Any tool that uses this now has to vendor this whole repo

hmm I had the idea one can vendor individual packages, not the whole repo? @sttts had also done some experimenting with this I think wrt the ComponentConfig KEP in general

@thockin
Copy link
Member

thockin commented Jul 27, 2018 via email

@luxas
Copy link
Member

luxas commented Jul 27, 2018

Lucas, you should know by now that I never claim to be 100% self-consistent

Hahah, yeah ;). Can't say I'm always super consistent with reviews either lol

You can vendor just one package, but you have to download and examine the
whole repo. Some tools used to not do subdir-vendoring, but I think we're
past that.

I don't think this will be a problem as anything should be able to depend on k8s.io/utils, this is used by multiple k8s consumers in various repos, the package has a well-defined scope, and all modern vendoring systems I know of supports pulling individual packages.

@thockin If this sounds good to you, go ahead and approve kubernetes/kubernetes#66284 which follows this up in the k/k repo ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

6 participants