Skip to content

Commit

Permalink
The reserved memory calculation was changed in amazon-eks-ami to be b…
Browse files Browse the repository at this point in the history
…ased on pod density

(11*maxPodsPerNode+255) instead of total memory.
See https://github.com/awslabs/amazon-eks-ami/blob/21426e27e3845319dbca92e7df32e5c4b984a1d1/files/bootstrap.sh#L163

This commit introduces a new MaxPodsPerNode property on InstanceTypeInfo and populates it
using the data from maxpods.go so that it will be available for calculating the default memory
to reserve. It removes the Memory property from InstanceTypeInfo because it is no longer needed.

This commit also updates related unit tests. It fixes some unit tests which reference instance types which no
longer exist and adds a check to make sure instance types which are expected to exist actually exist, and those
which are not expected to exist do not exist.

Issue #2395
  • Loading branch information
brianpursley committed Jul 16, 2020
1 parent 9ac389a commit 9880f77
Show file tree
Hide file tree
Showing 7 changed files with 1,026 additions and 852 deletions.
2 changes: 1 addition & 1 deletion pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func completeKubeletConfig(kubeletConfigAssetContent []byte, clusterDNS string)
"kubeReserved:\n" +
" cpu: 70m\n" +
" ephemeral-storage: 1Gi\n" +
" memory: 1843Mi\n"
" memory: 574Mi\n"
}

var _ = Describe("CloudFormation template builder API", func() {
Expand Down
32 changes: 10 additions & 22 deletions pkg/nodebootstrap/reserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ type progression []struct {
}

var (
memProgression = progression{
{upper: 4096, fraction: 0.25},
{upper: 8192, fraction: 0.20},
{upper: 16384, fraction: 0.10},
{upper: 131072, fraction: 0.06},
{upper: math.MaxInt64, fraction: 0.02},
}
cpuProgression = progression{
{upper: 1000, fraction: 0.06},
{upper: 2000, fraction: 0.01},
Expand Down Expand Up @@ -58,10 +51,10 @@ type InstanceTypeInfo struct {
// Storage (ephemeral) available (GiB).
// Is 0 if not supported or none available.
Storage int64
// Memory available (MiB).
Memory int64
// CPU count.
CPU int64
// Max pods per node.
MaxPodsPerNode int64
}

// NewInstanceTypeInfo creates a simple version of ec2.InstanceTypeInfo
Expand All @@ -74,12 +67,12 @@ func NewInstanceTypeInfo(ec2info *ec2.InstanceTypeInfo) InstanceTypeInfo {
if aws.BoolValue(ec2info.InstanceStorageSupported) && ec2info.InstanceStorageInfo != nil {
i.Storage = aws.Int64Value(ec2info.InstanceStorageInfo.TotalSizeInGB)
}
if ec2info.MemoryInfo != nil {
i.Memory = aws.Int64Value(ec2info.MemoryInfo.SizeInMiB)
}
if ec2info.VCpuInfo != nil {
i.CPU = aws.Int64Value(ec2info.VCpuInfo.DefaultVCpus)
}
if maxPodsPerNode, exists := maxPodsPerNodeType[*ec2info.InstanceType]; exists {
i.MaxPodsPerNode = int64(maxPodsPerNode)
}
return i
}

Expand All @@ -93,17 +86,12 @@ func (i InstanceTypeInfo) DefaultStorageToReserve() string {

// DefaultMemoryToReserve returns how much memory to reserve.
//
// See https://github.com/awslabs/amazon-eks-ami/blob/ff690788dfaf399e6919eebb59371ee923617df4/files/bootstrap.sh#L150-L181
// which takes it form https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture#node_allocatable
//
// 255 Mi of memory for machines with less than 1024Mi of memory
// 25% of the first 4096Mi of memory
// 20% of the next 4096Mi of memory (up to 8192Mi)
// 10% of the next 8192Mi of memory (up to 16384Mi)
// 6% of the next 114688Mi of memory (up to 131072Mi)
// 2% of any memory above 131072Mi
// See https://github.com/awslabs/amazon-eks-ami/blob/21426e27e3845319dbca92e7df32e5c4b984a1d1/files/bootstrap.sh#L154-L165
func (i InstanceTypeInfo) DefaultMemoryToReserve() string {
mib := memProgression.calculate(i.Memory, minimumMemoryToReserve)
mib := 11*i.MaxPodsPerNode + minimumMemoryToReserve
if i.MaxPodsPerNode == 0 {
return ""
}
return fmt.Sprintf("%dMi", mib)
}

Expand Down

0 comments on commit 9880f77

Please sign in to comment.