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

admission: unify plugin constructors #54485

Merged

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Oct 24, 2017

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.

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 24, 2017
@sttts sttts added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 24, 2017
@sttts sttts force-pushed the sttts-unify-admission-constructors branch from 7f35fbc to 263c44a Compare October 24, 2017 14:32
@liggitt
Copy link
Member

liggitt commented Oct 24, 2017

is it common to return concrete unexported types? I guess I get the multiple interface thing, but it seems weird

@sttts
Copy link
Contributor Author

sttts commented Oct 25, 2017

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.

@sttts
Copy link
Contributor Author

sttts commented Oct 25, 2017

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

@sttts
Copy link
Contributor Author

sttts commented Oct 27, 2017

@liggitt
Copy link
Member

liggitt commented Oct 27, 2017

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

@sttts
Copy link
Contributor Author

sttts commented Oct 30, 2017

A local super interface doesn't work unfortunately:

type A interface { Foo() }
type B interface { Foo() }

type C interface {
  A
  B
}

This fails because Foo() is defined twice in C. So we are left with a public struct and private fields.

@sttts
Copy link
Contributor Author

sttts commented Oct 30, 2017

After super interfaces are broken in Golang, I don't care whether we

  • use unexported types in constructors (plus a golint exception)
  • or make the plugin structs public.

Which way do we choose? @deads2k @liggitt

@deads2k
Copy link
Contributor

deads2k commented Oct 30, 2017

Which way do we choose? @deads2k @liggitt

I don't care either way. Public structs just make some golint-ing sugar over the private structs. Whatever you've got working works for me.

@k8s-ci-robot
Copy link
Contributor

@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".
Please see: https://github.com/kubernetes/community/blob/master/contributors/devel/pull-requests.md#write-release-notes-if-needed.

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.

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 30, 2017
@sttts sttts force-pushed the sttts-unify-admission-constructors branch from 263c44a to 3471bee Compare October 30, 2017 13:22
@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 Oct 30, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2017
@sttts sttts force-pushed the sttts-unify-admission-constructors branch from 3471bee to ebc56aa Compare October 30, 2017 13:26
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2017
@sttts
Copy link
Contributor Author

sttts commented Oct 30, 2017

Ok, made the struct public now, with unexported fields (with the exception of the embedded Handler. But that is another issue we had before this PR, so no regression).

@liggitt
Copy link
Member

liggitt commented Oct 30, 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 Oct 30, 2017
@deads2k
Copy link
Contributor

deads2k commented Oct 30, 2017

/approve no-issue

@deads2k deads2k added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 30, 2017
@k8s-github-robot
Copy link

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

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2017
@sttts sttts force-pushed the sttts-unify-admission-constructors branch from ebc56aa to 84e7c3f Compare October 30, 2017 15:07
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2017
@sttts sttts added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2017
@sttts sttts force-pushed the sttts-unify-admission-constructors branch from 84e7c3f to 131905c Compare October 30, 2017 15:56
@sttts sttts added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Oct 30, 2017
@k8s-github-robot
Copy link

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.

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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. 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.

5 participants