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

Fix minikube addons list output for default addons #15762

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 dashboard to be disabled")
shubhbapna marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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