Startup previously enabled addons

pull/6471/head
tstromberg 2020-02-03 10:49:40 -08:00
parent 6cc2fc8e49
commit bcc186b908
2 changed files with 29 additions and 16 deletions

View File

@ -367,8 +367,12 @@ func runStart(cmd *cobra.Command, args []string) {
bootstrapCluster(bs, cr, mRunner, mc, preExists, isUpgrade) bootstrapCluster(bs, cr, mRunner, mc, preExists, isUpgrade)
configureMounts() configureMounts()
// enable addons // enable addons, both old and new!
addons.Start(viper.GetString(config.MachineProfile), addonList) existingAddons := map[string]bool{}
if existing != nil && existing.Addons != nil {
existingAddons = existing.Addons
}
addons.Start(viper.GetString(config.MachineProfile), existingAddons, addonList)
if err = cacheAndLoadImagesInConfig(); err != nil { if err = cacheAndLoadImagesInConfig(); err != nil {
out.T(out.FailureType, "Unable to load cached images from config file.") out.T(out.FailureType, "Unable to load cached images from config file.")

View File

@ -19,6 +19,7 @@ package addons
import ( import (
"fmt" "fmt"
"path" "path"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -68,8 +69,7 @@ func Set(name, value, profile string) error {
return errors.Wrap(err, "running callbacks") return errors.Wrap(err, "running callbacks")
} }
glog.Infof("Writing new config for %q ...", profile) glog.Infof("Writing out %q config to set %s=%v...", profile, name, value)
// Write the value
return config.Write(profile, c) return config.Write(profile, c)
} }
@ -263,33 +263,42 @@ func enableOrDisableStorageClasses(name, val, profile string) error {
} }
// Start enables the default addons for a profile, plus any additional // Start enables the default addons for a profile, plus any additional
func Start(profile string, additional []string) { func Start(profile string, toEnable map[string]bool, additional []string) {
start := time.Now() start := time.Now()
glog.Infof("enableAddons") glog.Infof("enableAddons start: toEnable=%v, additional=%s", toEnable, additional)
defer func() { defer func() {
glog.Infof("enableAddons completed in %s", time.Since(start)) glog.Infof("enableAddons completed in %s", time.Since(start))
}() }()
toEnable := []string{}
// Apply addons that are enabled by default // Get the default values of any addons not saved to our config
for name, a := range assets.Addons { for name, a := range assets.Addons {
enabled, err := a.IsEnabled(profile) defaultVal, err := a.IsEnabled(profile)
if err != nil { if err != nil {
glog.Errorf("is-enabled failed for %q: %v", a.Name(), err) glog.Errorf("is-enabled failed for %q: %v", a.Name(), err)
continue continue
} }
if enabled {
toEnable = append(toEnable, name) _, exists := toEnable[name]
if !exists {
toEnable[name] = defaultVal
} }
} }
toEnable = append(toEnable, additional...) // Apply new addons
if len(toEnable) == 0 { for _, name := range additional {
return toEnable[name] = true
} }
out.T(out.AddonEnable, "Enabling addons: {{.addons}}", out.V{"addons": strings.Join(toEnable, ", ")}) toEnableList := []string{}
for _, a := range toEnable { for k, v := range toEnable {
if v {
toEnableList = append(toEnableList, k)
}
}
sort.Strings(toEnableList)
out.T(out.AddonEnable, "Enabling addons: {{.addons}}", out.V{"addons": strings.Join(toEnableList, ", ")})
for _, a := range toEnableList {
err := Set(a, "true", profile) err := Set(a, "true", profile)
if err != nil { if err != nil {
// Intentionally non-fatal // Intentionally non-fatal