Skip to content

Commit

Permalink
Add option to configure extra pod capacity for alternate cnis
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmcavoy committed Apr 15, 2024
1 parent ed7564c commit 1a6b47d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/operator/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Options struct {
VMMemoryOverheadPercent float64
InterruptionQueue string
ReservedENIs int
MaxPodsExtraCapacity int
}

func (o *Options) AddFlags(fs *coreoptions.FlagSet) {
Expand All @@ -54,6 +55,7 @@ func (o *Options) AddFlags(fs *coreoptions.FlagSet) {
fs.Float64Var(&o.VMMemoryOverheadPercent, "vm-memory-overhead-percent", env.WithDefaultFloat64("VM_MEMORY_OVERHEAD_PERCENT", 0.075), "The VM memory overhead as a percent that will be subtracted from the total memory for all instance types.")
fs.StringVar(&o.InterruptionQueue, "interruption-queue", env.WithDefaultString("INTERRUPTION_QUEUE", ""), "Interruption queue is disabled if not specified. Enabling interruption handling may require additional permissions on the controller service account. Additional permissions are outlined in the docs.")
fs.IntVar(&o.ReservedENIs, "reserved-enis", env.WithDefaultInt("RESERVED_ENIS", 0), "Reserved ENIs are not included in the calculations for max-pods or kube-reserved. This is most often used in the VPC CNI custom networking setup https://docs.aws.amazon.com/eks/latest/userguide/cni-custom-network.html.")
fs.IntVar(&o.MaxPodsExtraCapacity, "max-pods-extra-capacity", env.WithDefaultInt("MAX_PODS_EXTRA_CAPACITY", 2), "Extra pod capacity allocatable on nodes due to host networked pods that do not consume ENIs. The default is for aws-cni and kube-proxy pods, which are not included in the calculations for max-pods or kube-reserved.")
}

func (o *Options) Parse(fs *coreoptions.FlagSet, args ...string) error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/operator/options/options_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (o Options) Validate() error {
o.validateVMMemoryOverheadPercent(),
o.validateAssumeRoleDuration(),
o.validateReservedENIs(),
o.validateMaxPodsExtraCapacity(),
o.validateRequiredFields(),
)
}
Expand Down Expand Up @@ -66,6 +67,13 @@ func (o Options) validateReservedENIs() error {
return nil
}

func (o Options) validateMaxPodsExtraCapacity() error {
if o.MaxPodsExtraCapacity < 0 {
return fmt.Errorf("max-pods-extra-capacity cannot be negative")
}
return nil
}

func (o Options) validateRequiredFields() error {
if o.ClusterName == "" {
return fmt.Errorf("missing field, cluster-name")
Expand Down
11 changes: 10 additions & 1 deletion pkg/operator/options/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ var _ = Describe("Options", func() {
"--isolated-vpc",
"--vm-memory-overhead-percent", "0.1",
"--interruption-queue", "env-cluster",
"--reserved-enis", "10")
"--reserved-enis", "10",
"--max-pods-extra-capacity", "1")
Expect(err).ToNot(HaveOccurred())
expectOptionsEqual(opts, test.Options(test.OptionsFields{
AssumeRoleARN: lo.ToPtr("env-role"),
Expand All @@ -77,6 +78,7 @@ var _ = Describe("Options", func() {
VMMemoryOverheadPercent: lo.ToPtr[float64](0.1),
InterruptionQueue: lo.ToPtr("env-cluster"),
ReservedENIs: lo.ToPtr(10),
MaxPodsExtraCapacity: lo.ToPtr(1),
}))
})
It("should correctly fallback to env vars when CLI flags aren't set", func() {
Expand All @@ -89,6 +91,7 @@ var _ = Describe("Options", func() {
os.Setenv("VM_MEMORY_OVERHEAD_PERCENT", "0.1")
os.Setenv("INTERRUPTION_QUEUE", "env-cluster")
os.Setenv("RESERVED_ENIS", "10")
os.Setenv("MAX_PODS_EXTRA_CAPACITY", "1")

// Add flags after we set the environment variables so that the parsing logic correctly refers
// to the new environment variable values
Expand All @@ -105,6 +108,7 @@ var _ = Describe("Options", func() {
VMMemoryOverheadPercent: lo.ToPtr[float64](0.1),
InterruptionQueue: lo.ToPtr("env-cluster"),
ReservedENIs: lo.ToPtr(10),
MaxPodsExtraCapacity: lo.ToPtr(1),
}))
})

Expand Down Expand Up @@ -132,6 +136,10 @@ var _ = Describe("Options", func() {
err := opts.Parse(fs, "--cluster-name", "test-cluster", "--reserved-enis", "-1")
Expect(err).To(HaveOccurred())
})
It("should fail when maxPodsExtraCapacity is negative", func() {
err := opts.Parse(fs, "--cluster-name", "test-cluster", "--max-pods-extra-capacity", "-1")
Expect(err).To(HaveOccurred())
})
})
})

Expand All @@ -146,4 +154,5 @@ func expectOptionsEqual(optsA *options.Options, optsB *options.Options) {
Expect(optsA.VMMemoryOverheadPercent).To(Equal(optsB.VMMemoryOverheadPercent))
Expect(optsA.InterruptionQueue).To(Equal(optsB.InterruptionQueue))
Expect(optsA.ReservedENIs).To(Equal(optsB.ReservedENIs))
Expect(optsA.MaxPodsExtraCapacity).To(Equal(optsB.MaxPodsExtraCapacity))
}
2 changes: 1 addition & 1 deletion pkg/providers/instancetype/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func ENILimitedPods(ctx context.Context, info *ec2.InstanceTypeInfo) *resource.Q
return resource.NewQuantity(0, resource.DecimalSI)
}
addressesPerInterface := *info.NetworkInfo.Ipv4AddressesPerInterface
return resources.Quantity(fmt.Sprint(usableNetworkInterfaces*(addressesPerInterface-1) + 2))
return resources.Quantity(fmt.Sprint(usableNetworkInterfaces*(addressesPerInterface-1) + int64(options.FromContext(ctx).MaxPodsExtraCapacity)))
}

func privateIPv4Address(info *ec2.InstanceTypeInfo) *resource.Quantity {
Expand Down
2 changes: 2 additions & 0 deletions pkg/test/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type OptionsFields struct {
VMMemoryOverheadPercent *float64
InterruptionQueue *string
ReservedENIs *int
MaxPodsExtraCapacity *int
}

func Options(overrides ...OptionsFields) *options.Options {
Expand All @@ -53,5 +54,6 @@ func Options(overrides ...OptionsFields) *options.Options {
VMMemoryOverheadPercent: lo.FromPtrOr(opts.VMMemoryOverheadPercent, 0.075),
InterruptionQueue: lo.FromPtrOr(opts.InterruptionQueue, ""),
ReservedENIs: lo.FromPtrOr(opts.ReservedENIs, 0),
MaxPodsExtraCapacity: lo.FromPtrOr(opts.MaxPodsExtraCapacity, 2),
}
}

0 comments on commit 1a6b47d

Please sign in to comment.