The kubeconfig.yaml generated by K3S uses local host as the host name by default. It won't work when running with docker machine. This patch detects if the docker environment is set up with docker machine. If it is, then replace the host name to the IP address of the docker machine.
27 lines
456 B
Go
27 lines
456 B
Go
package run
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func getDockerMachineIp() (string, error) {
|
|
machine := os.ExpandEnv("$DOCKER_MACHINE_NAME")
|
|
|
|
if machine == "" {
|
|
return "", nil
|
|
}
|
|
|
|
dockerMachinePath, err := exec.LookPath("docker-machine")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
out, err := exec.Command(dockerMachinePath, "ip").Output()
|
|
|
|
ipStr := strings.TrimSuffix(string(out), "\n")
|
|
ipStr = strings.TrimSuffix(ipStr, "\r")
|
|
return ipStr, err
|
|
}
|