Skip to content

Commit 374bcb2

Browse files
committed
fix podcidr route still use join ip as src ip
Signed-off-by: clyi <clyi@alauda.io>
1 parent 54021bf commit 374bcb2

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

pkg/daemon/controller_linux.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,26 +401,30 @@ func routeDiff(nodeNicRoutes, allRoutes []netlink.Route, cidrs, joinCIDR []strin
401401
}
402402

403403
found := false
404+
_, cidrNet, _ := net.ParseCIDR(c)
404405
for _, ar := range allRoutes {
405-
if ar.Dst != nil && ar.Dst.String() == c {
406-
// route already exist
407-
found = true
408-
break
406+
if ar.Dst != nil && ar.Dst.String() == cidrNet.String() {
407+
if slices.Contains(joinCIDR, cidrNet.String()) {
408+
// Only compare Dst for join subnets
409+
found = true
410+
klog.V(3).Infof("[routeDiff] joinCIDR route already exists in allRoutes: %v", ar)
411+
break
412+
} else if (ar.Src == nil && src == nil) || (ar.Src != nil && src != nil && ar.Src.Equal(src)) {
413+
// For non-join subnets, both Dst and Src must be the same
414+
found = true
415+
klog.V(3).Infof("[routeDiff] route already exists in allRoutes: %v", ar)
416+
break
417+
}
409418
}
410419
}
411420
if found {
412421
continue
413422
}
414423
for _, r := range nodeNicRoutes {
415-
if r.Dst == nil || r.Dst.String() != c {
424+
if r.Dst == nil || r.Dst.String() != cidrNet.String() {
416425
continue
417426
}
418-
if src == nil {
419-
if r.Src == nil {
420-
found = true
421-
break
422-
}
423-
} else if src.Equal(r.Src) {
427+
if (src == nil && r.Src == nil) || (src != nil && r.Src != nil && src.Equal(r.Src)) {
424428
found = true
425429
break
426430
}

0 commit comments

Comments
 (0)