Skip to content

Commit

Permalink
Merge pull request #609 from l1b0k/fix/cal
Browse files Browse the repository at this point in the history
fix: cal max pods
  • Loading branch information
BSWANG authored Apr 18, 2024
2 parents c17a149 + 0327744 commit a74bb3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR

if l.enableIPv4 {
if lo.NoCache {
if len(l.ipv4)+l.allocatingV4 >= l.cap {
return nil, []Trace{{Condition: Full}}
}
expectV4 = 1
} else {
ipv4 := l.ipv4.PeekAvailable(cni.PodID)
Expand All @@ -363,6 +366,9 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR

if l.enableIPv6 {
if lo.NoCache {
if len(l.ipv6)+l.allocatingV6 >= l.cap {
return nil, []Trace{{Condition: Full}}
}
expectV6 = 1
} else {
ipv6 := l.ipv6.PeekAvailable(cni.PodID)
Expand Down
14 changes: 14 additions & 0 deletions pkg/eni/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,17 @@ func TestLocal_DisposeWholeENI(t *testing.T) {
assert.Equal(t, 1, n)
assert.Equal(t, statusDeleting, local.status)
}

func TestLocal_Allocate_NoCache(t *testing.T) {
local := NewLocalTest(&daemon.ENI{ID: "eni-1"}, nil, &types.PoolConfig{MaxIPPerENI: 2, EnableIPv4: true})

request := &LocalIPRequest{NoCache: true}
cni := &daemon.CNI{PodID: "pod-1"}

local.ipv4.Add(NewValidIP(netip.MustParseAddr("192.0.2.1"), false))
local.ipv4.Add(NewValidIP(netip.MustParseAddr("192.0.2.2"), false))

_, resp := local.Allocate(context.Background(), cni, request)

assert.Equal(t, 1, len(resp))
}

0 comments on commit a74bb3d

Please sign in to comment.