Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix podman network inspect format and error #9866

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions pkg/drivers/kic/oci/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ 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) {
return createDockerNetwork(ociBin, name)
}
func CreateNetwork(ociBin string, clusterName string) (net.IP, error) {
var defaultBridgeName string
if ociBin == Docker {
defaultBridgeName = dockerDefaultBridge
}
if ociBin == Podman {
defaultBridgeName = podmanDefaultBridge
}

func createDockerNetwork(ociBin string, clusterName string) (net.IP, error) {
// check if the network already exists
info, err := containerNetworkInspect(ociBin, clusterName)
if err == nil {
Expand Down Expand Up @@ -124,6 +131,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
Expand Down Expand Up @@ -191,7 +201,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)
Expand Down