MCPcopy Index your code
hub / github.com/containerd/containerd / getNetworkNamespaceIPs

Function getNetworkNamespaceIPs

integration/nri_linux_test.go:226–257  ·  view source on GitHub ↗
(nsPath string)

Source from the content-addressed store, hash-verified

224}
225
226func 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}

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…