MCPcopy Create free account
hub / github.com/Mirantis/cri-dockerd / getOnePodIP

Function getOnePodIP

network/plugins.go:277–315  ·  view source on GitHub ↗
(
	execer utilexec.Interface,
	nsenterPath, netnsPath, interfaceName, addrType string,
)

Source from the content-addressed store, hash-verified

275}
276
277func getOnePodIP(
278 execer utilexec.Interface,
279 nsenterPath, netnsPath, interfaceName, addrType string,
280) (net.IP, error) {
281 // Try to retrieve ip inside container network namespace
282 output, err := execer.Command(
283 nsenterPath,
284 fmt.Sprintf("--net=%s", netnsPath),
285 "-F",
286 "--",
287 "ip",
288 "-o",
289 addrType,
290 "addr",
291 "show",
292 "dev",
293 interfaceName,
294 "scope",
295 "global",
296 ).CombinedOutput()
297 if err != nil {
298 return nil, fmt.Errorf("unexpected command output %s with error: %v", output, err)
299 }
300
301 lines := strings.Split(string(output), "\n")
302 if len(lines) < 1 {
303 return nil, fmt.Errorf("unexpected command output %s", output)
304 }
305 fields := strings.Fields(lines[0])
306 if len(fields) < 4 {
307 return nil, fmt.Errorf("unexpected address output %s ", lines[0])
308 }
309 ip, _, err := net.ParseCIDR(fields[3])
310 if err != nil {
311 return nil, fmt.Errorf("CNI failed to parse ip from output %s due to %v", output, err)
312 }
313
314 return ip, nil
315}
316
317// GetPodIP gets the IP of the pod by inspecting the network info inside the pod's network namespace.
318// we are defaulting to v4 as primary

Callers 1

GetPodIPsFunction · 0.85

Calls 3

lenFunction · 0.85
CombinedOutputMethod · 0.65
CommandMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…