Merge branch '21603-ec2-subnet-error'
[arvados.git] / lib / cloud / ec2 / ec2.go
index 9a3f784b51e77d9d90d214183fb071b1190a39c6..6251f18df0fc485f876e710731875a9e9061e14d 100644 (file)
@@ -13,6 +13,7 @@ import (
        "encoding/json"
        "fmt"
        "math/big"
+       "regexp"
        "strconv"
        "strings"
        "sync"
@@ -713,6 +714,8 @@ func isErrorQuota(err error) bool {
        return false
 }
 
+var reSubnetSpecificInvalidParameterMessage = regexp.MustCompile(`(?ms).*( subnet |sufficient free [Ii]pv[46] addresses).*`)
+
 // isErrorSubnetSpecific returns true if the problem encountered by
 // RunInstances might be avoided by trying a different subnet.
 func isErrorSubnetSpecific(err error) bool {
@@ -724,7 +727,12 @@ func isErrorSubnetSpecific(err error) bool {
        return strings.Contains(code, "Subnet") ||
                code == "InsufficientInstanceCapacity" ||
                code == "InsufficientVolumeCapacity" ||
-               code == "Unsupported"
+               code == "Unsupported" ||
+               // See TestIsErrorSubnetSpecific for examples of why
+               // we look for substrings in code/message instead of
+               // only using specific codes here.
+               (strings.Contains(code, "InvalidParameter") &&
+                       reSubnetSpecificInvalidParameterMessage.MatchString(aerr.Message()))
 }
 
 // isErrorCapacity returns true if the error indicates lack of