Satisfy the Is interface with ValidationTimeoutError and change callers of err check

Signed-off-by: Jack Andersen <jandersen@plaid.com>
This commit is contained in:
Jack Andersen 2022-12-01 14:02:39 -08:00
parent 4eb455c6b9
commit f5f71f17f9
No known key found for this signature in database
GPG Key ID: 3F47FBCA70B709C7
2 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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{})
}