Skip to content

Scheme helper fn #62

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 1 commit into from
Jun 26, 2018
Merged

Conversation

pwittrock
Copy link
Contributor

No description provided.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 26, 2018
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

LG
Have a few minor comments

s := runtime.NewScheme()

Expect(a(s)).To(Succeed())
Expect(s.AllKnownTypes()).To(HaveLen(13))
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why it has 13 items.
Maybe add a comments.

Expect(a(s)).To(Succeed())
Expect(s.AllKnownTypes()).To(HaveLen(13))
Expect(s.AllKnownTypes()[gv.WithKind("Pod")]).To(Equal(reflect.TypeOf(v1.Pod{})))
Expect(s.AllKnownTypes()[gv.WithKind("PodList")]).To(BeEquivalentTo(reflect.TypeOf(v1.PodList{})))
Copy link
Member

Choose a reason for hiding this comment

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

Why this one is using BeEquivalentTo but not Equal?
What is the difference between Pod and PodList?

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

I think the structure of this is fairly confusing. Why not have a helper like NewStandardScheme, which returns a new Scheme with these defaults already applied? You could still have this method available, but this seems like a weird entry point for common cases.


// NewAddToScheme returns a function to add go struct types as GroupVersionKinds to a runtime.Scheme.
// Scheme is used to map go structs to GroupVersionKinds and vice versa.
func NewAddToScheme(gv schema.GroupVersion, types func() []runtime.Object) func(*runtime.Scheme) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really weird name, and seems like a weird return type. Find a better name, maybe?

Copy link
Contributor Author

@pwittrock pwittrock Jun 26, 2018

Choose a reason for hiding this comment

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

It creates the new AddToScheme function that is required for all group version packages..

@pwittrock
Copy link
Contributor Author

I think the structure of this is fairly confusing. Why not have a helper like NewStandardScheme, which returns a new Scheme with these defaults already applied? You could still have this method available, but this seems like a weird entry point for common cases.

The approach of creating a NewAddToScheme function seems like a standard pattern across the kubernetes/kubernetes codebase. This removes the need to copy-paste the code. I think some of the code-generators rely upon the AddToScheme package function existing.

https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/abac/v1beta1/register.go

@pwittrock pwittrock force-pushed the register branch 2 times, most recently from 4f56484 to 68378b1 Compare June 26, 2018 16:42
@mengqiy
Copy link
Member

mengqiy commented Jun 26, 2018

LGTM
golint is failing.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 26, 2018
@pwittrock
Copy link
Contributor Author

@mengqiy Fixed the comment :)

@pwittrock pwittrock force-pushed the register branch 3 times, most recently from 23cf91f to 63b1f01 Compare June 26, 2018 18:30
@DirectXMan12
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2018
@pwittrock pwittrock added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2018
@k8s-ci-robot k8s-ci-robot merged commit eb6b5de into kubernetes-sigs:master Jun 26, 2018
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
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. 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.

4 participants