create special error to skip addons without erroring out
parent
ca04178ced
commit
06ed3378b9
|
@ -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})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue