Skip to content

Commit

Permalink
Merge pull request #15762 from shubhbapna/issue-15710
Browse files Browse the repository at this point in the history
Fix `minikube addons list` output for default addons
  • Loading branch information
spowelljr authored Feb 17, 2023
2 parents 90457b9 + f88c6ad commit e066375
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
12 changes: 10 additions & 2 deletions pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func ToEnable(cc *config.ClusterConfig, existing map[string]bool, additional []s
// Get the default values of any addons not saved to our config
for name, a := range assets.Addons {
if _, exists := existing[name]; !exists {
enable[name] = a.IsEnabled(cc)
enable[name] = a.IsEnabledOrDefault(cc)
}
}

Expand All @@ -563,10 +563,18 @@ func ToEnable(cc *config.ClusterConfig, existing map[string]bool, additional []s

// UpdateConfig tries to update config with all enabled addons (not thread-safe).
// Any error will be logged and it will continue.
func UpdateConfig(cc *config.ClusterConfig, enabled []string) {
func UpdateConfigToEnable(cc *config.ClusterConfig, enabled []string) {
for _, a := range enabled {
if err := Set(cc, a, "true"); err != nil {
klog.Errorf("store failed: %v", err)
}
}
}

func UpdateConfigToDisable(cc *config.ClusterConfig) {
for name := range assets.Addons {
if err := Set(cc, name, "false"); err != nil {
klog.Errorf("store failed: %v", err)
}
}
}
24 changes: 22 additions & 2 deletions pkg/addons/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestSetAndSave(t *testing.T) {
}
}

func TestStart(t *testing.T) {
func TestStartWithAddonsEnabled(t *testing.T) {
// this test will write a config.json into MinikubeHome, create a temp dir for it
tests.MakeTempDir(t)

Expand All @@ -133,10 +133,30 @@ func TestStart(t *testing.T) {
go Enable(&wg, cc, toEnable, enabled)
wg.Wait()
if ea, ok := <-enabled; ok {
UpdateConfig(cc, ea)
UpdateConfigToEnable(cc, ea)
}

if !assets.Addons["dashboard"].IsEnabled(cc) {
t.Errorf("expected dashboard to be enabled")
}
}

func TestStartWithAllAddonsDisabled(t *testing.T) {
// this test will write a config.json into MinikubeHome, create a temp dir for it
tests.MakeTempDir(t)

cc := &config.ClusterConfig{
Name: "start",
CPUs: 2,
Memory: 2500,
KubernetesConfig: config.KubernetesConfig{},
}

UpdateConfigToDisable(cc)

for name := range assets.Addons {
if assets.Addons[name].IsEnabled(cc) {
t.Errorf("expected %s to be disabled", name)
}
}
}
10 changes: 10 additions & 0 deletions pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func (a *Addon) IsEnabled(cc *config.ClusterConfig) bool {
return status
}

return false
}

// IsEnabledOrDefault checks if an Addon is enabled for the given profile. If not found in profile it returns the default state
func (a *Addon) IsEnabledOrDefault(cc *config.ClusterConfig) bool {
status, ok := cc.Addons[a.Name()]
if ok {
return status
}

// Return the default unconfigured state of the addon
return a.enabled
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
if starter.ExistingAddons != nil {
klog.Infof("waiting for cluster config update ...")
if ea, ok := <-enabledAddons; ok {
addons.UpdateConfig(starter.Cfg, ea)
addons.UpdateConfigToEnable(starter.Cfg, ea)
}
} else {
addons.UpdateConfigToDisable(starter.Cfg)
}

// Write enabled addons to the config before completion
Expand Down

0 comments on commit e066375

Please sign in to comment.