|
| 1 | +From 10e9e56f274e072dfac53f90f0ecaa4608896526 Mon Sep 17 00:00:00 2001 |
| 2 | +From: l1b0k <libokang.dev@gmail.com> |
| 3 | +Date: Mon, 23 May 2022 16:35:52 +0800 |
| 4 | +Subject: [PATCH 2/2] node: don't exclude IPs which is already included |
| 5 | + |
| 6 | +if we use node ip for service externalIP, this will cause node ip be excluded |
| 7 | + |
| 8 | +Signed-off-by: l1b0k <libokang.dev@gmail.com> |
| 9 | +--- |
| 10 | + pkg/node/ip_linux.go | 20 +++++++++++++++++++- |
| 11 | + 1 file changed, 19 insertions(+), 1 deletion(-) |
| 12 | + |
| 13 | +diff --git a/pkg/node/ip_linux.go b/pkg/node/ip_linux.go |
| 14 | +index 732f62babe..e1df3344b2 100644 |
| 15 | +--- a/pkg/node/ip_linux.go |
| 16 | ++++ b/pkg/node/ip_linux.go |
| 17 | +@@ -15,6 +15,7 @@ |
| 18 | + package node |
| 19 | + |
| 20 | + import ( |
| 21 | ++ "net" |
| 22 | + "strings" |
| 23 | + |
| 24 | + "github.com/vishvananda/netlink" |
| 25 | +@@ -33,6 +34,9 @@ func initExcludedIPs() { |
| 26 | + if err != nil { |
| 27 | + return |
| 28 | + } |
| 29 | ++ |
| 30 | ++ includedIPs := make(map[string]struct{}) |
| 31 | ++ var toExcludeIPs []net.IP |
| 32 | + for _, l := range links { |
| 33 | + // ... also all down devices since they won't be reachable. |
| 34 | + if l.Attrs().OperState == netlink.OperUp { |
| 35 | +@@ -44,6 +48,13 @@ func initExcludedIPs() { |
| 36 | + } |
| 37 | + } |
| 38 | + if skip { |
| 39 | ++ addr, err := netlink.AddrList(l, netlink.FAMILY_ALL) |
| 40 | ++ if err != nil { |
| 41 | ++ continue |
| 42 | ++ } |
| 43 | ++ for _, a := range addr { |
| 44 | ++ includedIPs[a.IP.String()] = struct{}{} |
| 45 | ++ } |
| 46 | + continue |
| 47 | + } |
| 48 | + } |
| 49 | +@@ -52,7 +63,14 @@ func initExcludedIPs() { |
| 50 | + continue |
| 51 | + } |
| 52 | + for _, a := range addr { |
| 53 | +- excludedIPs = append(excludedIPs, a.IP) |
| 54 | ++ toExcludeIPs = append(toExcludeIPs, a.IP) |
| 55 | ++ } |
| 56 | ++ } |
| 57 | ++ |
| 58 | ++ for _, value := range toExcludeIPs { |
| 59 | ++ _, ok := includedIPs[value.String()] |
| 60 | ++ if !ok { |
| 61 | ++ excludedIPs = append(excludedIPs, value) |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +-- |
| 66 | +2.36.1 |
| 67 | + |
0 commit comments