Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws: support arm64 instances #3848

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -390,7 +390,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 @@ -35,6 +35,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 = "2020-12-07"
ec2Arm64Processors = []string{"AWS Graviton Processor", "AWS Graviton2 Processor"}
)

type response struct {
Expand All @@ -50,6 +51,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 @@ -110,6 +112,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 @@ -150,6 +155,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 @@ -77,6 +77,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