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

refact kubectl Factory make it interface #33180

Merged
merged 3 commits into from
Oct 13, 2016

Conversation

adohe-zz
Copy link

@adohe-zz adohe-zz commented Sep 21, 2016

refactor kubectl to make Factory interface. @kubernetes/kubectl


This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Sep 21, 2016
@deads2k
Copy link
Contributor

deads2k commented Sep 21, 2016

@fabianofranz This ripples downstream.

@deads2k deads2k assigned fabianofranz and unassigned deads2k Sep 21, 2016
@deads2k
Copy link
Contributor

deads2k commented Sep 21, 2016

I'm in favor of the change, but wow that's big :)

@MHBauer
Copy link
Contributor

MHBauer commented Sep 21, 2016

related to #31702 ?

@deads2k
Copy link
Contributor

deads2k commented Sep 21, 2016

related to #31702 ?

Looks like it.

@smarterclayton
Copy link
Contributor

Please split the *cmdutil.Factory change in each command into its own commit - that will make this much easier to review.

@adohe-zz
Copy link
Author

yes, sure, I will split this into separate commits.

@adohe-zz
Copy link
Author

@fabianofranz As we have discussed on email, we will propose a new SIG for kubectl, which gives us a place to discuss the CLI architecture, like this one. So here I want to make sure this is the correct way. I will get this merged asap. @pwittrock ptal.

@@ -209,7 +213,12 @@ type testFactory struct {
Err error
}

func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.NegotiatedSerializer) {
type fakeFactory struct {
tf *testFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to have a general fakeFactory for tests, that will have all the methods implemented, with empty bodies, of course. Then in commands you'd be embedding it and just providing an implementation to whichever method you need. This should simplify testing, imho.

Copy link
Author

Choose a reason for hiding this comment

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

@soltysh a general fakeFactory with all methods implemented with empty bodies? what if several commands want to use a same implementation of some methods?

Copy link
Contributor

Choose a reason for hiding this comment

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

That shouldn't be a problem for several commands re-using those.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins GCI Kubemark GCE e2e failed for commit 8918223. Full PR test history.

The magic incantation to run this job again is @k8s-bot kubemark gci e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 25, 2016
@adohe-zz adohe-zz changed the title [WIP] refact kubectl Factory make it interface refact kubectl Factory make it interface Sep 25, 2016
return nil
}

func (f *fakeFactory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we return t.tf.Printer ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return t.tf.Printer

I think we should keep this pull targeted. Switch them all to methods on the Factory interface and then change signatures later. This pull is already massive.

}

func (f *fakeFactory) NewBuilder() *resource.Builder {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

The DrainOptions.SetupDrain in cmd/drain.go will use NewBuidler of factory, and the default implementation of NewFactory will take Factory::Object's return value as parameters. That's what I mean in slack.

But we're luck, it seems DrainOptions.SetupDrain is not used by anyone :).

Copy link
Author

Choose a reason for hiding this comment

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

we still need to be careful about this.

Object func() (meta.RESTMapper, runtime.ObjectTyper)
type Factory interface {
// Returns the inner flag set
Flags() *pflag.FlagSet
Copy link
Contributor

Choose a reason for hiding this comment

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

This used to be private, right? Can we keep it private?

// Command will stringify and return all environment arguments ie. a command run by a client
// using the factory.
// TODO: We need to filter out stuff like secrets.
Command() string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have these been added?

Copy link
Author

Choose a reason for hiding this comment

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

@deads2k originally Factory struct has these methods, and they are exported, so other packages can use. If we make Factory interface, and not add these methods to the interface definition, other packages which use this interface can not use theses methods anymore.

// TODO: We need to filter out stuff like secrets.
Command() string
// BindFlags adds any flags that are common to all kubectl sub commands.
BindFlags(flags *pflag.FlagSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

If these weren't exposed before, lets keep them hidden. I don't think we want to encourage access patterns like this.

Copy link
Author

Choose a reason for hiding this comment

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

@deads2k actually these are methods of Factory struct before, and they are exported. The problem is why we add these methods as struct methods, and others as struct fields.

// BindExternalFlags adds any flags defined by external projects (not part of pflags)
BindExternalFlags(flags *pflag.FlagSet)
// PrintObject prints an api object given command line flags to modify the output format
PrintObject(cmd *cobra.Command, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove/hide. We don't want to the factory accepting the command. We want specific structs passing the information we need and all of these look be net-new

@deads2k deads2k added the priority/backlog Higher priority than priority/awaiting-more-evidence. label Sep 26, 2016
@deads2k deads2k added this to the v1.5 milestone Sep 26, 2016
@deads2k
Copy link
Contributor

deads2k commented Sep 26, 2016

Mind squashing into

  1. update factory.
  2. create test factory
  3. mechanical command updates? - looks like these were mostly just removing the *.

I'd like to see the interface slimmed down a little bit. If that turns out to require rippling changes, just make follow-up issues. This is a nice improvement over where we are now.

@deads2k
Copy link
Contributor

deads2k commented Sep 26, 2016

After squash and green, I'd merge this as-is and we can iterate.

I bumped the priority, once its green, we want this to beat any other kubectl changes.

@adohe-zz
Copy link
Author

3. mechanical command updates? - looks like these were mostly just removing the *.

yes, so I would like to merge these into one commit, and one commit one command would leave so many commits tests failed.

@adohe-zz adohe-zz force-pushed the refactory_interface branch from 29e19ac to 284dbbc Compare October 13, 2016 00:20
@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 13, 2016
@adohe-zz
Copy link
Author

@deads2k @fabianofranz @pwittrock I just rebased and fixed the failed tests, please take a look, and give your feedback, I would hope we can get this merged asap. This is just a beginning of Factory refactor, eventually we will make Factory a collection of interfaces, and finally we will implement something we discussed in #31173 #7311

@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 13, 2016
@@ -54,7 +54,7 @@ type AnnotateOptions struct {
newAnnotations map[string]string
removeAnnotations []string

// Common shared fields
Copy link
Contributor

Choose a reason for hiding this comment

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

shared is correct here

@@ -419,6 +419,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
unsched.SetBool(desired)
_, err := helper.Replace(cmdNamespace, o.nodeInfo.Name, true, o.nodeInfo.Object)
if err != nil {
fmt.Println("get error here")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this?

Copy link
Author

Choose a reason for hiding this comment

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

some stupid error, :(

// Requires that printer flags have been added to cmd (see AddPrinterFlags).
PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, error)
// One stop shopping for a Builder
NewBuilder() *resource.Builder
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@adohe-zz adohe-zz force-pushed the refactory_interface branch from 284dbbc to b2280a6 Compare October 13, 2016 13:02
@adohe-zz
Copy link
Author

@deads2k @fabianofranz @pwittrock @Kargakis rebased and update, ptal.

@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 13, 2016
@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 13, 2016
@deads2k
Copy link
Contributor

deads2k commented Oct 13, 2016

@deads2k @fabianofranz @pwittrock @Kargakis rebased and update, ptal.

I don't see an obvious, "this doesn't work", so I'm tagging this as-is. This breaks the back of the problem and I'd like to merge it and take everything else as a follow-up unless someone finds a "this breaks kubectl" kind of bug.

@0xmichalis
Copy link
Contributor

Agreed.

On Thu, Oct 13, 2016 at 3:22 PM, David Eads notifications@github.com
wrote:

@deads2k https://github.com/deads2k @fabianofranz
https://github.com/fabianofranz @pwittrock
https://github.com/pwittrock @Kargakis https://github.com/kargakis
rebased and update, ptal.

I don't see an obvious, "this doesn't work", so I'm tagging this as-is.
This breaks the back of the problem and I'd like to merge it and take
everything else as a follow-up unless someone finds a "this breaks kubectl"
kind of bug.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#33180 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADuFf5hZTN1ioeKIpO6xKH8LZn1jWTHYks5qzjCigaJpZM4KC8-K
.

@k8s-github-robot k8s-github-robot added the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Oct 13, 2016
@deads2k deads2k added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. release-note-label-needed labels Oct 13, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@adohe-zz
Copy link
Author

wow~ so glad to see this thanks @deads2k @Kargakis @fabianofranz @pwittrock

@k8s-github-robot
Copy link

Automatic merge from submit-queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.