Unverified Commit 07c7b7ca authored by Medya Ghazizadeh's avatar Medya Ghazizadeh Committed by GitHub

Merge pull request #8168 from sharifelgamal/ip-save

move node ip save farther down stack
parents 06a3ed32 f0479872
Pipeline #148097109 passed with stage
in 2 minutes and 46 seconds
......@@ -81,7 +81,7 @@ func TestCreateHost(t *testing.T) {
t.Fatal("Machine already exists.")
}
_, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
_, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Fatalf("Error creating host: %v", err)
}
......@@ -122,7 +122,7 @@ func TestStartHostExists(t *testing.T) {
api := tests.NewMockAPI(t)
// Create an initial host.
ih, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
ih, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Fatalf("Error creating host: %v", err)
}
......@@ -142,7 +142,7 @@ func TestStartHostExists(t *testing.T) {
n := config.Node{Name: ih.Name}
// This should pass without calling Create because the host exists already.
h, _, err := StartHost(api, mc, n)
h, _, err := StartHost(api, &mc, &n)
if err != nil {
t.Fatalf("Error starting host: %v", err)
}
......@@ -161,7 +161,7 @@ func TestStartHostErrMachineNotExist(t *testing.T) {
api := tests.NewMockAPI(t)
// Create an incomplete host with machine does not exist error(i.e. User Interrupt Cancel)
api.NotExistError = true
h, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
h, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Fatalf("Error creating host: %v", err)
}
......@@ -175,7 +175,7 @@ func TestStartHostErrMachineNotExist(t *testing.T) {
n := config.Node{Name: h.Name}
// This should pass with creating host, while machine does not exist.
h, _, err = StartHost(api, mc, n)
h, _, err = StartHost(api, &mc, &n)
if err != nil {
if err != constants.ErrMachineMissing {
t.Fatalf("Error starting host: %v", err)
......@@ -188,7 +188,7 @@ func TestStartHostErrMachineNotExist(t *testing.T) {
n.Name = h.Name
// Second call. This should pass without calling Create because the host exists already.
h, _, err = StartHost(api, mc, n)
h, _, err = StartHost(api, &mc, &n)
if err != nil {
t.Fatalf("Error starting host: %v", err)
}
......@@ -207,7 +207,7 @@ func TestStartStoppedHost(t *testing.T) {
RegisterMockDriver(t)
api := tests.NewMockAPI(t)
// Create an initial host.
h, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
h, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Fatalf("Error creating host: %v", err)
}
......@@ -220,7 +220,7 @@ func TestStartStoppedHost(t *testing.T) {
mc := defaultClusterConfig
mc.Name = h.Name
n := config.Node{Name: h.Name}
h, _, err = StartHost(api, mc, n)
h, _, err = StartHost(api, &mc, &n)
if err != nil {
t.Fatal("Error starting host.")
}
......@@ -247,7 +247,7 @@ func TestStartHost(t *testing.T) {
md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}}
provision.SetDetector(md)
h, _, err := StartHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
h, _, err := StartHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Fatal("Error starting host.")
}
......@@ -283,7 +283,7 @@ func TestStartHostConfig(t *testing.T) {
DockerOpt: []string{"param=value"},
}
h, _, err := StartHost(api, cfg, config.Node{Name: "minikube"})
h, _, err := StartHost(api, &cfg, &config.Node{Name: "minikube"})
if err != nil {
t.Fatal("Error starting host.")
}
......@@ -313,7 +313,7 @@ func TestStopHostError(t *testing.T) {
func TestStopHost(t *testing.T) {
RegisterMockDriver(t)
api := tests.NewMockAPI(t)
h, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
h, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Errorf("createHost failed: %v", err)
}
......@@ -332,7 +332,7 @@ func TestStopHost(t *testing.T) {
func TestDeleteHost(t *testing.T) {
RegisterMockDriver(t)
api := tests.NewMockAPI(t)
if _, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"}); err != nil {
if _, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"}); err != nil {
t.Errorf("createHost failed: %v", err)
}
......@@ -347,7 +347,7 @@ func TestDeleteHost(t *testing.T) {
func TestDeleteHostErrorDeletingVM(t *testing.T) {
RegisterMockDriver(t)
api := tests.NewMockAPI(t)
h, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
h, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Errorf("createHost failed: %v", err)
}
......@@ -364,7 +364,7 @@ func TestDeleteHostErrorDeletingFiles(t *testing.T) {
RegisterMockDriver(t)
api := tests.NewMockAPI(t)
api.RemoveError = true
if _, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"}); err != nil {
if _, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"}); err != nil {
t.Errorf("createHost failed: %v", err)
}
......@@ -378,7 +378,7 @@ func TestDeleteHostErrMachineNotExist(t *testing.T) {
api := tests.NewMockAPI(t)
// Create an incomplete host with machine does not exist error(i.e. User Interrupt Cancel)
api.NotExistError = true
_, err := createHost(api, defaultClusterConfig, config.Node{Name: "minikube"})
_, err := createHost(api, &defaultClusterConfig, &config.Node{Name: "minikube"})
if err != nil {
t.Errorf("createHost failed: %v", err)
}
......@@ -409,7 +409,7 @@ func TestStatus(t *testing.T) {
checkState(state.None.String(), m)
if _, err := createHost(api, cc, config.Node{Name: "minikube"}); err != nil {
if _, err := createHost(api, &cc, &config.Node{Name: "minikube"}); err != nil {
t.Errorf("createHost failed: %v", err)
}
......
......@@ -48,14 +48,14 @@ const (
)
// fixHost fixes up a previously configured VM so that it is ready to run Kubernetes
func fixHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.Host, error) {
func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*host.Host, error) {
start := time.Now()
glog.Infof("fixHost starting: %s", n.Name)
defer func() {
glog.Infof("fixHost completed within %s", time.Since(start))
}()
h, err := api.Load(driver.MachineName(cc, n))
h, err := api.Load(driver.MachineName(*cc, *n))
if err != nil {
return h, errors.Wrap(err, "Error loading existing host. Please try running [minikube delete], then run [minikube start] again.")
}
......@@ -72,7 +72,7 @@ func fixHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.
// Avoid reprovisioning "none" driver because provision.Detect requires SSH
if !driver.BareMetal(h.Driver.DriverName()) {
e := engineOptions(cc)
e := engineOptions(*cc)
h.HostOptions.EngineOptions.Env = e.Env
err = provisionDockerMachine(h)
if err != nil {
......@@ -84,7 +84,7 @@ func fixHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.
return h, nil
}
if err := postStartSetup(h, cc); err != nil {
if err := postStartSetup(h, *cc); err != nil {
return h, errors.Wrap(err, "post-start")
}
......@@ -96,8 +96,8 @@ func fixHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.
return h, ensureSyncedGuestClock(h, driverName)
}
func recreateIfNeeded(api libmachine.API, cc config.ClusterConfig, n config.Node, h *host.Host) (*host.Host, error) {
machineName := driver.MachineName(cc, n)
func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.Node, h *host.Host) (*host.Host, error) {
machineName := driver.MachineName(*cc, *n)
machineType := driver.MachineType(cc.Driver)
recreated := false
s, serr := h.Driver.GetState()
......@@ -112,7 +112,7 @@ func recreateIfNeeded(api libmachine.API, cc config.ClusterConfig, n config.Node
if !me || err == constants.ErrMachineMissing {
out.T(out.Shrug, `{{.driver_name}} "{{.cluster}}" {{.machine_type}} is missing, will recreate.`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
demolish(api, cc, n, h)
demolish(api, *cc, *n, h)
glog.Infof("Sleeping 1 second for extra luck!")
time.Sleep(1 * time.Second)
......@@ -144,8 +144,8 @@ func recreateIfNeeded(api libmachine.API, cc config.ClusterConfig, n config.Node
if err := h.Driver.Start(); err != nil {
return h, errors.Wrap(err, "driver start")
}
if err := api.Save(h); err != nil {
return h, errors.Wrap(err, "save")
if err := saveHost(api, h, cc, n); err != nil {
return h, err
}
return h, nil
}
......
......@@ -19,10 +19,12 @@ package machine
import (
"time"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
libprovision "github.com/docker/machine/libmachine/provision"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/provision"
)
......@@ -108,3 +110,18 @@ func fastDetectProvisioner(h *host.Host) (libprovision.Provisioner, error) {
return provision.NewBuildrootProvisioner(h.Driver), nil
}
}
// saveHost is a wrapper around libmachine's Save function to proactively update the node's IP whenever a host is saved
func saveHost(api libmachine.API, h *host.Host, cfg *config.ClusterConfig, n *config.Node) error {
if err := api.Save(h); err != nil {
return errors.Wrap(err, "save")
}
// Save IP to config file for subsequent use
ip, err := h.Driver.GetIP()
if err != nil {
return err
}
n.IP = ip
return config.SaveNode(cfg, n)
}
......@@ -62,8 +62,8 @@ var (
)
// StartHost starts a host VM.
func StartHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*host.Host, bool, error) {
machineName := driver.MachineName(cfg, n)
func StartHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (*host.Host, bool, error) {
machineName := driver.MachineName(*cfg, *n)
// Prevent machine-driver boot races, as well as our own certificate race
releaser, err := acquireMachinesLock(machineName)
......@@ -117,7 +117,7 @@ func engineOptions(cfg config.ClusterConfig) *engine.Options {
return &o
}
func createHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*host.Host, error) {
func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (*host.Host, error) {
glog.Infof("createHost starting for %q (driver=%q)", n.Name, cfg.Driver)
start := time.Now()
defer func() {
......@@ -130,12 +130,12 @@ func createHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*h
See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information.
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
}
showHostInfo(cfg)
showHostInfo(*cfg)
def := registry.Driver(cfg.Driver)
if def.Empty() {
return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.Driver)
}
dd, err := def.Config(cfg, n)
dd, err := def.Config(*cfg, *n)
if err != nil {
return nil, errors.Wrap(err, "config")
}
......@@ -151,7 +151,7 @@ func createHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*h
h.HostOptions.AuthOptions.CertDir = localpath.MiniPath()
h.HostOptions.AuthOptions.StorePath = localpath.MiniPath()
h.HostOptions.EngineOptions = engineOptions(cfg)
h.HostOptions.EngineOptions = engineOptions(*cfg)
cstart := time.Now()
glog.Infof("libmachine.API.Create for %q (driver=%q)", cfg.Name, cfg.Driver)
......@@ -161,13 +161,14 @@ func createHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*h
}
glog.Infof("duration metric: libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart))
if err := postStartSetup(h, cfg); err != nil {
if err := postStartSetup(h, *cfg); err != nil {
return h, errors.Wrap(err, "post-start")
}
if err := api.Save(h); err != nil {
return nil, errors.Wrap(err, "save")
if err := saveHost(api, h, cfg, n); err != nil {
return h, err
}
return h, nil
}
......
......@@ -322,7 +322,7 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to get machine client")
}
host, preExists, err = startHost(m, *cfg, *node)
host, preExists, err = startHost(m, cfg, node)
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to start host")
}
......@@ -342,18 +342,11 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.
out.FailureT("Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.", out.V{"ip": ip})
}
// Save IP to config file for subsequent use
node.IP = ip
err = config.SaveNode(cfg, node)
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "saving node")
}
return runner, preExists, m, host, err
}
// startHost starts a new minikube host using a VM or None
func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*host.Host, bool, error) {
func startHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*host.Host, bool, error) {
host, exists, err := machine.StartHost(api, cc, n)
if err == nil {
return host, exists, nil
......@@ -361,7 +354,7 @@ func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*hos
// NOTE: People get very cranky if you delete their prexisting VM. Only delete new ones.
if !exists {
err := machine.DeleteHost(api, driver.MachineName(cc, n))
err := machine.DeleteHost(api, driver.MachineName(*cc, *n))
if err != nil {
glog.Warningf("delete host: %v", err)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment