caee4a99c9
Vendor updated containers/image and containers/storage, along with any new dependencies they drag in, and updated versions of other dependencies that happen to get pulled in. github.com/coreos/go-systemd/daemon/SdNotify() now takes a boolean to control whether or not it unsets the NOTIFY_SOCKET variable from the calling process's environment. Adapt. github.com/opencontainers/runtime-tools/generate/Generator.AddProcessEnv() now takes the environment variable name and value as two arguments, not one. Adapt. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
32 lines
942 B
Go
32 lines
942 B
Go
package ocicni
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func getContainerIP(nsenterPath, netnsPath, interfaceName, addrType string) (net.IP, error) {
|
|
// Try to retrieve ip inside container network namespace
|
|
output, err := exec.Command(nsenterPath, fmt.Sprintf("--net=%s", netnsPath), "-F", "--",
|
|
"ip", "-o", addrType, "addr", "show", "dev", interfaceName, "scope", "global").CombinedOutput()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Unexpected command output %s with error: %v", output, err)
|
|
}
|
|
|
|
lines := strings.Split(string(output), "\n")
|
|
if len(lines) < 1 {
|
|
return nil, fmt.Errorf("Unexpected command output %s", output)
|
|
}
|
|
fields := strings.Fields(lines[0])
|
|
if len(fields) < 4 {
|
|
return nil, fmt.Errorf("Unexpected address output %s ", lines[0])
|
|
}
|
|
ip, _, err := net.ParseCIDR(fields[3])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("CNI failed to parse ip from output %s due to %v", output, err)
|
|
}
|
|
|
|
return ip, nil
|
|
}
|