Allow kubectl get to fetch multiple resource types

Like Delete, which can now run over multiple types:

    kubectl delete pods,services -l name=foo

Get should be able to span items for label selection

    kubectl get pods,services -l name=foo
This commit is contained in:
Clayton Coleman
2014-12-30 19:42:55 -05:00
parent b8333bdeef
commit 2151afe334
9 changed files with 672 additions and 166 deletions

View File

@@ -22,6 +22,8 @@ import (
"io"
"io/ioutil"
"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/kubectl"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
@@ -66,12 +68,12 @@ func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
}
type testPrinter struct {
Obj runtime.Object
Err error
Objects []runtime.Object
Err error
}
func (t *testPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
t.Obj = obj
t.Objects = append(t.Objects, obj)
fmt.Fprintf(out, "%#v", obj)
return t.Err
}
@@ -112,6 +114,23 @@ func NewTestFactory() (*Factory, *testFactory, runtime.Codec) {
}, t, codec
}
func NewAPIFactory() (*Factory, *testFactory, runtime.Codec) {
t := &testFactory{}
return &Factory{
Mapper: latest.RESTMapper,
Typer: api.Scheme,
RESTClient: func(*cobra.Command, *meta.RESTMapping) (kubectl.RESTClient, error) {
return t.Client, t.Err
},
Describer: func(*cobra.Command, *meta.RESTMapping) (kubectl.Describer, error) {
return t.Describer, t.Err
},
Printer: func(cmd *cobra.Command, mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error) {
return t.Printer, t.Err
},
}, t, latest.Codec
}
func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
}