From f5f71f17f9f7d02562421d303821057515ab945b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 1 Dec 2022 14:02:39 -0800 Subject: [PATCH] Satisfy the Is interface with ValidationTimeoutError and change callers of err check Signed-off-by: Jack Andersen --- pkg/instancegroups/instancegroups.go | 9 +++++++++ pkg/instancegroups/rollingupdate.go | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/instancegroups/instancegroups.go b/pkg/instancegroups/instancegroups.go index 0882ca0e52..7abe807f5b 100644 --- a/pkg/instancegroups/instancegroups.go +++ b/pkg/instancegroups/instancegroups.go @@ -54,6 +54,15 @@ func (v *ValidationTimeoutError) Error() string { return fmt.Sprintf("error validating cluster%s: %v", v.Operation, v.Err) } +// Is checks that a given error is a ValidationTimeoutError. +func (v *ValidationTimeoutError) Is(err error) bool { + // Currently all validation timeout errors are equivalent + // If you wish to differentiate, please update the instances of `errors.Is` that check + // this error to take that into account + _, ok := err.(*ValidationTimeoutError) + return ok +} + // promptInteractive asks the user to continue, mostly copied from vendor/google.golang.org/api/examples/gmail.go. func promptInteractive(upgradedHostID, upgradedHostName string) (stopPrompting bool, err error) { stopPrompting = false diff --git a/pkg/instancegroups/rollingupdate.go b/pkg/instancegroups/rollingupdate.go index 96665fb5e8..4db65cc59e 100644 --- a/pkg/instancegroups/rollingupdate.go +++ b/pkg/instancegroups/rollingupdate.go @@ -18,6 +18,7 @@ package instancegroups import ( "context" + stderrors "errors" "fmt" "sort" "sync" @@ -187,7 +188,7 @@ func (c *RollingUpdateCluster) RollingUpdate(groups map[string]*cloudinstances.C for _, k := range sortGroups(apiServerGroups) { err := c.rollingUpdateInstanceGroup(apiServerGroups[k], c.NodeInterval) - if err != nil && exitableError(err) { + if err != nil && isExitableError(err) { return err } @@ -209,7 +210,7 @@ func (c *RollingUpdateCluster) RollingUpdate(groups map[string]*cloudinstances.C for _, k := range sortGroups(nodeGroups) { err := c.rollingUpdateInstanceGroup(nodeGroups[k], c.NodeInterval) - if err != nil && exitableError(err) { + if err != nil && isExitableError(err) { return err } @@ -237,13 +238,12 @@ func sortGroups(groupMap map[string]*cloudinstances.CloudInstanceGroup) []string return groups } -// exitableError inspects an error to determine if the error is +// isExitableError inspects an error to determine if the error is // fatal enough that the rolling update cannot continue. // // For example, if a cluster is unable to be validated by the deadline, then it // is unlikely that it will validate on the next instance roll, so an early exit as a // warning to the user is more appropriate. func isExitableError(err error) bool { - _, ok := err.(*ValidationTimeoutError) - return ok + return stderrors.Is(err, &ValidationTimeoutError{}) }