Repository: keikoproj/instance-manager
Pull request #342 (2022-02-04 01:31:50)

fix: don't set max pods above kubernetes recommended limit
Signed-off-by: Jonah Back <jonah@jonahback.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) Report
> Merging [#342](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) (a8b6295) into [master](https://codecov.io/gh/keikoproj/instance-manager/commit/306c823e7c06f5087b6acc70a0f9df4da78dc51a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) (306c823) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/keikoproj/instance-manager/pull/342/graphs/tree.svg?width=650&height=150&src=pr&token=IJbjmSBliL&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj)](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj)

```diff
@@            Coverage Diff             @@
##           master     #342      +/-   ##
==========================================
+ Coverage   51.09%   51.13%   +0.03%     
==========================================
  Files          33       33              
  Lines        4505     4508       +3     
==========================================
+ Hits         2302     2305       +3     
  Misses       2062     2062              
  Partials      141      141              
```


| [Impacted Files](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) | Coverage Δ | |
|---|---|---|
| [controllers/provisioners/eks/helpers.go](https://codecov.io/gh/keikoproj/instance-manager/pull/342/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj#diff-Y29udHJvbGxlcnMvcHJvdmlzaW9uZXJzL2Vrcy9oZWxwZXJzLmdv) | `91.43% <100.00%> (+0.03%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj). Last update [306c823...a8b6295](https://codecov.io/gh/keikoproj/instance-manager/pull/342?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj).


Patch:
diff --git a/controllers/common/utils.go b/controllers/common/utils.go
index 07dad17..892de8c 100644
--- a/controllers/common/utils.go
+++ b/controllers/common/utils.go
@@ -256,6 +256,13 @@ func StringSliceContains(x, y []string) bool {
 	return true
 }
 
+func Min(a, b int64) int64 {
+	if a < b {
+		return a
+	}
+	return b
+}
+
 func GetLastElementBy(s, sep string) string {
 	sp := strings.Split(s, sep)
 	return sp[len(sp)-1]
diff --git a/controllers/provisioners/eks/helpers.go b/controllers/provisioners/eks/helpers.go
index 87ca462..143f812 100644
--- a/controllers/provisioners/eks/helpers.go
+++ b/controllers/provisioners/eks/helpers.go
@@ -511,7 +511,8 @@ func (ctx *EksInstanceGroupContext) GetComputedBootstrapOptions() *v1alpha1.Boot
 			ipsPerInterface = 16 //Number of ips in a /28 block
 		}
 
-		maxPods = enis*((aws.Int64Value(instanceTypeNetworkInfo.Ipv4AddressesPerInterface)-1)*ipsPerInterface) + hostNetworkPods
+		// Don't set maxPods above Kubernetes-recommended 110 per node for large clusters.
+		maxPods = common.Min(enis*((aws.Int64Value(instanceTypeNetworkInfo.Ipv4AddressesPerInterface)-1)*ipsPerInterface) + hostNetworkPods, 110)
 
 		if configuration.BootstrapOptions == nil {
 			return &v1alpha1.BootstrapOptions{


Test patch:
diff --git a/controllers/provisioners/eks/helpers_test.go b/controllers/provisioners/eks/helpers_test.go
index 71f77be..7329263 100644
--- a/controllers/provisioners/eks/helpers_test.go
+++ b/controllers/provisioners/eks/helpers_test.go
@@ -403,7 +403,7 @@ func TestCustomNetworkingMaxPods(t *testing.T) {
 				CustomNetworkingEnabledAnnotation:                 "true",
 			},
 			bootstrapOptions: nil,
-			expectedMaxPods:  "--max-pods=290",
+			expectedMaxPods:  "--max-pods=110",
 		},
 		{
 			annotations: map[string]string{