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

Podman: fix minikube delete for Podman v4 #13881

Merged
Merged
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions pkg/drivers/kic/oci/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
var v semver.Version

if ociBin == Podman {
rr, err = runCmd(exec.Command(Podman, "version", "--format", "{{.Version}}"))
if err != nil {
return 0, errors.Wrapf(err, "podman version")
}
output := strings.TrimSpace(rr.Stdout.String())
v, err = semver.Make(output)
v, err = podmanVersion()
if err != nil {
return 0, errors.Wrapf(err, "podman version")
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/drivers/kic/oci/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os/exec"
"strings"

"github.com/blang/semver/v4"
"github.com/pkg/errors"

"k8s.io/klog/v2"
Expand Down Expand Up @@ -213,7 +214,16 @@ func dockerNetworkInspect(name string) (netInfo, error) {
}

var podmanInspectGetter = func(name string) (*RunResult, error) {
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}}`)
v, err := podmanVersion()
if err != nil {
return nil, errors.Wrapf(err, "podman version")
}
format := `{{range .}}{{if eq .Driver "bridge"}}{{(index .Subnets 0).Subnet}},{{(index .Subnets 0).Gateway}}{{end}}{{end}}`
if v.LT(semver.Version{Major: 4, Minor: 0, Patch: 0}) {
// format was changed in Podman 4.0.0: https://github.com/kubernetes/minikube/issues/13861#issuecomment-1082639236
format = `{{range .plugins}}{{if eq .type "bridge"}}{{(index (index .ipam.ranges 0) 0).subnet}},{{(index (index .ipam.ranges 0) 0).gateway}}{{end}}{{end}}`
}
cmd := exec.Command(Podman, "network", "inspect", name, "--format", format)
return runCmd(cmd)
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"strings"
"time"

"github.com/blang/semver/v4"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"

Expand Down Expand Up @@ -736,3 +737,12 @@ func IsExternalDaemonHost(driver string) bool {
}
return false
}

func podmanVersion() (semver.Version, error) {
rr, err := runCmd(exec.Command(Podman, "version", "--format", "{{.Version}}"))
if err != nil {
return semver.Version{}, errors.Wrapf(err, "podman version")
}
output := strings.TrimSpace(rr.Stdout.String())
return semver.Make(output)
}