Fix sed command to not try shell redirection

RunCmd uses Go's os/exec library to run commands directly. Since these
are not run through a shell, we can't use shell syntax for piping for
file redirection. The proper way to do that is to create a Command
object and set the Std{in,out,err} pipes appropriately. Luckily sed
can handle the behavior we need without having to manually set this up.
This commit is contained in:
Kris 2017-09-29 10:01:11 -07:00
parent e51752239c
commit 8e4bc73a74

View File

@ -114,10 +114,14 @@ func masterUpgradeKubernetesAnywhere(v string) error {
backupConfigPath := filepath.Join(kaPath, ".config.bak")
updatedConfigPath := filepath.Join(kaPath, fmt.Sprintf(".config-%s", v))
// backup .config to .config.bak
if err := os.Rename(originalConfigPath, backupConfigPath); err != nil {
// modify config with specified k8s version
if _, _, err := RunCmd("sed",
"-i.bak", // writes original to .config.bak
fmt.Sprintf(`s/kubernetes_version=.*$/kubernetes_version=%s/`, v),
originalConfigPath); err != nil {
return err
}
defer func() {
// revert .config.bak to .config
if err := os.Rename(backupConfigPath, originalConfigPath); err != nil {
@ -125,13 +129,6 @@ func masterUpgradeKubernetesAnywhere(v string) error {
}
}()
// modify config with specified k8s version
if _, _, err := RunCmd("sed",
fmt.Sprintf(`s/kubernetes_version=.*$/kubernetes_version=%s/`, v),
backupConfigPath, ">", originalConfigPath); err != nil {
return err
}
// invoke ka upgrade
if _, _, err := RunCmd("make", "-C", TestContext.KubernetesAnywherePath,
"WAIT_FOR_KUBECONFIG=y", "upgrade-master"); err != nil {