Skip to content

Commit dd9457d

Browse files
authored
Disallow ARM-based instances, which are not currently supported (#1536)
1 parent be9a31a commit dd9457d

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

pkg/lib/aws/ec2.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package aws
1818

1919
import (
2020
"math"
21+
"regexp"
2122
"time"
2223

2324
"github.com/aws/aws-sdk-go/aws"
@@ -28,6 +29,19 @@ import (
2829
s "github.com/cortexlabs/cortex/pkg/lib/strings"
2930
)
3031

32+
// aws instance types take this form: (\w+)([0-9]+)(\w*).(\w+)
33+
// the first group is the instance series, e.g. "m", "t", "g", "inf", ...
34+
// the second group is a version number for that series, e.g. 3, 4, ...
35+
// the third group is optional, and is a set of single-character "flags"
36+
// "g" represents ARM (graviton), "a" for AMD, "n" for fast networking, "d" for fast storage, etc.
37+
// the fourth and final group (after the dot) is the instance size, e.g. "large"
38+
var _armInstanceRegex = regexp.MustCompile(`^\w+[0-9]+\w*g\w*\.\w+$`)
39+
40+
// instanceType must be a valid instance type that exists in AWS, e.g. g4dn.xlarge
41+
func IsARMInstance(instanceType string) bool {
42+
return _armInstanceRegex.MatchString(instanceType)
43+
}
44+
3145
func (c *Client) SpotInstancePrice(region string, instanceType string) (float64, error) {
3246
result, err := c.EC2().DescribeSpotPriceHistory(&ec2.DescribeSpotPriceHistoryInput{
3347
InstanceTypes: []*string{aws.String(instanceType)},

pkg/lib/aws/elb.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ limitations under the License.
1717
package aws
1818

1919
import (
20+
"strings"
21+
2022
"github.com/aws/aws-sdk-go/aws"
2123
"github.com/aws/aws-sdk-go/service/elbv2"
2224
"github.com/cortexlabs/cortex/pkg/lib/errors"
2325
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
2426
)
2527

2628
// https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html
27-
var NLBUnsupportedInstancePrefixes = strset.New("c1", "cc1", "cc2", "cg1", "cg2", "cr1", "g1", "g2", "hi1", "hs1", "m1", "m2", "m3", "t1")
29+
var _nlbUnsupportedInstancePrefixes = strset.New("c1", "cc1", "cc2", "cg1", "cg2", "cr1", "g1", "g2", "hi1", "hs1", "m1", "m2", "m3", "t1")
30+
31+
// instanceType must be a valid instance type that exists in AWS, e.g. g4dn.xlarge
32+
func IsInstanceSupportedByNLB(instanceType string) bool {
33+
instancePrefix := strings.Split(instanceType, ".")[0]
34+
return !_nlbUnsupportedInstancePrefixes.Has(instancePrefix)
35+
}
2836

2937
// returns the the first load balancer which has all of the specified tags, or nil if no load balancers match
3038
func (c *Client) FindLoadBalancer(tags map[string]string) (*elbv2.LoadBalancer, error) {

pkg/lib/aws/servicequotas.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ import (
2727
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
2828
)
2929

30-
var _instancePrefixRegex = regexp.MustCompile(`[a-zA-Z]+`)
31-
var _standardInstancePrefixes = strset.New("a", "c", "d", "h", "i", "m", "r", "t", "z")
32-
var _knownInstancePrefixes = strset.Union(_standardInstancePrefixes, strset.New("p", "g", "inf", "x", "f"))
30+
var _instanceCategoryRegex = regexp.MustCompile(`[a-zA-Z]+`)
31+
var _standardInstanceCategories = strset.New("a", "c", "d", "h", "i", "m", "r", "t", "z")
32+
var _knownInstanceCategories = strset.Union(_standardInstanceCategories, strset.New("p", "g", "inf", "x", "f"))
3333

3434
func (c *Client) VerifyInstanceQuota(instanceType string) error {
35-
instancePrefix := _instancePrefixRegex.FindString(instanceType)
35+
instanceCategory := _instanceCategoryRegex.FindString(instanceType)
3636

3737
// Allow the instance if we don't recognize the type
38-
if !_knownInstancePrefixes.Has(instancePrefix) {
38+
if !_knownInstanceCategories.Has(instanceCategory) {
3939
return nil
4040
}
4141

42-
if _standardInstancePrefixes.Has(instancePrefix) {
43-
instancePrefix = "standard"
42+
if _standardInstanceCategories.Has(instanceCategory) {
43+
instanceCategory = "standard"
4444
}
4545

4646
var cpuLimit *int
@@ -62,7 +62,7 @@ func (c *Client) VerifyInstanceQuota(instanceType string) error {
6262
continue
6363
}
6464

65-
if strings.ToLower(*metricClass) == instancePrefix+"/ondemand" {
65+
if strings.ToLower(*metricClass) == instanceCategory+"/ondemand" {
6666
cpuLimit = pointer.Int(int(*quota.Value)) // quota is specified in number of vCPU permitted per family
6767
return false
6868
}

pkg/types/clusterconfig/clusterconfig.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,14 @@ func checkCortexSupport(instanceMetadata aws.InstanceMetadata) error {
654654
return ErrorInstanceTypeTooSmall()
655655
}
656656

657-
instancePrefix := strings.Split(instanceMetadata.Type, ".")[0]
658-
if aws.NLBUnsupportedInstancePrefixes.Has(instancePrefix) {
657+
if !aws.IsInstanceSupportedByNLB(instanceMetadata.Type) {
659658
return ErrorInstanceTypeNotSupported(instanceMetadata.Type)
660659
}
661660

661+
if aws.IsARMInstance(instanceMetadata.Type) {
662+
return ErrorARMInstancesNotSupported(instanceMetadata.Type)
663+
}
664+
662665
if err := checkCNISupport(instanceMetadata.Type); err != nil {
663666
return err
664667
}

pkg/types/clusterconfig/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
ErrSpotPriceGreaterThanTargetOnDemand = "clusterconfig.spot_price_greater_than_target_on_demand"
3939
ErrSpotPriceGreaterThanMaxPrice = "clusterconfig.spot_price_greater_than_max_price"
4040
ErrInstanceTypeNotSupported = "clusterconfig.instance_type_not_supported"
41+
ErrARMInstancesNotSupported = "clusterconfig.arm_instances_not_supported"
4142
ErrAtLeastOneInstanceDistribution = "clusterconfig.at_least_one_instance_distribution"
4243
ErrNoCompatibleSpotInstanceFound = "clusterconfig.no_compatible_spot_instance_found"
4344
ErrConfiguredWhenSpotIsNotEnabled = "clusterconfig.configured_when_spot_is_not_enabled"
@@ -133,6 +134,13 @@ func ErrorInstanceTypeNotSupported(instanceType string) error {
133134
})
134135
}
135136

137+
func ErrorARMInstancesNotSupported(instanceType string) error {
138+
return errors.WithStack(&errors.Error{
139+
Kind: ErrARMInstancesNotSupported,
140+
Message: fmt.Sprintf("ARM-based instances (including %s) are not supported", instanceType),
141+
})
142+
}
143+
136144
func ErrorConfiguredWhenSpotIsNotEnabled(configKey string) error {
137145
return errors.WithStack(&errors.Error{
138146
Kind: ErrConfiguredWhenSpotIsNotEnabled,

0 commit comments

Comments
 (0)