Skip to content

Commit

Permalink
fix idempotent issue
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Feb 23, 2024
1 parent 99ddd72 commit 5634388
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR
expectV6 := 0

if l.enableIPv4 {
ipv4 := l.ipv4.PeekAvailable(cni.PodID, lo.IPv4)
log.Info("peek", "cni", cni.PodID, "lo", lo.IPv4.String())
ipv4 := l.ipv4.PeekAvailable(cni.PodID)
if ipv4 == nil && len(l.ipv4)+l.allocatingV4 >= l.cap {
return nil, []Trace{{Condition: Full}}
} else if ipv4 == nil {
Expand All @@ -337,7 +338,7 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR
}

if l.enableIPv6 {
ipv6 := l.ipv6.PeekAvailable(cni.PodID, lo.IPv6)
ipv6 := l.ipv6.PeekAvailable(cni.PodID)
if ipv6 == nil && len(l.ipv6)+l.allocatingV6 >= l.cap {
return nil, []Trace{{Condition: Full}}
} else if ipv6 == nil {
Expand Down Expand Up @@ -452,15 +453,15 @@ func (l *Local) allocWorker(ctx context.Context, cni *daemon.CNI, request *Local
var ip types.IPSet2
var ipv4, ipv6 *IP
if l.enableIPv4 {
ipv4 = l.ipv4.PeekAvailable(cni.PodID, request.IPv4)
ipv4 = l.ipv4.PeekAvailable(cni.PodID)
if ipv4 == nil {
l.cond.Wait()
continue
}
ip.IPv4 = ipv4.ip
}
if l.enableIPv6 {
ipv6 = l.ipv6.PeekAvailable(cni.PodID, request.IPv6)
ipv6 = l.ipv6.PeekAvailable(cni.PodID)
if ipv6 == nil {
l.cond.Wait()
continue
Expand Down
6 changes: 3 additions & 3 deletions pkg/eni/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (s Set) Allocatable() []*IP {
return result
}

func (s Set) PeekAvailable(podID string, prefer netip.Addr) *IP {
if podID != "" && prefer.IsValid() {
if v, ok := s[prefer]; ok {
func (s Set) PeekAvailable(podID string) *IP {
if podID != "" {
for _, v := range s {
if v.podID == podID {
return v
}
Expand Down
2 changes: 1 addition & 1 deletion types/daemon/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (p PodResources) GetResourceItemByType(resType string) []ResourceItem {
var ret []ResourceItem
for _, r := range p.Resources {
if resType == r.Type {
ret = append(ret, ResourceItem{Type: resType, ID: r.ID})
ret = append(ret, ResourceItem{Type: resType, ID: r.ID, ENIID: r.ENIID, ENIMAC: r.ENIMAC, IPv4: r.IPv4, IPv6: r.IPv6})
}
}
return ret
Expand Down

0 comments on commit 5634388

Please sign in to comment.