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

Add config option for number of ENIs get preallocated #68

Merged
merged 1 commit into from
May 18, 2018

Conversation

liwenwu-amazon
Copy link
Contributor

@liwenwu-amazon liwenwu-amazon commented May 15, 2018

Description of changes

Current Behavior
Today, ipamD dynamically allocate and free ENIs based on the number Pods running on the node.
It allocates one more ENI when the number of available IP addresses goes below the per ENI's secondary IP limit. It can free an ENI when the number of available IP addresses grows more than 2 * per ENI's secondary IP limit.

For example, for c3.xlarge, each ENI have 14 secondary IPs. When there is one ENI attached to the instance(e.g. when the instance is first booted) and after 8 pods just get scheduled to run on this node. The available IPs becomes 6 (14-8) and this will trigger ipamD allocating a new ENI.

Requirements
There are 3 different deployment scenarios requires 3 different triggering threshold:

  • scenario-1: default and same as today's behavior. Let ipamD dynamically allocate and free one ENI at time based on the available IPs
  • scenario-2: allocate all available ENIs and IPs right after the instance is initialized. Once all ENIs are allocated on all nodes, there will be no delay on Pod deployment (compare to scenario-1, that some pods may have to wait for nodes to get new ENI and IPs)
  • scenario-3: do NOT allocate any ENI. And only use secondary IPs from instance's primary ENI.

New Behavior
This PR add config option which allow user to define the number of ENIs get allocated. If the config option is not defined, it is default to today's behavior

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

@liwenwu-amazon liwenwu-amazon requested a review from dbenhur May 16, 2018 00:22
Copy link
Contributor

@dbenhur dbenhur left a comment

Choose a reason for hiding this comment

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

mostly nits, but I'm confused by the threshold. I think we need an issue to make the warm address management driven by desired pool size and move away from eni centric logic.

@@ -117,6 +120,8 @@ func New() (*IPAMContext, error) {

//TODO need to break this function down(comments from CR)
func (c *IPAMContext) nodeInit() error {
ipamdActionsInprogress.WithLabelValues("nodeInit").Add(float64(1))
defer ipamdActionsInprogress.WithLabelValues("nodeInit").Sub(float64(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. Glad to see we're tracking pending actions now.

@@ -260,6 +265,10 @@ func (c *IPAMContext) increaseIPPool() {
return
}
if (c.maxENI > 0) && (c.maxENI == c.dataStore.GetENIs()) {
if c.maxENI < maxENIs {
errString := "desired: " + strconv.FormatInt(int64(maxENIs), 10) + "current: " + strconv.FormatInt(int64(c.maxENI), 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

this would be simpler with sprintf. eg:

errString = fmt.sprintf("desired: %d, current: %d", maxENIs, c.maxENI)

ipamd/ipamd.go Outdated

return ((total - used) <= c.currentMaxAddrsPerENI)
return ((total - used) <= c.currentMaxAddrsPerENI*preAllocENIs)
Copy link
Contributor

Choose a reason for hiding this comment

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

pls put spaces around * for readability.

ipamd/ipamd.go Outdated
total, used := c.dataStore.GetStats()
log.Debugf("IP pool stats: total=%d, used=%d, c.currentMaxAddrsPerENI =%d, c.maxAddrsPerENI = %d, preAllocENIs",
total, used, c.currentMaxAddrsPerENI, c.maxAddrsPerENI, preAllocENIs)
Copy link
Contributor

Choose a reason for hiding this comment

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

We produce this IP pool stats message in multiple locations. Please extract to a function so it stays consistent everywhere.

ipamd/ipamd.go Outdated
total, used, c.currentMaxAddrsPerENI, c.maxAddrsPerENI)

return (total-used > 2*c.currentMaxAddrsPerENI)
return (total-used > (preAllocENIs+1)*c.currentMaxAddrsPerENI)
Copy link
Contributor

Choose a reason for hiding this comment

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

add some whitespace

Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to understand why this is the threshold. Why does pre allocation effect whether we have too many available addrs other than setting a floor? I still think all this management would be better expressed with a desired address-warm-pool-buffer size, and derive eni requirements from that.

ipamd/ipamd.go Outdated
ipMax = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "ip_max",
Help: "The number of maximum IPs can be allocated to the instance",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/number of maximum IPs can/maximum number of IP addresses that can/

Copy link
Contributor

Choose a reason for hiding this comment

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

please correct as advised. this is user facing description, let's get the grammar right.

Copy link

@ofiliz ofiliz May 18, 2018

Choose a reason for hiding this comment

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

These are "private IPv4 addresses". Not "IPs". Even the internal-facing strings/objects should be properly named.

ipamd/ipamd.go Outdated
}

func logPoolStats(total, used, currentMaxAddrsPerENI, maxAddrsPerENI int) {
log.Debugf("IP pool stats: total=%d, used=%d, c.currentMaxAddrsPerENI =%d, c.maxAddrsPerENI = %d",
Copy link
Contributor

Choose a reason for hiding this comment

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

be consistent on your use of spaces around =

ipamd/ipamd.go Outdated

return ((total - used) <= c.currentMaxAddrsPerENI)
return ((total - used) <= c.currentMaxAddrsPerENI*warmENITarget)
Copy link
Contributor

Choose a reason for hiding this comment

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

this would be clearer if you said available := total - used then made the comparison against available. add space around ' * '.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go fmt removes spaces around '*'

ipamd/ipamd.go Outdated
total, used, c.currentMaxAddrsPerENI, c.maxAddrsPerENI)

return (total-used > 2*c.currentMaxAddrsPerENI)
return (total-used > (warmENITarget+1)*c.currentMaxAddrsPerENI)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

ipamd/ipamd.go Outdated
maxENIs, err := c.awsClient.GetENILimit()
enisMax.Set(float64(maxENIs))
maxIPs, err := c.awsClient.GetENIipLimit()
ipMax.Set(float64(maxIPs * int64(maxENIs)))
Copy link
Contributor

Choose a reason for hiding this comment

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

These can get an error which the code completely ignores.

ipamd/ipamd.go Outdated
ipMax = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "ip_max",
Help: "The number of maximum IPs can be allocated to the instance",
Copy link
Contributor

Choose a reason for hiding this comment

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

please correct as advised. this is user facing description, let's get the grammar right.

@liwenwu-amazon liwenwu-amazon force-pushed the preallocate-eni branch 2 times, most recently from 3960987 to 96d2d7a Compare May 18, 2018 21:37
Copy link
Contributor

@dbenhur dbenhur left a comment

Choose a reason for hiding this comment

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

Ship it!

@liwenwu-amazon liwenwu-amazon merged commit 5d6757f into aws:master May 18, 2018
@tvalasek tvalasek mentioned this pull request Jun 19, 2019
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.

3 participants