refactor saving IP to node

pull/8168/head
Sharif Elgamal 2020-05-19 15:12:05 -07:00
parent 46fe5c4ac1
commit da91c6fee1
3 changed files with 21 additions and 14 deletions

View File

@ -144,8 +144,8 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No
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
}

View File

@ -17,12 +17,15 @@ limitations under the License.
package machine
import (
"fmt"
"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 +111,18 @@ func fastDetectProvisioner(h *host.Host) (libprovision.Provisioner, error) {
return provision.NewBuildrootProvisioner(h.Driver), nil
}
}
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
fmt.Printf("SAVING NEW IP HERE: %s\n", ip)
return config.SaveNode(cfg, n)
}

View File

@ -148,18 +148,7 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (
return h, errors.Wrap(err, "post-start")
}
if err := api.Save(h); err != nil {
return nil, errors.Wrap(err, "save")
}
// Save IP to config file for subsequent use
ip, err := h.Driver.GetIP()
if err != nil {
return h, err
}
n.IP = ip
err = config.SaveNode(cfg, n)
if err != nil {
if err := saveHost(api, h, cfg, n); err != nil {
return h, err
}