Skip to content

Commit

Permalink
Update default reserved memory calculation to match new calculation u…
Browse files Browse the repository at this point in the history
…sed in amazon-eks-ami

The reserved memory calculation was recently changed in amazon-eks-ami to be
based 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 property on InstanceTypeInfo to store MaxPodsPerNode
and populates it using the already available data that has been generated into
maxpods.go.

Because the image type specs (cpu, memory) come from an API call the the max
number of pods per node comes from a file in amaxon-eks-ami, there is a chance
that an image type is returned by the API for which there is no corresponding
record in maxpods.go. To handle this, I left the original memory calculation
in place as a fallback that will be used if max pods per node cannot be
determined.

Issue eksctl-io#2395
  • Loading branch information
brianpursley committed Jul 15, 2020
1 parent 9ac389a commit db69fcf
Show file tree
Hide file tree
Showing 6 changed files with 1,305 additions and 827 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
25 changes: 15 additions & 10 deletions pkg/nodebootstrap/reserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type InstanceTypeInfo struct {
Memory int64
// CPU count.
CPU int64
// Max pods per node
MaxPodsPerNode int64
}

// NewInstanceTypeInfo creates a simple version of ec2.InstanceTypeInfo
Expand All @@ -80,6 +82,9 @@ func NewInstanceTypeInfo(ec2info *ec2.InstanceTypeInfo) InstanceTypeInfo {
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 +98,17 @@ 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)
var mib int64
if i.MaxPodsPerNode > 0 {
mib = 11*i.MaxPodsPerNode + minimumMemoryToReserve
} else {
// As a fallback, if MaxPodsPerNode is 0, use the original calculation, which is a progressive calculation based on total memory.
// See https://github.com/awslabs/amazon-eks-ami/blob/ff690788dfaf399e6919eebb59371ee923617df4/files/bootstrap.sh#L150-L181
// which takes it from https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture#node_allocatable
mib = memProgression.calculate(i.Memory, minimumMemoryToReserve)
}
return fmt.Sprintf("%dMi", mib)
}

Expand Down
Loading

0 comments on commit db69fcf

Please sign in to comment.