refactor to move kubectl.cmd.Factory to kubect/cmd/util

This commit is contained in:
deads2k
2015-04-07 14:21:25 -04:00
parent 13b805fe1e
commit 6344cf3c3a
34 changed files with 664 additions and 611 deletions

View File

@@ -23,7 +23,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"github.com/spf13/cobra"
)
@@ -45,7 +45,7 @@ $ kubectl resize --current-replicas=2 --replicas=3 replicationcontrollers foo`
retryTimeout = 10 * time.Second
)
func (f *Factory) NewCmdResize(out io.Writer) *cobra.Command {
func NewCmdResize(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "resize [--resource-version=version] [--current-replicas=count] --replicas=COUNT RESOURCE ID",
Short: "Set a new size for a Replication Controller.",
@@ -53,7 +53,7 @@ func (f *Factory) NewCmdResize(out io.Writer) *cobra.Command {
Example: resize_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunResize(f, out, cmd, args)
util.CheckErr(err)
cmdutil.CheckErr(err)
},
}
cmd.Flags().String("resource-version", "", "Precondition for resource version. Requires that the current resource version match this value in order to resize.")
@@ -62,10 +62,10 @@ func (f *Factory) NewCmdResize(out io.Writer) *cobra.Command {
return cmd
}
func RunResize(f *Factory, out io.Writer, cmd *cobra.Command, args []string) error {
count := util.GetFlagInt(cmd, "replicas")
func RunResize(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
count := cmdutil.GetFlagInt(cmd, "replicas")
if len(args) != 2 || count < 0 {
return util.UsageError(cmd, "--replicas=COUNT RESOURCE ID")
return cmdutil.UsageError(cmd, "--replicas=COUNT RESOURCE ID")
}
cmdNamespace, err := f.DefaultNamespace()
@@ -75,7 +75,7 @@ func RunResize(f *Factory, out io.Writer, cmd *cobra.Command, args []string) err
mapper, _ := f.Object()
// TODO: use resource.Builder instead
mapping, namespace, name, err := util.ResourceFromArgs(cmd, args, mapper, cmdNamespace)
mapping, namespace, name, err := cmdutil.ResourceFromArgs(cmd, args, mapper, cmdNamespace)
if err != nil {
return err
}
@@ -85,8 +85,8 @@ func RunResize(f *Factory, out io.Writer, cmd *cobra.Command, args []string) err
return err
}
resourceVersion := util.GetFlagString(cmd, "resource-version")
currentSize := util.GetFlagInt(cmd, "current-replicas")
resourceVersion := cmdutil.GetFlagString(cmd, "resource-version")
currentSize := cmdutil.GetFlagInt(cmd, "current-replicas")
precondition := &kubectl.ResizePrecondition{currentSize, resourceVersion}
cond := kubectl.ResizeCondition(resizer, precondition, namespace, name, uint(count))