(nsPath string)
| 224 | } |
| 225 | |
| 226 | func getNetworkNamespaceIPs(nsPath string) []string { |
| 227 | ips := []string{} |
| 228 | sandboxNs, err := netns.GetFromPath(nsPath) |
| 229 | if err != nil { |
| 230 | return ips |
| 231 | } |
| 232 | // to avoid golang problem with goroutines we create the socket in the |
| 233 | // namespace and use it directly |
| 234 | nhNs, err := netlink.NewHandleAt(sandboxNs) |
| 235 | if err != nil { |
| 236 | return ips |
| 237 | } |
| 238 | |
| 239 | // there is a convention the interface inside the Pod is always named eth0 |
| 240 | // internal/cri/server/helpers.go: defaultIfName = "eth0" |
| 241 | nsLink, err := nhNs.LinkByName("eth0") |
| 242 | if err != nil { |
| 243 | return ips |
| 244 | } |
| 245 | addrs, err := nhNs.AddrList(nsLink, netlink.FAMILY_ALL) |
| 246 | if err != nil { |
| 247 | return ips |
| 248 | } |
| 249 | for _, addr := range addrs { |
| 250 | // ignore link local and loopback addresses |
| 251 | // those are not added by the CNI |
| 252 | if addr.IP.IsGlobalUnicast() { |
| 253 | ips = append(ips, addr.IP.String()) |
| 254 | } |
| 255 | } |
| 256 | return ips |
| 257 | } |
no test coverage detected
searching dependent graphs…