Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ENI limit struct #1035

Merged
merged 1 commit into from
Aug 5, 2020
Merged

Refactor ENI limit struct #1035

merged 1 commit into from
Aug 5, 2020

Conversation

mogren
Copy link
Contributor

@mogren mogren commented Jun 16, 2020

Description of changes:

Refactored the two static ENI limit lists to a map from instance type to InstanceTypeLimits. This is a preparation for adding additional limits. Also added some better logging when generating the file and the option to generate a matching eni-max-pods.txt file for the EKS AMI repo by using make generate-max-pods.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mogren mogren force-pushed the refactor-eni-limits branch 2 times, most recently from e8156b6 to 5516566 Compare June 19, 2020 20:35
pkg/awsutils/awsutils.go Outdated Show resolved Hide resolved
pkg/awsutils/awsutils.go Outdated Show resolved Hide resolved
@mogren mogren requested a review from jaypipes June 30, 2020 23:01
@mogren mogren force-pushed the refactor-eni-limits branch 2 times, most recently from 8e4a6ae to 0cb3723 Compare July 15, 2020 20:04
mogren pushed a commit to mogren/amazon-eks-ami that referenced this pull request Jul 15, 2020
@mogren mogren force-pushed the refactor-eni-limits branch 2 times, most recently from 0106208 to 8754f63 Compare July 16, 2020 20:51
mogren pushed a commit to awslabs/amazon-eks-ami that referenced this pull request Jul 24, 2020
@mogren mogren force-pushed the refactor-eni-limits branch 2 times, most recently from 0cefc6a to be4f230 Compare August 3, 2020 18:57
@mogren mogren requested a review from jayanthvn August 4, 2020 02:59
@mogren mogren assigned mogren and unassigned jayanthvn Aug 4, 2020
Copy link
Contributor

@anguslees anguslees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems fine, assuming we want to do this at all. It seems like it might be better to just call DescribeInstanceTypes at CNI startup?

(Maybe keep manuallyAddedLimits, although that just escalates an arms-race - since then we need env vars to override the hardcoded limits, in which case just have the env vars and remove manuallyAddedLimits.)

pkg/awsutils/awsutils.go Show resolved Hide resolved
Makefile Outdated
# Generate eni-max-pods.txt file for EKS AMI
generate-max-pods: GOOS=
generate-max-pods:
GENERATE_MAX_PODS=true go run scripts/gen_vpc_ip_limits.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too fancy. Just (re)generate both output files always.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... The issue here is that the eni-max-pods.txt file actually belongs to the EKS AMI package... I just added the functionality here to generate it, using the same code that already generated the CNI limits. Since these are flags to the Kubelet on startup, it's not as easy to fetch the limits there.

Copy link
Contributor

@anguslees anguslees Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a loop over the results of a single API call - any benefit isn't worth carrying extra unused code. Either we invoke (and therefore exercise) both code paths all the time, or the code path that this repo doesn't care about should be removed. Every conditional multiplies your entire test matrix - fighting complexity is everybody's responsibility!

I haven't dug deeply enough to understand how this glues into the AMI build process, but afaics it's one of:

  • we don't need eni-max-pods.txt from this binary: remove the code branch
  • we need to generate eni-max-pods.txt from this binary during AMI build: generate it always, and .gitignore it from this repo (with a comment).
  • we need to pull the already-generated eni-max-pods.txt from this repo during AMI build: generate it always and commit it to this repo (with a comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anguslees We already have a dependency the other way, where the CNI will download the debug script from the EKS AMI repo. I've changed this PR to use int and to generate both files, checking in misc/eni-max-pods.txt.

Copy link
Contributor

@anguslees anguslees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

ipLimit, ok := InstanceIPsAvailable[cache.instanceType]
// GetENIIPv4Limit return IP address limit per ENI based on EC2 instance type
func (cache *EC2InstanceMetadataCache) GetENIIPv4Limit() (int, error) {
eniLimits, ok := InstanceNetworkingLimits[cache.instanceType]
if !ok {
log.Errorf("Failed to get ENI IP limit due to unknown instance type %s", cache.instanceType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't fallback to DescribeInstanceTypes ?
Do we want to add that in this PR or a followup? (I'm ok with either - this PR doesn't make it worse)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is really a bit hacky, but in GetENILimit() we add the missing instance type to the InstanceNetworkingLimits map, so as long as that function is called first, it always works. That said, we should probably move that part out to a separate function. I'll make a follow up PR.

pkg/awsutils/awsutils.go Show resolved Hide resolved
@mogren mogren merged commit be9ca94 into aws:master Aug 5, 2020
@mogren mogren deleted the refactor-eni-limits branch August 5, 2020 23:24
cryptosguru added a commit to cryptosguru/amazon that referenced this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants