From 8b3118a694e21f967388e8a5c80b9ce7bfced194 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Sat, 8 May 2021 15:15:20 -0700 Subject: [PATCH 1/2] Disallow AMD GPU instance types (e.g. g4ad) --- pkg/lib/aws/ec2.go | 19 +++++++++++++++++++ pkg/types/clusterconfig/cluster_config.go | 8 ++++++++ pkg/types/clusterconfig/errors.go | 10 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/lib/aws/ec2.go b/pkg/lib/aws/ec2.go index 9ca9ef36bc..851be8e2fb 100644 --- a/pkg/lib/aws/ec2.go +++ b/pkg/lib/aws/ec2.go @@ -32,6 +32,8 @@ import ( var _digitsRegex = regexp.MustCompile(`[0-9]+`) +var _gpu_instance_families = strset.New("g", "p") + type ParsedInstanceType struct { Family string Generation int @@ -117,6 +119,23 @@ func IsARMInstance(instanceType string) (bool, error) { return false, nil } +func IsAMDGPUInstance(instanceType string) (bool, error) { + parsedType, err := ParseInstanceType(instanceType) + if err != nil { + return false, err + } + + if !_gpu_instance_families.Has(parsedType.Family) { + return false, nil + } + + if parsedType.Capabilities.Has("a") { + return true, nil + } + + return false, nil +} + func (c *Client) SpotInstancePrice(instanceType string) (float64, error) { result, err := c.EC2().DescribeSpotPriceHistory(&ec2.DescribeSpotPriceHistoryInput{ InstanceTypes: []*string{aws.String(instanceType)}, diff --git a/pkg/types/clusterconfig/cluster_config.go b/pkg/types/clusterconfig/cluster_config.go index cd34c4ff7c..0bac1e602d 100644 --- a/pkg/types/clusterconfig/cluster_config.go +++ b/pkg/types/clusterconfig/cluster_config.go @@ -1269,6 +1269,14 @@ func validateInstanceType(instanceType string) (string, error) { return "", ErrorARMInstancesNotSupported(instanceType) } + isAMDGPU, err := aws.IsAMDGPUInstance(instanceType) + if err != nil { + return "", err + } + if isAMDGPU { + return "", ErrorAMDGPUInstancesNotSupported(instanceType) + } + if err := checkCNISupport(instanceType); err != nil { return "", err } diff --git a/pkg/types/clusterconfig/errors.go b/pkg/types/clusterconfig/errors.go index e238912aab..fa69e95c23 100644 --- a/pkg/types/clusterconfig/errors.go +++ b/pkg/types/clusterconfig/errors.go @@ -47,6 +47,7 @@ const ( ErrSpotPriceGreaterThanMaxPrice = "clusterconfig.spot_price_greater_than_max_price" ErrInstanceTypeNotSupportedByCortex = "clusterconfig.instance_type_not_supported_by_cortex" ErrARMInstancesNotSupported = "clusterconfig.arm_instances_not_supported" + ErrAMDGPUInstancesNotSupported = "clusterconfig.amd_gpu_instances_not_supported" ErrAtLeastOneInstanceDistribution = "clusterconfig.at_least_one_instance_distribution" ErrNoCompatibleSpotInstanceFound = "clusterconfig.no_compatible_spot_instance_found" ErrConfiguredWhenSpotIsNotEnabled = "clusterconfig.configured_when_spot_is_not_enabled" @@ -203,7 +204,14 @@ func ErrorInstanceTypeNotSupportedByCortex(instanceType string) error { func ErrorARMInstancesNotSupported(instanceType string) error { return errors.WithStack(&errors.Error{ Kind: ErrARMInstancesNotSupported, - Message: fmt.Sprintf("ARM-based instances (including %s) are not supported", instanceType), + Message: fmt.Sprintf("ARM-based instances (including %s) are not supported by cortex", instanceType), + }) +} + +func ErrorAMDGPUInstancesNotSupported(instanceType string) error { + return errors.WithStack(&errors.Error{ + Kind: ErrAMDGPUInstancesNotSupported, + Message: fmt.Sprintf("AMD GPU instances (including %s) are not supported by cortex", instanceType), }) } From 0abf624734ca6aec2ed80c784e24d2857941763a Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Sun, 9 May 2021 01:29:23 +0300 Subject: [PATCH 2/2] Don't use underscores in Go names --- pkg/lib/aws/ec2.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/lib/aws/ec2.go b/pkg/lib/aws/ec2.go index 851be8e2fb..8ae55b0cb8 100644 --- a/pkg/lib/aws/ec2.go +++ b/pkg/lib/aws/ec2.go @@ -30,9 +30,10 @@ import ( s "github.com/cortexlabs/cortex/pkg/lib/strings" ) -var _digitsRegex = regexp.MustCompile(`[0-9]+`) - -var _gpu_instance_families = strset.New("g", "p") +var ( + _digitsRegex = regexp.MustCompile(`[0-9]+`) + _gpuInstanceFamilies = strset.New("g", "p") +) type ParsedInstanceType struct { Family string @@ -125,7 +126,7 @@ func IsAMDGPUInstance(instanceType string) (bool, error) { return false, err } - if !_gpu_instance_families.Has(parsedType.Family) { + if !_gpuInstanceFamilies.Has(parsedType.Family) { return false, nil }