Skip to content

Commit 57afc8a

Browse files
committed
update oc env, return resources in list
Running a command such as `oc new-app https://myrepo -o yaml | oc set env -f - MYVAR=value -o yaml` will not return a set of resources in an `api.List`, but rather print them out individually. This prevents all items from being piped to another `oc` command successfully, as only the last item will be parsed. This patch appends all resources to an api.List before printing.
1 parent d942e98 commit 57afc8a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/cmd/cli/cmd/set/env.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/spf13/cobra"
1414
kapi "k8s.io/kubernetes/pkg/api"
15+
"k8s.io/kubernetes/pkg/api/unversioned"
1516
"k8s.io/kubernetes/pkg/fieldpath"
1617
"k8s.io/kubernetes/pkg/kubectl"
1718
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@@ -489,11 +490,20 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
489490
if err != nil {
490491
return err
491492
}
492-
for _, object := range objects {
493-
if err := p.PrintObj(object, out); err != nil {
494-
return err
495-
}
493+
494+
resourceList := &kapi.List{
495+
TypeMeta: unversioned.TypeMeta{
496+
Kind: "List",
497+
APIVersion: outputVersion.Version,
498+
},
499+
ListMeta: unversioned.ListMeta{},
500+
Items: objects,
501+
}
502+
503+
if err := p.PrintObj(resourceList, out); err != nil {
504+
return err
496505
}
506+
497507
return nil
498508
}
499509

0 commit comments

Comments
 (0)