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 8300be8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
}

podResources := getPodResources(objList)
serviceLog.Info(fmt.Sprintf("loaded pod res, %v", podResources))

Check warning on line 1055 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L1055

Added line #L1055 was not covered by tests

if config.EnableEIPMigrate {
err = netSrv.migrateEIP(ctx, objList)
Expand Down
9 changes: 5 additions & 4 deletions pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,13 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR
}

log := logf.FromContext(ctx)
log.Info(fmt.Sprintf("local request %v", lo))

Check warning on line 326 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L326

Added line #L326 was not covered by tests

expectV4 := 0
expectV6 := 0

if l.enableIPv4 {
ipv4 := l.ipv4.PeekAvailable(cni.PodID, lo.IPv4)
ipv4 := l.ipv4.PeekAvailable(cni.PodID)

Check warning on line 332 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L332

Added line #L332 was not covered by tests
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)

Check warning on line 341 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L341

Added line #L341 was not covered by tests
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)

Check warning on line 456 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L456

Added line #L456 was not covered by tests
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)

Check warning on line 464 in pkg/eni/local.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/local.go#L464

Added line #L464 was not covered by tests
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 {

Check warning on line 131 in pkg/eni/types.go

View check run for this annotation

Codecov / codecov/patch

pkg/eni/types.go#L129-L131

Added lines #L129 - L131 were not covered by tests
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})

Check warning on line 79 in types/daemon/res.go

View check run for this annotation

Codecov / codecov/patch

types/daemon/res.go#L79

Added line #L79 was not covered by tests
}
}
return ret
Expand Down

0 comments on commit 8300be8

Please sign in to comment.