Skip to content

Commit

Permalink
Add default instance types for managed nodegroups
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Sep 4, 2024
1 parent 893521e commit 3c46d4a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
37 changes: 21 additions & 16 deletions kubetest2/internal/deployers/eksapi/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ func (d *deployer) verifyUpFlags() error {
d.IPFamily = string(ekstypes.IpFamilyIpv4)
klog.V(2).Infof("Using default IP family: %s", d.IPFamily)
}
if d.UnmanagedNodes && d.AMI == "" {
return fmt.Errorf("--ami must be specified for --unmanaged-nodes")
}
if !d.UnmanagedNodes && d.AMI != "" {
return fmt.Errorf("--ami should not be provided without --unmanaged-nodes")
}
if d.UnmanagedNodes {
if d.AMI == "" {
return fmt.Errorf("--ami must be specified for --unmanaged-nodes")
}
if d.AMIType != "" {
return fmt.Errorf("--ami-type should not be provided with --unmanaged-nodes")
}
if d.NodeNameStrategy == "" {
d.NodeNameStrategy = "EC2PrivateDNSName"
klog.V(2).Infof("Using default node name strategy: EC2PrivateDNSName")
Expand All @@ -241,16 +241,21 @@ func (d *deployer) verifyUpFlags() error {
return fmt.Errorf("--node-name-strategy must be one of the following values: ['SessionName', 'EC2PrivateDNSName']")
}
}
}
if d.UnmanagedNodes && d.UserDataFormat == "" {
d.UserDataFormat = "bootstrap.sh"
klog.V(2).Infof("Using default user data format: %s", d.UserDataFormat)
}
if d.UnmanagedNodes && d.EFA && len(d.InstanceTypes) != 1 {
return fmt.Errorf("--efa requires a single instance type")
}
if d.UnmanagedNodes && d.AMIType != "" {
return fmt.Errorf("--ami-type should not be provided with --unmanaged-nodes")
if d.UserDataFormat == "" {
d.UserDataFormat = "bootstrap.sh"
klog.V(2).Infof("Using default user data format: %s", d.UserDataFormat)
}
if d.EFA && len(d.InstanceTypes) != 1 {
return fmt.Errorf("--efa requires a single instance type")
}
} else {
if d.AMI != "" {
return fmt.Errorf("--ami should not be provided without --unmanaged-nodes")
}
if d.AMIType == "" {
d.AMIType = "AL2023_STANDARD_X86_64"
klog.V(2).Infof("Using default AMI type: %s", d.AMIType)
}
}
if d.NodeCreationTimeout == 0 {
d.NodeCreationTimeout = time.Minute * 20
Expand Down
35 changes: 25 additions & 10 deletions kubetest2/internal/deployers/eksapi/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ var (
"t4g.xlarge",
"t4g.large",
}

defaultInstanceTypesByEC2ArchitectureValues = map[ec2types.ArchitectureValues][]string{
ec2types.ArchitectureValuesX8664: defaultInstanceTypes_x86_64,
ec2types.ArchitectureValuesArm64: defaultInstanceTypes_arm64,
}

defaultInstanceTypesByEKSAMITypes = map[ekstypes.AMITypes][]string{
ekstypes.AMITypesAl2X8664: defaultInstanceTypes_x86_64,
ekstypes.AMITypesAl2Arm64: defaultInstanceTypes_arm64,
ekstypes.AMITypesAl2023X8664Standard: defaultInstanceTypes_x86_64,
ekstypes.AMITypesAl2023Arm64Standard: defaultInstanceTypes_arm64,
}
)

type NodegroupManager struct {
Expand All @@ -68,14 +80,11 @@ func (m *NodegroupManager) createNodegroup(infra *Infrastructure, cluster *Clust
return fmt.Errorf("failed to describe AMI when populating default instance types: %s: %v", opts.AMI, err)
} else {
amiArch := out.Images[0].Architecture
switch out.Images[0].Architecture {
case ec2types.ArchitectureValuesX8664:
opts.InstanceTypes = defaultInstanceTypes_x86_64
case ec2types.ArchitectureValuesArm64:
opts.InstanceTypes = defaultInstanceTypes_arm64
default:
return fmt.Errorf("no default instance types known for AMI architecture: %v", out.Images[0].Architecture)
defaultInstanceTypes, ok := defaultInstanceTypesByEC2ArchitectureValues[amiArch]
if !ok {
return fmt.Errorf("no default instance types known for AMI architecture: %v", amiArch)
}
opts.InstanceTypes = defaultInstanceTypes
klog.V(2).Infof("Using default instance types for AMI architecture: %v: %v", amiArch, opts.InstanceTypes)
}
}
Expand All @@ -102,12 +111,18 @@ func (m *NodegroupManager) createManagedNodegroup(infra *Infrastructure, cluster
MaxSize: aws.Int32(int32(opts.Nodes)),
DesiredSize: aws.Int32(int32(opts.Nodes)),
},
}
if opts.AMIType != "" {
input.AmiType = ekstypes.AMITypes(opts.AMIType)
AmiType: ekstypes.AMITypes(opts.AMIType),
}
if len(opts.InstanceTypes) > 0 {
input.InstanceTypes = opts.InstanceTypes
} else {
// managed nodegroups uses a t3.medium by default at the time of writing
// this only supports 17 pods, which can cause some flakes in the k8s e2e suite
defaultInstanceTypes, ok := defaultInstanceTypesByEKSAMITypes[input.AmiType]
if !ok {
return fmt.Errorf("no default instance types known for AmiType: %v", input.AmiType)
}
input.InstanceTypes = defaultInstanceTypes
}
out, err := m.clients.EKS().CreateNodegroup(context.TODO(), &input)
if err != nil {
Expand Down

0 comments on commit 3c46d4a

Please sign in to comment.