Skip to content

Commit

Permalink
Fix GenKubeConfigFile, move from "cat" command to "scp"
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Nov 12, 2024
1 parent 98f8861 commit 777ee71
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/e2e/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,29 @@ func FetchNodeExternalIP(nodename string) (string, error) {
}

func GenKubeConfigFile(serverName string) (string, error) {
cmd := fmt.Sprintf("vagrant ssh %s -c \"sudo cat /etc/rancher/k3s/k3s.yaml\"", serverName)
kubeConfig, err := RunCommand(cmd)
kubeConfigFile := fmt.Sprintf("kubeconfig-%s", serverName)
cmd := fmt.Sprintf("vagrant scp %s:/etc/rancher/k3s/k3s.yaml ./%s", serverName, kubeConfigFile)
_, err := RunCommand(cmd)
if err != nil {
return "", err
}

kubeConfig, err := os.ReadFile(kubeConfigFile)
if err != nil {
return "", err
}

re := regexp.MustCompile(`(?m)==> vagrant:.*\n`)
kubeConfig = re.ReplaceAllString(kubeConfig, "")
modifiedKubeConfig := re.ReplaceAllString(string(kubeConfig), "")
nodeIP, err := FetchNodeExternalIP(serverName)
if err != nil {
return "", err
}
kubeConfig = strings.Replace(kubeConfig, "127.0.0.1", nodeIP, 1)
kubeConfigFile := fmt.Sprintf("kubeconfig-%s", serverName)
if err := os.WriteFile(kubeConfigFile, []byte(kubeConfig), 0644); err != nil {
modifiedKubeConfig = strings.Replace(modifiedKubeConfig, "127.0.0.1", nodeIP, 1)
if err := os.WriteFile(kubeConfigFile, []byte(modifiedKubeConfig), 0644); err != nil {
return "", err
}

if err := os.Setenv("E2E_KUBECONFIG", kubeConfigFile); err != nil {
return "", err
}
Expand Down

0 comments on commit 777ee71

Please sign in to comment.