diff --git a/google/metadata.go b/google/metadata.go index 5dc63a67185..230b7a169ec 100644 --- a/google/metadata.go +++ b/google/metadata.go @@ -3,12 +3,14 @@ package google import ( "fmt" "log" + "strings" "google.golang.org/api/compute/v1" ) const FINGERPRINT_RETRIES = 10 -const FINGERPRINT_FAIL = "Invalid fingerprint." + +var FINGERPRINT_FAIL_ERRORS = []string{"Invalid fingerprint.", "Supplied fingerprint does not match current metadata fingerprint."} // Since the google compute API uses optimistic locking, there is a chance // we need to resubmit our updated metadata. To do this, you need to provide @@ -17,11 +19,25 @@ func MetadataRetryWrapper(update func() error) error { attempt := 0 for attempt < FINGERPRINT_RETRIES { err := update() - if err != nil && err.Error() == FINGERPRINT_FAIL { - attempt++ - } else { + if err == nil { + return nil + } + + // Check to see if the error matches any of our fingerprint-related failure messages + var fingerprintError bool + for _, msg := range FINGERPRINT_FAIL_ERRORS { + if strings.Contains(err.Error(), msg) { + fingerprintError = true + break + } + } + + if !fingerprintError { + // Something else went wrong, don't retry return err } + + attempt++ } return fmt.Errorf("Failed to update metadata after %d retries", attempt)