diff --git a/cmd/minikube/cmd/config/enable.go b/cmd/minikube/cmd/config/enable.go index 788a9477ae..801e64ec3b 100644 --- a/cmd/minikube/cmd/config/enable.go +++ b/cmd/minikube/cmd/config/enable.go @@ -17,6 +17,7 @@ limitations under the License. package config import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -48,7 +49,7 @@ var addonsEnableCmd = &cobra.Command{ viper.Set(config.AddonImages, images) viper.Set(config.AddonRegistries, registries) err := addons.SetAndSave(ClusterFlagValue(), addon, "true") - if err != nil { + if err != nil && !errors.Is(err, addons.ErrSkipThisAddon) { exit.Error(reason.InternalAddonEnable, "enable failed", err) } if addon == "dashboard" { @@ -63,8 +64,9 @@ var addonsEnableCmd = &cobra.Command{ `, out.V{"profileArg": tipProfileArg}) } - - out.Step(style.AddonEnable, "The '{{.addonName}}' addon is enabled", out.V{"addonName": addon}) + if err != nil { + out.Step(style.AddonEnable, "The '{{.addonName}}' addon is enabled", out.V{"addonName": addon}) + } }, } diff --git a/pkg/addons/addons.go b/pkg/addons/addons.go index 47fed71d3c..b0a13f81c2 100644 --- a/pkg/addons/addons.go +++ b/pkg/addons/addons.go @@ -55,6 +55,9 @@ var Force bool = false // Currently only used for gcp-auth var Refresh bool = false +// ErrSkipThisAddon is a special error that tells us to not error out, but to also not mark the addon as enabled +var ErrSkipThisAddon = errors.New("skipping this addon") + // RunCallbacks runs all actions associated to an addon, but does not set it (thread-safe) func RunCallbacks(cc *config.ClusterConfig, name string, value string) error { klog.Infof("Setting %s=%s in profile %q", name, value, cc.Name) @@ -65,11 +68,17 @@ func RunCallbacks(cc *config.ClusterConfig, name string, value string) error { // Run any additional validations for this property if err := run(cc, name, value, a.validations); err != nil { + if errors.Is(err, ErrSkipThisAddon) { + return err + } return errors.Wrap(err, "running validations") } // Run any callbacks for this property if err := run(cc, name, value, a.callbacks); err != nil { + if errors.Is(err, ErrSkipThisAddon) { + return err + } return errors.Wrap(err, "running callbacks") } return nil @@ -92,6 +101,9 @@ func SetAndSave(profile string, name string, value string) error { } if err := RunCallbacks(cc, name, value); err != nil { + if errors.Is(err, ErrSkipThisAddon) { + return err + } return errors.Wrap(err, "run callbacks") } @@ -105,15 +117,18 @@ func SetAndSave(profile string, name string, value string) error { // Runs all the validation or callback functions and collects errors func run(cc *config.ClusterConfig, name string, value string, fns []setFn) error { - var errors []error + var errs []error for _, fn := range fns { err := fn(cc, name, value) if err != nil { - errors = append(errors, err) + if errors.Is(err, ErrSkipThisAddon) { + return ErrSkipThisAddon + } + errs = append(errs, err) } } - if len(errors) > 0 { - return fmt.Errorf("%v", errors) + if len(errs) > 0 { + return fmt.Errorf("%v", errs) } return nil } diff --git a/pkg/addons/addons_gcpauth.go b/pkg/addons/addons_gcpauth.go index 65b613a2f0..23cadfd897 100644 --- a/pkg/addons/addons_gcpauth.go +++ b/pkg/addons/addons_gcpauth.go @@ -342,7 +342,7 @@ func verifyGCPAuthAddon(cc *config.ClusterConfig, name string, val string) error // If we're in GCE and didn't actually start the gcp-auth pods, don't check for them. // We also don't want to actually set the addon as enabled, so just exit completely. if !Force && detect.IsOnGCE() && os.Getenv("GOOGLE_APPLICATION_CREDENTUALS") == "" { - os.Exit(0) + return ErrSkipThisAddon } err = verifyAddonStatusInternal(cc, name, val, "gcp-auth")