diff --git a/pkg/bindings/play/play.go b/pkg/bindings/play/play.go index 9ee02a093e..d43923b027 100644 --- a/pkg/bindings/play/play.go +++ b/pkg/bindings/play/play.go @@ -9,6 +9,7 @@ import ( "github.com/containers/podman/v2/pkg/auth" "github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/pkg/errors" ) func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) { @@ -21,11 +22,27 @@ func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.Pla return nil, err } - f, err := os.Open(path) - if err != nil { - return nil, err + var f *os.File + + if path == "-" { + fi, err := os.Stdin.Stat() + if err != nil { + return nil, errors.Wrapf(err, "unable to read from stdin") + } + + if fi.Mode()&os.ModeNamedPipe == 0 { + return nil, errors.New("No data is supplied by a shell pipe but '-' was used as filename") + } + + f = os.Stdin + + } else { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() } - defer f.Close() params, err := options.ToParams() if err != nil { diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 70c7104f1e..4d9683a0bb 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1,6 +1,7 @@ package abi import ( + "bufio" "context" "fmt" "io" @@ -29,9 +30,34 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, path string, options en kubeObject v1.ObjectReference ) - content, err := ioutil.ReadFile(path) - if err != nil { - return nil, err + var content []byte + var err error + + if path == "-" { + fi, err := os.Stdin.Stat() + if err != nil { + return nil, errors.Wrapf(err, "unable to read from stdin") + } + + if fi.Mode()&os.ModeNamedPipe == 0 { + return nil, errors.New("No data is supplied by a shell pipe but '-' was used as filename") + } + + reader := bufio.NewReader(os.Stdin) + + for { + input, err := reader.ReadByte() + if err != nil && err == io.EOF { + break + } + content = append(content, input) + } + + } else { + content, err = ioutil.ReadFile(path) + if err != nil { + return nil, err + } } if err := yaml.Unmarshal(content, &kubeObject); err != nil {