mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
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:
parent
e51752239c
commit
8e4bc73a74
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user