-
Notifications
You must be signed in to change notification settings - Fork 40.3k
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
admission: unify plugin constructors #54485
admission: unify plugin constructors #54485
Conversation
7f35fbc
to
263c44a
Compare
is it common to return concrete unexported types? I guess I get the multiple interface thing, but it seems weird |
It does not make the type exported and you cannot observe the actual type programmatically without reflection. Hence, there is no harm. To the contrary, I have never seen multiple constructors for concrete types so fulfill multiple interfaces in Golang. It's used everywhere for non-private types. Making a type private seems to be orthogonal to that pattern. |
@liggitt golint also thinks it's weird, for Godoc reasons golang/lint#210. The alternative in the multi-interface case is to define a interface for each admission plugin that is public and subsumes all implemented interfaces. Certainly doable (remember we might get MutationInterface and ValidationInterface soon) and semi-ugly. Wdyt? |
the superinterface is the most appealing to me. in most places, we're already doing essentially this with a series of private package type assertions |
A local super interface doesn't work unfortunately: type A interface { Foo() }
type B interface { Foo() }
type C interface {
A
B
} This fails because |
@sttts: Adding do-not-merge/release-note-label-needed because the release note process has not been followed. One of the following labels is required "release-note", "release-note-action-required", or "release-note-none". 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. |
263c44a
to
3471bee
Compare
3471bee
to
ebc56aa
Compare
Ok, made the struct public now, with unexported fields (with the exception of the embedded |
/lgtm |
/approve no-issue |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, liggitt, sttts Associated issue requirement bypassed by: deads2k 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 |
ebc56aa
to
84e7c3f
Compare
84e7c3f
to
131905c
Compare
Automatic merge from submit-queue (batch tested with PRs 54761, 54748, 53991, 54485, 46951). If you want to cherry-pick this change to another branch, please follow the instructions here. |
It's common in Go to return the actual object in constructors, not one interface
it implements. This allows us to implement multiple interfaces, but only have
one constructor. As having private types in constructors, we export all plugin structs, of course with private fields.
Note: super interfaces do not work if there are overlapping methods.