Skip to content

Commit

Permalink
Merge pull request #118 from BSWANG/features/fix-allocate-ip-over-eni…
Browse files Browse the repository at this point in the history
…-limition

Fix allocate ip over eni limition
  • Loading branch information
BSWANG authored Jun 30, 2020
2 parents 27bd606 + 83e9c98 commit 40d0695
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions daemon/eni-multi-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (f *eniIPFactory) submit() error {
eni.lock.Unlock()
continue
}
logrus.Debugf("submit eniip to the eni backlog: %+v", eni)
eni.pending++
eni.lock.Unlock()
return nil
Expand All @@ -208,6 +209,7 @@ func (f *eniIPFactory) submit() error {

func (f *eniIPFactory) popResult() (ip *types.ENIIP, err error) {
result := <-f.ipResultChan
logrus.Debugf("pop result from resultChan: %+v", result)
if result.ENIIP == nil || result.err != nil {
// There are two error cases:
// Error Case 1. The ENI-associated VSwitch has no available IP for Pod IP allocation.
Expand Down Expand Up @@ -391,8 +393,8 @@ func (f *eniIPFactory) Dispose(res types.NetworkResource) (err error) {
return nil
}

func (f *eniIPFactory) initialENI(eni *ENI) {
rawEni, err := f.eniFactory.CreateWithIPCount(eni.pending)
func (f *eniIPFactory) initialENI(eni *ENI, ipCount int) {
rawEni, err := f.eniFactory.CreateWithIPCount(ipCount)
var ips []net.IP
// eni operate finished
<-f.eniOperChan
Expand Down Expand Up @@ -454,7 +456,8 @@ func (f *eniIPFactory) initialENI(eni *ENI) {
}

eni.lock.Lock()
extraAlloc := eni.pending - len(ips)
logrus.Infof("allocate status on async eni: %+v, pending: %v, ips: %v, backlog: %v",
eni, eni.pending, ips, len(eni.ipBacklog))
for _, ip := range ips {
eniip := &types.ENIIP{
Eni: eni.ENI,
Expand All @@ -466,19 +469,6 @@ func (f *eniIPFactory) initialENI(eni *ENI) {
err: nil,
}
}
for i := 0; i < extraAlloc; i++ {
select {
case eni.ipBacklog <- struct{}{}:
default:
f.ipResultChan <- &ENIIP{
ENIIP: &types.ENIIP{
Eni: nil,
},
err: errors.Errorf("need retry to allocate eni ip: %v", err),
}
}

}

eni.lock.Unlock()
go eni.allocateWorker(f.ipResultChan)
Expand All @@ -503,7 +493,7 @@ func (f *eniIPFactory) createENIAsync(initIPs int) (*ENI, error) {
<-f.maxENI
return nil, fmt.Errorf("trigger ENI throttle, max operating concurrent: %v", maxEniOperating)
}
go f.initialENI(eni)
go f.initialENI(eni, eni.pending)
default:
return nil, fmt.Errorf("max ENI exceeded")
}
Expand Down

0 comments on commit 40d0695

Please sign in to comment.