Skip to content

Commit

Permalink
Merge pull request kubernetes#3848 from DataDog/aws-arm-support
Browse files Browse the repository at this point in the history
aws: support arm64 instances
  • Loading branch information
k8s-ci-robot authored and Jian Cheung committed Jul 29, 2022
1 parent 464ecd7 commit 6b90120
Show file tree
Hide file tree
Showing 6 changed files with 538 additions and 815 deletions.
3 changes: 2 additions & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ func (m *AwsManager) buildNodeFromTemplate(asg *asg, template *asgTemplate) (*ap
func buildGenericLabels(template *asgTemplate, nodeName string) map[string]string {
result := make(map[string]string)
// TODO: extract it somehow
result[kubeletapis.LabelArch] = cloudprovider.DefaultArch
result[kubeletapis.LabelArch] = template.InstanceType.Architecture
result[apiv1.LabelArchStable] = template.InstanceType.Architecture
result[kubeletapis.LabelOS] = cloudprovider.DefaultOS

result[apiv1.LabelInstanceType] = template.InstanceType.InstanceType
Expand Down
2 changes: 2 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ func TestBuildGenericLabels(t *testing.T) {
InstanceType: "c4.large",
VCPU: 2,
MemoryMb: 3840,
Architecture: cloudprovider.DefaultArch,
},
Region: "us-east-1",
}, "sillyname")
assert.Equal(t, "us-east-1", labels[apiv1.LabelZoneRegion])
assert.Equal(t, "sillyname", labels[apiv1.LabelHostname])
assert.Equal(t, "c4.large", labels[apiv1.LabelInstanceType])
assert.Equal(t, cloudprovider.DefaultArch, labels[kubeletapis.LabelArch])
assert.Equal(t, cloudprovider.DefaultArch, labels[apiv1.LabelArchStable])
assert.Equal(t, cloudprovider.DefaultOS, labels[kubeletapis.LabelOS])
}

Expand Down
14 changes: 14 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
ec2PricingServiceUrlTemplateCN = "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/%s/index.json"
staticListLastUpdateTime = "2022-06-02"
ec2Arm64Processors = []string{"AWS Graviton Processor", "AWS Graviton2 Processor"}
)

type response struct {
Expand All @@ -55,6 +56,7 @@ type productAttributes struct {
VCPU string `json:"vcpu"`
Memory string `json:"memory"`
GPU string `json:"gpu"`
Architecture string `json:"physicalProcessor"`
}

// GenerateEC2InstanceTypes returns a map of ec2 resources
Expand Down Expand Up @@ -108,6 +110,9 @@ func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {
if attr.GPU != "" {
instanceTypes[attr.InstanceType].GPU = parseCPU(attr.GPU)
}
if attr.Architecture != "" {
instanceTypes[attr.InstanceType].Architecture = parseArchitecture(attr.Architecture)
}
}
}
}
Expand Down Expand Up @@ -200,6 +205,15 @@ func parseCPU(cpu string) int64 {
return i
}

func parseArchitecture(archName string) string {
for _, processor := range ec2Arm64Processors {
if archName == processor {
return "arm64"
}
}
return "amd64"
}

// GetCurrentAwsRegion return region of current cluster without building awsManager
func GetCurrentAwsRegion() (string, error) {
region, present := os.LookupEnv("AWS_REGION")
Expand Down
25 changes: 25 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ func TestParseCPU(t *testing.T) {
}
}

func TestParseArchitecture(t *testing.T) {
tests := []struct {
input string
expect string
}{
{
input: "Intel Xeon Platinum 8259 (Cascade Lake)",
expect: "amd64",
},
{
input: "AWS Graviton2 Processor",
expect: "arm64",
},
{
input: "anything default",
expect: "amd64",
},
}

for _, test := range tests {
got := parseArchitecture(test.input)
assert.Equal(t, test.expect, got)
}
}

func TestGetCurrentAwsRegion(t *testing.T) {
region := "us-west-2"
if oldRegion, found := os.LookupEnv("AWS_REGION"); found {
Expand Down
Loading

0 comments on commit 6b90120

Please sign in to comment.