Skip to content

Commit 5d910e8

Browse files
priyawadhwabalopat
priyawadhwa
authored andcommitted
Save old cluster config in memory before overwriting (#3450)
* Save old cluster config in memory before overwriting In PR #3426, I changed "minikube start" to overwrite the cluster config earlier so that the container runtime could be extracted from it by the buildroot provisioner. This introduced a bug later on, where minikube expected to read the kubernetes version from theold config (which no longer existed, because the config was overwritten). To fix this, I changed the code to store the old version of the config in memory before overwriting it. This should fix #3447
1 parent 1514511 commit 5d910e8

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

cmd/minikube/cmd/start.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func runStart(cmd *cobra.Command, args []string) {
162162
GPU: viper.GetBool(gpu),
163163
}
164164

165+
// Load current profile cluster config from file, before overwriting it with the new state
166+
oldConfig, err := cfg.Load()
167+
if err != nil && !os.IsNotExist(err) {
168+
glog.Errorln("Error loading profile config: ", err)
169+
}
170+
165171
// Write profile cluster configuration to file
166172
clusterConfig := cfg.Config{
167173
MachineConfig: config,
@@ -198,14 +204,8 @@ func runStart(cmd *cobra.Command, args []string) {
198204
if strings.Compare(selectedKubernetesVersion, "") == 0 {
199205
selectedKubernetesVersion = constants.DefaultKubernetesVersion
200206
}
201-
// Load profile cluster config from file
202-
cc, err := cfg.Load()
203-
if err != nil && !os.IsNotExist(err) {
204-
glog.Errorln("Error loading profile config: ", err)
205-
}
206-
207-
if err == nil {
208-
oldKubernetesVersion, err := semver.Make(strings.TrimPrefix(cc.KubernetesConfig.KubernetesVersion, version.VersionPrefix))
207+
if oldConfig != nil {
208+
oldKubernetesVersion, err := semver.Make(strings.TrimPrefix(oldConfig.KubernetesConfig.KubernetesVersion, version.VersionPrefix))
209209
if err != nil {
210210
glog.Errorln("Error parsing version semver: ", err)
211211
}

pkg/minikube/config/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,35 @@ func GetMachineName() string {
9292
}
9393

9494
// Load loads the kubernetes and machine config for the current machine
95-
func Load() (Config, error) {
95+
func Load() (*Config, error) {
9696
return DefaultLoader.LoadConfigFromFile(GetMachineName())
9797
}
9898

9999
// Loader loads the kubernetes and machine config based on the machine profile name
100100
type Loader interface {
101-
LoadConfigFromFile(profile string) (Config, error)
101+
LoadConfigFromFile(profile string) (*Config, error)
102102
}
103103

104104
type simpleConfigLoader struct{}
105105

106106
var DefaultLoader Loader = &simpleConfigLoader{}
107107

108-
func (c *simpleConfigLoader) LoadConfigFromFile(profile string) (Config, error) {
108+
func (c *simpleConfigLoader) LoadConfigFromFile(profile string) (*Config, error) {
109109
var cc Config
110110

111111
path := constants.GetProfileFile(profile)
112112

113113
if _, err := os.Stat(path); os.IsNotExist(err) {
114-
return cc, err
114+
return nil, err
115115
}
116116

117117
data, err := ioutil.ReadFile(path)
118118
if err != nil {
119-
return cc, err
119+
return nil, err
120120
}
121121

122122
if err := json.Unmarshal(data, &cc); err != nil {
123-
return cc, err
123+
return nil, err
124124
}
125-
return cc, nil
125+
return &cc, nil
126126
}

pkg/minikube/tunnel/cluster_inspector.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ func (m *clusterInspector) getStateAndRoute() (HostState, *Route, error) {
6363
if err != nil {
6464
return hostState, nil, err
6565
}
66-
var c config.Config
66+
var c *config.Config
6767
c, err = m.configLoader.LoadConfigFromFile(m.machineName)
6868
if err != nil {
6969
err = errors.Wrapf(err, "error loading config for %s", m.machineName)
7070
return hostState, nil, err
7171
}
7272

7373
var route *Route
74-
route, err = getRoute(h, c)
74+
route, err = getRoute(h, *c)
7575
if err != nil {
7676
err = errors.Wrapf(err, "error getting route info for %s", m.machineName)
7777
return hostState, nil, err

pkg/minikube/tunnel/cluster_inspector_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestMinikubeCheckReturnsHostInformation(t *testing.T) {
6060
}
6161

6262
configLoader := &stubConfigLoader{
63-
c: config.Config{
63+
c: &config.Config{
6464
KubernetesConfig: config.KubernetesConfig{
6565
ServiceCIDR: "96.0.0.0/12",
6666
},

pkg/minikube/tunnel/test_doubles.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ func (r *fakeRouter) Inspect(route *Route) (exists bool, conflict string, overla
8282
}
8383

8484
type stubConfigLoader struct {
85-
c config.Config
85+
c *config.Config
8686
e error
8787
}
8888

89-
func (l *stubConfigLoader) LoadConfigFromFile(profile string) (config.Config, error) {
89+
func (l *stubConfigLoader) LoadConfigFromFile(profile string) (*config.Config, error) {
9090
return l.c, l.e
9191
}

pkg/minikube/tunnel/tunnel_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func TestTunnel(t *testing.T) {
395395
},
396396
}
397397
configLoader := &stubConfigLoader{
398-
c: config.Config{
398+
c: &config.Config{
399399
KubernetesConfig: config.KubernetesConfig{
400400
ServiceCIDR: tc.serviceCIDR,
401401
}},
@@ -446,7 +446,7 @@ func TestErrorCreatingTunnel(t *testing.T) {
446446
}
447447

448448
configLoader := &stubConfigLoader{
449-
c: config.Config{
449+
c: &config.Config{
450450
KubernetesConfig: config.KubernetesConfig{
451451
ServiceCIDR: "10.96.0.0/12",
452452
}},

0 commit comments

Comments
 (0)