Skip to content

Commit

Permalink
Merge pull request #11464 from hakman/automated-cherry-pick-of-#11463…
Browse files Browse the repository at this point in the history
…-upstream-release-1.21

Automated cherry pick of #11463: Allow AWS instance types with multiple architectures
  • Loading branch information
k8s-ci-robot committed May 12, 2021
2 parents 3ee1d2d + c4ee884 commit 5f8f917
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 26 deletions.
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,23 @@ func (c *MockAWSCloud) DescribeInstanceType(instanceType string) (*ec2.InstanceT
}

switch instanceType {
case "c5.large", "m3.medium", "m4.large", "m5.large", "m5.xlarge", "t2.micro", "t2.medium", "t3.medium", "t3.large", "c4.large":
case "c5.large", "m3.medium", "m4.large", "m5.large", "m5.xlarge", "t3.micro", "t3.medium", "t3.large", "c4.large":
info.ProcessorInfo = &ec2.ProcessorInfo{
SupportedArchitectures: []*string{
aws.String("x86_64"),
aws.String(ec2.ArchitectureTypeX8664),
},
}
case "a1.large":
info.ProcessorInfo = &ec2.ProcessorInfo{
SupportedArchitectures: []*string{
aws.String("arm64"),
aws.String(ec2.ArchitectureTypeArm64),
},
}
case "t2.micro", "t2.medium":
info.ProcessorInfo = &ec2.ProcessorInfo{
SupportedArchitectures: []*string{
aws.String(ec2.ArchitectureTypeI386),
aws.String(ec2.ArchitectureTypeX8664),
},
}
}
Expand Down
File renamed without changes.
20 changes: 12 additions & 8 deletions upup/pkg/fi/cloudup/populate_instancegroup_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,19 @@ func MachineArchitecture(cloud fi.Cloud, machineType string) (architectures.Arch
if info.ProcessorInfo == nil || len(info.ProcessorInfo.SupportedArchitectures) == 0 {
return "", fmt.Errorf("error finding architecture info for instance type %q", machineType)
}
arch := fi.StringValue(info.ProcessorInfo.SupportedArchitectures[0])
switch arch {
case ec2.ArchitectureTypeX8664:
return architectures.ArchitectureAmd64, nil
case ec2.ArchitectureTypeArm64:
return architectures.ArchitectureArm64, nil
default:
return "", fmt.Errorf("unsupported architecture for instance type %q: %s", machineType, arch)
var unsupported []string
for _, arch := range info.ProcessorInfo.SupportedArchitectures {
// Return the first found supported architecture, in order of popularity
switch fi.StringValue(arch) {
case ec2.ArchitectureTypeX8664:
return architectures.ArchitectureAmd64, nil
case ec2.ArchitectureTypeArm64:
return architectures.ArchitectureArm64, nil
default:
unsupported = append(unsupported, fi.StringValue(arch))
}
}
return "", fmt.Errorf("unsupported architecture for instance type %q: %v", machineType, unsupported)
default:
// No other clouds are known to support any other architectures at this time
return architectures.ArchitectureAmd64, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/util/pkg/architectures"
)

func buildMinimalNodeInstanceGroup(subnets ...string) *kopsapi.InstanceGroup {
Expand Down Expand Up @@ -77,3 +78,47 @@ func expectErrorFromPopulateInstanceGroup(t *testing.T, cluster *kopsapi.Cluster
t.Fatalf("Expected error %q, got %q", message, actualMessage)
}
}

func TestMachineArchitecture(t *testing.T) {
tests := []struct {
machineType string
arch architectures.Architecture
err error
}{
{
machineType: "t2.micro",
arch: architectures.ArchitectureAmd64,
err: nil,
},
{
machineType: "t3.micro",
arch: architectures.ArchitectureAmd64,
err: nil,
},
{
machineType: "a1.large",
arch: architectures.ArchitectureArm64,
err: nil,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%s-%s", test.machineType, test.arch), func(t *testing.T) {
_, cluster := buildMinimalCluster()
cloud, err := BuildCloud(cluster)
if err != nil {
t.Fatalf("error from BuildCloud: %v", err)
}

arch, err := MachineArchitecture(cloud, test.machineType)
if err != test.err {
t.Errorf("actual error %q differs from expected error %q", err, test.err)
return
}

if arch != test.arch {
t.Errorf("actual architecture %q differs from expected architecture %q", arch, test.arch)
return
}
})
}
}
13 changes: 0 additions & 13 deletions upup/pkg/fi/cloudup/scratchpad

This file was deleted.

0 comments on commit 5f8f917

Please sign in to comment.