mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user