diff --git a/kubetest2/internal/deployers/eksapi/deployer.go b/kubetest2/internal/deployers/eksapi/deployer.go index cc46021b7..e813d5c30 100644 --- a/kubetest2/internal/deployers/eksapi/deployer.go +++ b/kubetest2/internal/deployers/eksapi/deployer.go @@ -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") @@ -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 diff --git a/kubetest2/internal/deployers/eksapi/nodegroup.go b/kubetest2/internal/deployers/eksapi/nodegroup.go index fcd3b50d0..6b16b3637 100644 --- a/kubetest2/internal/deployers/eksapi/nodegroup.go +++ b/kubetest2/internal/deployers/eksapi/nodegroup.go @@ -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 { @@ -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) } } @@ -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 {