Dump stdin to a temporary file in kubectl replace --force

This commit is contained in:
Marcin Wielgus
2015-07-15 14:10:47 +02:00
parent 8f3c3108b8
commit 866bd7b4e5
4 changed files with 67 additions and 1 deletions

View File

@@ -19,7 +19,9 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/spf13/cobra"
@@ -131,6 +133,22 @@ func forceReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
return err
}
for i, filename := range filenames {
if filename == "-" {
tempDir, err := ioutil.TempDir("", "kubectl_replace_")
if err != nil {
return err
}
defer os.RemoveAll(tempDir)
tempFilename := filepath.Join(tempDir, "resource.stdin")
err = cmdutil.DumpReaderToFile(os.Stdin, tempFilename)
if err != nil {
return err
}
filenames[i] = tempFilename
}
}
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
ContinueOnError().