Fix kubectl get -f <file> -o <nondefault printer>

Fix kubectl get -f <file> -o <nondefault printer> so it prints all the
objects in the file, instead of just the first one. Also add a test for
this feature.
This commit is contained in:
Andy Goldstein
2017-01-09 14:21:24 -05:00
parent ba611194f7
commit 613ada4cd7
8 changed files with 117 additions and 103 deletions

View File

@@ -307,10 +307,10 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
// 2. if there is a single item and that item is a list, leave it as its specific list
// 3. if there is a single item and it is not a a list, leave it as a single item
var errs []error
singular := false
infos, err := r.IntoSingular(&singular).Infos()
singleItemImplied := false
infos, err := r.IntoSingleItemImplied(&singleItemImplied).Infos()
if err != nil {
if singular {
if singleItemImplied {
return err
}
errs = append(errs, err)
@@ -325,9 +325,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
}
var obj runtime.Object
if singular {
obj = infos[0].Object
} else {
if !singleItemImplied || len(infos) > 1 {
// we have more than one item, so coerce all items into a list
list := &unstructured.UnstructuredList{
Object: map[string]interface{}{
@@ -340,6 +338,8 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
list.Items = append(list.Items, info.Object.(*unstructured.Unstructured))
}
obj = list
} else {
obj = infos[0].Object
}
isList := meta.IsListType(obj)