Allow Create/Update/Delete kubectl commands to handle arbitrary objects

* Ensure kubectl uses abstractions from other parts of Kube
* Begin adding abstractions that allow arbitrary objects
* Refactor "update" to more closely match allowed behavior
This commit is contained in:
Clayton Coleman
2014-10-26 22:21:31 -04:00
parent f0c23d68f7
commit 39882a3555
10 changed files with 288 additions and 185 deletions

View File

@@ -27,12 +27,20 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/golang/glog"
"github.com/spf13/cobra"
)
type Factory struct {
Mapper meta.RESTMapper
Typer runtime.ObjectTyper
Client func(*cobra.Command, *meta.RESTMapping) (kubectl.RESTClient, error)
}
func RunKubectl(out io.Writer) {
// Parent command to which all subcommands are added.
cmds := &cobra.Command{
@@ -44,6 +52,15 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
Run: runHelp,
}
factory := &Factory{
Mapper: latest.NewDefaultRESTMapper(),
Typer: api.Scheme,
Client: func(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.RESTClient, error) {
// Will handle all resources defined by the command
return getKubeClient(cmd), nil
},
}
// Globally persistent flags across all subcommands.
// TODO Change flag names to consts to allow safer lookup from subcommands.
// TODO Add a verbose flag that turns on glog logging. Probably need a way
@@ -63,9 +80,11 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
cmds.AddCommand(NewCmdProxy(out))
cmds.AddCommand(NewCmdGet(out))
cmds.AddCommand(NewCmdDescribe(out))
cmds.AddCommand(NewCmdCreate(out))
cmds.AddCommand(NewCmdUpdate(out))
cmds.AddCommand(NewCmdDelete(out))
cmds.AddCommand(factory.NewCmdCreate(out))
cmds.AddCommand(factory.NewCmdUpdate(out))
cmds.AddCommand(factory.NewCmdDelete(out))
cmds.AddCommand(NewCmdNamespace(out))
cmds.AddCommand(NewCmdLog(out))
cmds.AddCommand(NewCmdCreateAll(out))