diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/network/netconflist.go | 4 | ||||
-rw-r--r-- | libpod/network/netconflist_test.go | 6 | ||||
-rw-r--r-- | libpod/util.go | 30 |
3 files changed, 27 insertions, 13 deletions
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go index d61b96ecb..af25ee59c 100644 --- a/libpod/network/netconflist.go +++ b/libpod/network/netconflist.go @@ -95,6 +95,10 @@ func NewIPAMLocalHostRange(subnet *net.IPNet, ipRange *net.IPNet, gw net.IP) ([] } if gw != nil { hostRange.Gateway = gw.String() + } else { + // Add first ip in subnet as gateway. It is not required + // by cni but should be included because of network inspect. + hostRange.Gateway = CalcGatewayIP(subnet).String() } ranges = append(ranges, hostRange) return ranges, nil diff --git a/libpod/network/netconflist_test.go b/libpod/network/netconflist_test.go index 6bf1a9777..5ff733f0f 100644 --- a/libpod/network/netconflist_test.go +++ b/libpod/network/netconflist_test.go @@ -51,7 +51,8 @@ func TestNewIPAMLocalHostRange(t *testing.T) { subnet: &net.IPNet{IP: net.IPv4(192, 168, 0, 0), Mask: net.IPv4Mask(255, 255, 255, 0)}, want: []IPAMLocalHostRangeConf{ { - Subnet: "192.168.0.0/24", + Subnet: "192.168.0.0/24", + Gateway: "192.168.0.1", }, }, }, @@ -74,7 +75,8 @@ func TestNewIPAMLocalHostRange(t *testing.T) { subnet: &net.IPNet{IP: net.ParseIP("2001:DB8::"), Mask: net.IPMask(net.ParseIP("ffff:ffff:ffff::"))}, want: []IPAMLocalHostRangeConf{ { - Subnet: "2001:db8::/48", + Subnet: "2001:db8::/48", + Gateway: "2001:db8::1", }, }, }, diff --git a/libpod/util.go b/libpod/util.go index c26039c50..ae9ef7172 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -142,29 +142,37 @@ func JSONDeepCopy(from, to interface{}) error { return json.Unmarshal(tmp, to) } -func dpkgVersion(path string) string { +func queryPackageVersion(cmdArg ...string) string { output := unknownPackage - cmd := exec.Command("/usr/bin/dpkg", "-S", path) - if outp, err := cmd.Output(); err == nil { - output = string(outp) + if 1 < len(cmdArg) { + cmd := exec.Command(cmdArg[0], cmdArg[1:]...) + if outp, err := cmd.Output(); err == nil { + output = string(outp) + } } return strings.Trim(output, "\n") } +func pacmanVersion(path string) string { + return queryPackageVersion("/usr/bin/pacman", "-Qo", path) +} + +func dpkgVersion(path string) string { + return queryPackageVersion("/usr/bin/dpkg", "-S", path) +} + func rpmVersion(path string) string { - output := unknownPackage - cmd := exec.Command("/usr/bin/rpm", "-q", "-f", path) - if outp, err := cmd.Output(); err == nil { - output = string(outp) - } - return strings.Trim(output, "\n") + return queryPackageVersion("/usr/bin/rpm", "-q", "-f", path) } func packageVersion(program string) string { if out := rpmVersion(program); out != unknownPackage { return out } - return dpkgVersion(program) + if out := dpkgVersion(program); out != unknownPackage { + return out + } + return pacmanVersion(program) } func programVersion(mountProgram string) (string, error) { |