github.com/grahambrereton-form3/tilt@v0.10.18/internal/k8s/ip.go (about) 1 package k8s 2 3 import ( 4 "context" 5 "fmt" 6 "os/exec" 7 "strings" 8 9 "github.com/pkg/errors" 10 ) 11 12 // Some K8s environments expose a single IP for the whole cluster. 13 type NodeIP string 14 15 func DetectNodeIP(ctx context.Context, env Env) (NodeIP, error) { 16 if env != EnvMinikube { 17 return "", nil 18 } 19 20 // TODO(nick): Should this be part of MinikubeClient? 21 cmd := exec.CommandContext(ctx, "minikube", "ip") 22 out, err := cmd.Output() 23 if err != nil { 24 exitErr, isExitErr := err.(*exec.ExitError) 25 if isExitErr { 26 // TODO(nick): Maybe we should automatically run minikube start? 27 return "", fmt.Errorf("Could not read node IP from minikube.\n"+ 28 "Did you forget to run `minikube start`?\n%s", string(exitErr.Stderr)) 29 } 30 return "", errors.Wrap(err, "Could not read node IP from minikube") 31 } 32 33 return NodeIP(strings.TrimSpace(string(out))), nil 34 }