-
Notifications
You must be signed in to change notification settings - Fork 40k
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
refact kubectl Factory make it interface #33180
Conversation
@fabianofranz This ripples downstream. |
I'm in favor of the change, but wow that's big :) |
related to #31702 ? |
Looks like it. |
Please split the |
yes, sure, I will split this into separate commits. |
@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 |
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.
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.
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.
@soltysh a general fakeFactory with all methods implemented with empty bodies? what if several commands want to use a same implementation of some methods?
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.
That shouldn't be a problem for several commands re-using those.
edb7b7e
to
8918223
Compare
Jenkins GCI Kubemark GCE e2e failed for commit 8918223. Full PR test history. The magic incantation to run this job again is |
return nil | ||
} | ||
|
||
func (f *fakeFactory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, 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.
Should we return t.tf.Printer
?
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.
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 |
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.
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 :).
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.
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 |
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 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 |
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 have these been added?
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.
@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) |
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.
If these weren't exposed before, lets keep them hidden. I don't think we want to encourage access patterns like this.
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.
@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 |
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.
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
Mind squashing into
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. |
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 |
yes, so I would like to merge these into one commit, and one commit one command would leave so many commits tests failed. |
29e19ac
to
284dbbc
Compare
@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 |
@@ -54,7 +54,7 @@ type AnnotateOptions struct { | |||
newAnnotations map[string]string | |||
removeAnnotations []string | |||
|
|||
// Common shared fields |
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.
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") |
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.
remove this?
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.
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 |
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.
Nice
284dbbc
to
b2280a6
Compare
@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 |
Agreed. On Thu, Oct 13, 2016 at 3:22 PM, David Eads notifications@github.com
|
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
wow~ so glad to see this thanks @deads2k @Kargakis @fabianofranz @pwittrock |
Automatic merge from submit-queue |
refactor kubectl to make Factory interface. @kubernetes/kubectl
This change is