From 8e4bc73a74a8f887a346f1631e3016545ddea89d Mon Sep 17 00:00:00 2001 From: Kris Date: Fri, 29 Sep 2017 10:01:11 -0700 Subject: [PATCH] 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. --- test/e2e/framework/nodes_util.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/e2e/framework/nodes_util.go b/test/e2e/framework/nodes_util.go index 8ab6e9defe7..c3670be97e7 100644 --- a/test/e2e/framework/nodes_util.go +++ b/test/e2e/framework/nodes_util.go @@ -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 {