-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Scheme helper fn #62
Conversation
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.
LG
Have a few minor comments
pkg/runtime/scheme/scheme_test.go
Outdated
s := runtime.NewScheme() | ||
|
||
Expect(a(s)).To(Succeed()) | ||
Expect(s.AllKnownTypes()).To(HaveLen(13)) |
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 don't understand why it has 13 items.
Maybe add a comments.
pkg/runtime/scheme/scheme_test.go
Outdated
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{}))) |
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.
Why this one is using BeEquivalentTo
but not Equal
?
What is the difference between Pod and PodList?
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 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.
pkg/runtime/scheme/scheme.go
Outdated
|
||
// 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 { |
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 is a really weird name, and seems like a weird return type. Find a better name, maybe?
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.
It creates the new AddToScheme
function that is required for all group version packages..
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 |
4f56484
to
68378b1
Compare
LGTM |
@mengqiy Fixed the comment :) |
23cf91f
to
63b1f01
Compare
/lgtm |
Scheme helper fn
No description provided.