Skip to content

Commit

Permalink
Merge branch 'master' into ip_alloc_wait
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthvn authored Jul 20, 2022
2 parents 408ba48 + f8d731a commit 9b193f0
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 92 deletions.
68 changes: 34 additions & 34 deletions README.md

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions cmd/aws-k8s-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ func main() {

func _main() int {
//Do not add anything before initializing logger
logConfig := logger.Configuration{
LogLevel: logger.GetLogLevel(),
LogLocation: logger.GetLogLocation(),
}
log := logger.New(&logConfig)
log := logger.Get()

log.Infof("Starting L-IPAMD %s ...", version.Version)
version.RegisterMetric()
Expand Down
45 changes: 44 additions & 1 deletion misc/eni-max-pods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# This file was generated at 2022-03-29T17:33:52Z
# This file was generated at 2022-06-29T20:20:11Z
#
# The regions queried were:
# - ap-northeast-1
Expand Down Expand Up @@ -110,6 +110,7 @@ c6a.48xlarge 737
c6a.4xlarge 234
c6a.8xlarge 234
c6a.large 29
c6a.metal 737
c6a.xlarge 58
c6g.12xlarge 234
c6g.16xlarge 737
Expand Down Expand Up @@ -147,6 +148,16 @@ c6i.8xlarge 234
c6i.large 29
c6i.metal 737
c6i.xlarge 58
c6id.12xlarge 234
c6id.16xlarge 737
c6id.24xlarge 737
c6id.2xlarge 58
c6id.32xlarge 737
c6id.4xlarge 234
c6id.8xlarge 234
c6id.large 29
c6id.metal 737
c6id.xlarge 58
c7g.12xlarge 234
c7g.16xlarge 737
c7g.2xlarge 58
Expand Down Expand Up @@ -233,6 +244,14 @@ i3en.6xlarge 234
i3en.large 29
i3en.metal 737
i3en.xlarge 58
i4i.16xlarge 737
i4i.2xlarge 58
i4i.32xlarge 737
i4i.4xlarge 234
i4i.8xlarge 234
i4i.large 29
i4i.metal 737
i4i.xlarge 58
im4gn.16xlarge 737
im4gn.2xlarge 58
im4gn.4xlarge 234
Expand Down Expand Up @@ -334,6 +353,7 @@ m6a.48xlarge 737
m6a.4xlarge 234
m6a.8xlarge 234
m6a.large 29
m6a.metal 737
m6a.xlarge 58
m6g.12xlarge 234
m6g.16xlarge 737
Expand Down Expand Up @@ -363,6 +383,16 @@ m6i.8xlarge 234
m6i.large 29
m6i.metal 737
m6i.xlarge 58
m6id.12xlarge 234
m6id.16xlarge 737
m6id.24xlarge 737
m6id.2xlarge 58
m6id.32xlarge 737
m6id.4xlarge 234
m6id.8xlarge 234
m6id.large 29
m6id.metal 737
m6id.xlarge 58
mac1.metal 234
p2.16xlarge 234
p2.8xlarge 234
Expand All @@ -372,6 +402,7 @@ p3.2xlarge 58
p3.8xlarge 234
p3dn.24xlarge 737
p4d.24xlarge 737
p4de.24xlarge 737
r3.2xlarge 58
r3.4xlarge 234
r3.8xlarge 234
Expand Down Expand Up @@ -472,6 +503,16 @@ r6i.8xlarge 234
r6i.large 29
r6i.metal 737
r6i.xlarge 58
r6id.12xlarge 234
r6id.16xlarge 737
r6id.24xlarge 737
r6id.2xlarge 58
r6id.32xlarge 737
r6id.4xlarge 234
r6id.8xlarge 234
r6id.large 29
r6id.metal 737
r6id.xlarge 58
t1.micro 4
t2.2xlarge 44
t2.large 35
Expand Down Expand Up @@ -534,12 +575,14 @@ x2gd.xlarge 58
x2idn.16xlarge 737
x2idn.24xlarge 737
x2idn.32xlarge 737
x2idn.metal 737
x2iedn.16xlarge 737
x2iedn.24xlarge 737
x2iedn.2xlarge 58
x2iedn.32xlarge 737
x2iedn.4xlarge 234
x2iedn.8xlarge 234
x2iedn.metal 737
x2iedn.xlarge 58
x2iezn.12xlarge 737
x2iezn.2xlarge 58
Expand Down
45 changes: 44 additions & 1 deletion pkg/awsutils/vpc_ip_resource_limit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ func (c *IPAMContext) decreaseDatastorePool(interval time.Duration) {

// tryFreeENI always tries to free one ENI
func (c *IPAMContext) tryFreeENI() {
if c.isTerminating() {
if c.isTerminating() || c.isNodeNonSchedulable() {
log.Debug("AWS CNI is terminating, not detaching any ENIs")
return
}
Expand Down Expand Up @@ -779,7 +779,7 @@ func (c *IPAMContext) increaseDatastorePool(ctx context.Context) {
}
}

if c.isTerminating() {
if c.isTerminating() || c.isNodeNonSchedulable() {
log.Debug("AWS CNI is terminating, will not try to attach any new IPs or ENIs right now")
return
}
Expand Down Expand Up @@ -1809,6 +1809,34 @@ func (c *IPAMContext) isTerminating() bool {
return atomic.LoadInt32(&c.terminating) > 0
}

func (c *IPAMContext) isNodeNonSchedulable() bool {
ctx := context.TODO()

request := types.NamespacedName{
Name: c.myNodeName,
}

node := &corev1.Node{}
// Find my node
err := c.cachedK8SClient.Get(ctx, request, node)
if err != nil {
log.Errorf("Failed to get node while determining schedulability: %v", err)
return false
}
log.Debugf("Node found %q - no of taints - %d", node.Name, len(node.Spec.Taints))
taintToMatch := &corev1.Taint{
Key: "node.kubernetes.io/unschedulable",
Effect: corev1.TaintEffectNoSchedule,
}
for _, taint := range node.Spec.Taints {
if taint.MatchTaint(taintToMatch) {
return true
}
}

return false
}

// GetConfigForDebug returns the active values of the configuration env vars (for debugging purposes).
func GetConfigForDebug() map[string]interface{} {
return map[string]interface{}{
Expand Down
29 changes: 21 additions & 8 deletions pkg/ipamd/ipamd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,16 @@ func TestTryAddIPToENI(t *testing.T) {

warmIPTarget := 3
mockContext := &IPAMContext{
awsClient: m.awsutils,
maxIPsPerENI: 14,
maxENI: 4,
warmENITarget: 1,
warmIPTarget: warmIPTarget,
networkClient: m.network,
primaryIP: make(map[string]string),
terminating: int32(0),
rawK8SClient: m.rawK8SClient,
cachedK8SClient: m.cachedK8SClient,
awsClient: m.awsutils,
maxIPsPerENI: 14,
maxENI: 4,
warmENITarget: 1,
warmIPTarget: warmIPTarget,
networkClient: m.network,
primaryIP: make(map[string]string),
terminating: int32(0),
}

mockContext.dataStore = testDatastore()
Expand Down Expand Up @@ -767,6 +769,17 @@ func TestTryAddIPToENI(t *testing.T) {
m.awsutils.EXPECT().GetPrimaryENI().Return(primaryENIid)
m.network.EXPECT().SetupENINetwork(gomock.Any(), secMAC, secDevice, secSubnet)

mockContext.myNodeName = myNodeName

//Create a Fake Node
fakeNode := v1.Node{
TypeMeta: metav1.TypeMeta{Kind: "Node"},
ObjectMeta: metav1.ObjectMeta{Name: myNodeName},
Spec: v1.NodeSpec{},
Status: v1.NodeStatus{},
}
_ = m.cachedK8SClient.Create(ctx, &fakeNode)

mockContext.increaseDatastorePool(ctx)
}

Expand Down
11 changes: 3 additions & 8 deletions pkg/utils/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,17 @@ type Logger interface {

// Get returns an default instance of the zap logger
func Get() Logger {
var logf = &structuredLogger{}
if logf.isEmpty() {
if log == nil {
logConfig := LoadLogConfig()
log = New(logConfig)
return log
log.Info("Initialized new logger as an existing instance was not found")
}
log = logf
return log
}

func (logf *structuredLogger) isEmpty() bool {
return logf.zapLogger == nil
}

//New logger initializes logger
func New(inputLogConfig *Configuration) Logger {
log = inputLogConfig.newZapLogger()
log.Info("Constructed new logger instance")
return log
}
15 changes: 15 additions & 0 deletions pkg/utils/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ func TestEnvLogFilePath(t *testing.T) {
assert.Equal(t, path, GetLogLocation())
}

func TestLoggerGetSameInstance(t *testing.T) {
log1 := Get()
log2 := Get()

assert.True(t, log1 == log2)
}

func TestLoggerNewAndGetSameInstance(t *testing.T) {
logConfig := LoadLogConfig()
log1 := New(logConfig)
log2 := Get()

assert.True(t, log1 == log2)
}

func TestGetLogFileLocationReturnsDefaultPath(t *testing.T) {
defaultPath := "/host/var/log/aws-routed-eni/ipamd.log"
assert.Equal(t, defaultPath, GetLogLocation())
Expand Down
1 change: 1 addition & 0 deletions scripts/gen_vpc_ip_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func addManualLimits(limitMap map[string]awsutils.InstanceTypeLimits) map[string
"c5a.metal": {ENILimit: 15, IPv4Limit: 50, HypervisorType: "unknown", IsBareMetal: true},
"c5ad.metal": {ENILimit: 15, IPv4Limit: 50, HypervisorType: "unknown", IsBareMetal: true},
"p4d.24xlarge": {ENILimit: 15, IPv4Limit: 50, HypervisorType: "unknown", IsBareMetal: false},
"p4de.24xlarge": {ENILimit: 15, IPv4Limit: 50, HypervisorType: "unknown", IsBareMetal: false},
"dl1.24xlarge": {ENILimit: 15, IPv4Limit: 50, HypervisorType: "unknown", IsBareMetal: false},
"c6g.xlarge": {ENILimit: 4, IPv4Limit: 15, HypervisorType: "nitro", IsBareMetal: false},
"c7g.12xlarge": {ENILimit: 8, IPv4Limit: 30, HypervisorType: "nitro", IsBareMetal: false},
Expand Down
Loading

0 comments on commit 9b193f0

Please sign in to comment.