From 5461a8a3c19b071bdb796a93f22cd357598d8a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 5 Dec 2020 18:05:40 +0100 Subject: [PATCH] Fix podman network inspect format and error Somehow this ended up with the docker network inspect format, instead of the CNI based one used by podman network inspect ? Also add a check for when trying to name the cluster "podman", which runs into trouble (same as docker driver with name "bridge") --- pkg/drivers/kic/oci/network_create.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/drivers/kic/oci/network_create.go b/pkg/drivers/kic/oci/network_create.go index e9421fcb4a27..2b0ba60db0b5 100644 --- a/pkg/drivers/kic/oci/network_create.go +++ b/pkg/drivers/kic/oci/network_create.go @@ -38,7 +38,10 @@ const firstSubnetAddr = "192.168.49.0" const defaultSubnetMask = 24 // name of the default bridge network, used to lookup the MTU (see #9528) -const defaultBridgeName = "bridge" +const dockerDefaultBridge = "bridge" + +// name of the default bridge network +const podmanDefaultBridge = "podman" // CreateNetwork creates a network returns gateway and error, minikube creates one network per cluster func CreateNetwork(ociBin string, name string) (net.IP, error) { @@ -46,6 +49,19 @@ func CreateNetwork(ociBin string, name string) (net.IP, error) { } func createDockerNetwork(ociBin string, clusterName string) (net.IP, error) { + var defaultBridgeName string + if ociBin == Docker { + defaultBridgeName = dockerDefaultBridge + } + if ociBin == Podman { + defaultBridgeName = podmanDefaultBridge + } + + // validate the name of the new network + if clusterName == defaultBridgeName { + return nil, errors.Errorf("Can't use same name as %s's default network: %s", ociBin, clusterName) + } + // check if the network already exists info, err := containerNetworkInspect(ociBin, clusterName) if err == nil { @@ -124,6 +140,9 @@ func tryCreateDockerNetwork(ociBin string, subnetAddr string, subnetMask int, mt if strings.Contains(rr.Output(), "failed to allocate gateway") && strings.Contains(rr.Output(), "Address already in use") { return nil, ErrNetworkGatewayTaken } + if strings.Contains(rr.Output(), "is being used by a network interface") { + return nil, ErrNetworkGatewayTaken + } return nil, errors.Wrapf(err, "create network %s", fmt.Sprintf("%s %s/%d", name, subnetAddr, subnetMask)) } return gateway, nil @@ -191,7 +210,7 @@ func dockerNetworkInspect(name string) (netInfo, error) { func podmanNetworkInspect(name string) (netInfo, error) { var info = netInfo{name: name} - cmd := exec.Command(Podman, "network", "inspect", name, "--format", `{{(index .IPAM.Config 0).Subnet}},{{(index .IPAM.Config 0).Gateway}}`) + cmd := exec.Command(Podman, "network", "inspect", name, "--format", `{{range .plugins}}{{if eq .type "bridge"}}{{(index (index .ipam.ranges 0) 0).subnet}},{{(index (index .ipam.ranges 0) 0).gateway}}{{end}}{{end}}`) rr, err := runCmd(cmd) if err != nil { logDockerNetworkInspect(Podman, name)