Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save old cluster config in memory before overwriting #3450

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ func runStart(cmd *cobra.Command, args []string) {
GPU: viper.GetBool(gpu),
}

// Load current profile cluster config from file, before overwriting it with the new state
oldConfig, err := cfg.Load()
if err != nil && !os.IsNotExist(err) {
glog.Errorln("Error loading profile config: ", err)
}

// Write profile cluster configuration to file
clusterConfig := cfg.Config{
MachineConfig: config,
Expand Down Expand Up @@ -198,14 +204,8 @@ func runStart(cmd *cobra.Command, args []string) {
if strings.Compare(selectedKubernetesVersion, "") == 0 {
selectedKubernetesVersion = constants.DefaultKubernetesVersion
}
// Load profile cluster config from file
cc, err := cfg.Load()
if err != nil && !os.IsNotExist(err) {
glog.Errorln("Error loading profile config: ", err)
}

if err == nil {
oldKubernetesVersion, err := semver.Make(strings.TrimPrefix(cc.KubernetesConfig.KubernetesVersion, version.VersionPrefix))
if oldConfig != nil {
oldKubernetesVersion, err := semver.Make(strings.TrimPrefix(oldConfig.KubernetesConfig.KubernetesVersion, version.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/minikube/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,35 @@ func GetMachineName() string {
}

// Load loads the kubernetes and machine config for the current machine
func Load() (Config, error) {
func Load() (*Config, error) {
return DefaultLoader.LoadConfigFromFile(GetMachineName())
}

// Loader loads the kubernetes and machine config based on the machine profile name
type Loader interface {
LoadConfigFromFile(profile string) (Config, error)
LoadConfigFromFile(profile string) (*Config, error)
}

type simpleConfigLoader struct{}

var DefaultLoader Loader = &simpleConfigLoader{}

func (c *simpleConfigLoader) LoadConfigFromFile(profile string) (Config, error) {
func (c *simpleConfigLoader) LoadConfigFromFile(profile string) (*Config, error) {
var cc Config

path := constants.GetProfileFile(profile)

if _, err := os.Stat(path); os.IsNotExist(err) {
return cc, err
return nil, err
}

data, err := ioutil.ReadFile(path)
if err != nil {
return cc, err
return nil, err
}

if err := json.Unmarshal(data, &cc); err != nil {
return cc, err
return nil, err
}
return cc, nil
return &cc, nil
}
4 changes: 2 additions & 2 deletions pkg/minikube/tunnel/cluster_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func (m *clusterInspector) getStateAndRoute() (HostState, *Route, error) {
if err != nil {
return hostState, nil, err
}
var c config.Config
var c *config.Config
c, err = m.configLoader.LoadConfigFromFile(m.machineName)
if err != nil {
err = errors.Wrapf(err, "error loading config for %s", m.machineName)
return hostState, nil, err
}

var route *Route
route, err = getRoute(h, c)
route, err = getRoute(h, *c)
if err != nil {
err = errors.Wrapf(err, "error getting route info for %s", m.machineName)
return hostState, nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/tunnel/cluster_inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestMinikubeCheckReturnsHostInformation(t *testing.T) {
}

configLoader := &stubConfigLoader{
c: config.Config{
c: &config.Config{
KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: "96.0.0.0/12",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/tunnel/test_doubles.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ func (r *fakeRouter) Inspect(route *Route) (exists bool, conflict string, overla
}

type stubConfigLoader struct {
c config.Config
c *config.Config
e error
}

func (l *stubConfigLoader) LoadConfigFromFile(profile string) (config.Config, error) {
func (l *stubConfigLoader) LoadConfigFromFile(profile string) (*config.Config, error) {
return l.c, l.e
}
4 changes: 2 additions & 2 deletions pkg/minikube/tunnel/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func TestTunnel(t *testing.T) {
},
}
configLoader := &stubConfigLoader{
c: config.Config{
c: &config.Config{
KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: tc.serviceCIDR,
}},
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestErrorCreatingTunnel(t *testing.T) {
}

configLoader := &stubConfigLoader{
c: config.Config{
c: &config.Config{
KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: "10.96.0.0/12",
}},
Expand Down