From 934ad06a82a8088affb308c3498261ad7f25e4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 1 May 2020 13:56:57 +0200 Subject: [PATCH 1/5] Use noninteractive sudo when running podman To avoid asking for a password in the middle of minikube commands. The setup process is supposed to involve adding podman to sudoers... --- pkg/drivers/kic/oci/cli_runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/drivers/kic/oci/cli_runner.go b/pkg/drivers/kic/oci/cli_runner.go index 7c9d2852abb1..7c348cd8e0f9 100644 --- a/pkg/drivers/kic/oci/cli_runner.go +++ b/pkg/drivers/kic/oci/cli_runner.go @@ -67,7 +67,7 @@ func (rr RunResult) Output() string { // PrefixCmd adds any needed prefix (such as sudo) to the command func PrefixCmd(cmd *exec.Cmd) *exec.Cmd { if cmd.Args[0] == Podman && runtime.GOOS == "linux" { // want sudo when not running podman-remote - cmdWithSudo := exec.Command("sudo", cmd.Args...) + cmdWithSudo := exec.Command("sudo", append([]string{"-n"}, cmd.Args...)...) cmdWithSudo.Env = cmd.Env cmdWithSudo.Dir = cmd.Dir cmdWithSudo.Stdin = cmd.Stdin From c1be17346b6b8a53e17bca639054cf29c9cda667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 9 May 2020 13:40:44 +0200 Subject: [PATCH 2/5] Also delete podman containers and volumes When deleting all minikube profiles, that is --- cmd/minikube/cmd/delete.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index cde68054e92f..28be38f1abb1 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -90,26 +90,26 @@ func init() { } // shotgun cleanup to delete orphaned docker container data -func deleteContainersAndVolumes() { - if _, err := exec.LookPath(oci.Docker); err != nil { - glog.Infof("skipping deleteContainersAndVolumes for %s: %v", oci.Docker, err) +func deleteContainersAndVolumes(ociBin string) { + if _, err := exec.LookPath(ociBin); err != nil { + glog.Infof("skipping deleteContainersAndVolumes for %s: %v", ociBin, err) return } glog.Infof("deleting containers and volumes ...") delLabel := fmt.Sprintf("%s=%s", oci.CreatedByLabelKey, "true") - errs := oci.DeleteContainersByLabel(oci.Docker, delLabel) + errs := oci.DeleteContainersByLabel(ociBin, delLabel) if len(errs) > 0 { // it will error if there is no container to delete glog.Infof("error delete containers by label %q (might be okay): %+v", delLabel, errs) } - errs = oci.DeleteAllVolumesByLabel(oci.Docker, delLabel) + errs = oci.DeleteAllVolumesByLabel(ociBin, delLabel) if len(errs) > 0 { // it will not error if there is nothing to delete glog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs) } - errs = oci.PruneAllVolumesByLabel(oci.Docker, delLabel) + errs = oci.PruneAllVolumesByLabel(ociBin, delLabel) if len(errs) > 0 { // it will not error if there is nothing to delete glog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs) } @@ -137,7 +137,8 @@ func runDelete(cmd *cobra.Command, args []string) { } if deleteAll { - deleteContainersAndVolumes() + deleteContainersAndVolumes(oci.Docker) + deleteContainersAndVolumes(oci.Podman) errs := DeleteProfiles(profilesToDelete) if len(errs) > 0 { From 9673b421df898bc038a3f95b421c185c89f2d0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 9 May 2020 13:47:45 +0200 Subject: [PATCH 3/5] Skip deleting leftovers if bin not available Avoids spamming the log with extra drivers --- cmd/minikube/cmd/delete.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 28be38f1abb1..101f7aae52d5 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -168,6 +168,7 @@ func runDelete(cmd *cobra.Command, args []string) { if orphan { // TODO: generalize for non-KIC drivers: #8040 deletePossibleKicLeftOver(cname, driver.Docker) + deletePossibleKicLeftOver(cname, driver.Podman) } } @@ -210,8 +211,6 @@ func DeleteProfiles(profiles []*config.Profile) []error { // TODO: remove and/or move to delete package: #8040 func deletePossibleKicLeftOver(cname string, driverName string) { - glog.Infof("deleting possible KIC leftovers for %s (driver=%s) ...", cname, driverName) - bin := "" switch driverName { case driver.Docker: @@ -222,6 +221,13 @@ func deletePossibleKicLeftOver(cname string, driverName string) { return } + if _, err := exec.LookPath(bin); err != nil { + glog.Infof("skipping deletePossibleKicLeftOver for %s: %v", bin, err) + return + } + + glog.Infof("deleting possible KIC leftovers for %s (driver=%s) ...", cname, driverName) + delLabel := fmt.Sprintf("%s=%s", oci.ProfileLabelKey, cname) cs, err := oci.ListContainersByLabel(bin, delLabel) if err == nil && len(cs) > 0 { From 1bd56a40cfea451ed6466f8b66878c462cfd94ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 9 May 2020 13:52:22 +0200 Subject: [PATCH 4/5] Don't use cached credentials for sudo podman We want to verify that "NOPASSWD" has been set up properly Otherwise the sudo timestamp might time out (after 15 mins) --- pkg/minikube/registry/drvs/podman/podman.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/registry/drvs/podman/podman.go b/pkg/minikube/registry/drvs/podman/podman.go index 4f22fc2c7481..3d2841f94102 100644 --- a/pkg/minikube/registry/drvs/podman/podman.go +++ b/pkg/minikube/registry/drvs/podman/podman.go @@ -86,7 +86,7 @@ func status() registry.State { cmd := exec.CommandContext(ctx, oci.Podman, "version", "--format", "{{.Server.Version}}") // Run with sudo on linux (local), otherwise podman-remote (as podman) if runtime.GOOS == "linux" { - cmd = exec.CommandContext(ctx, "sudo", "-n", oci.Podman, "version", "--format", "{{.Version}}") + cmd = exec.CommandContext(ctx, "sudo", "-k", "-n", oci.Podman, "version", "--format", "{{.Version}}") cmd.Env = append(os.Environ(), "LANG=C", "LC_ALL=C") // sudo is localized } o, err := cmd.Output() From 3fa4b9164dca6d9f01cda49881549cf8a2c85188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 9 May 2020 13:58:12 +0200 Subject: [PATCH 5/5] The podman volume prune does not support filter --- cmd/minikube/cmd/delete.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index 101f7aae52d5..711cf59da870 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -109,6 +109,11 @@ func deleteContainersAndVolumes(ociBin string) { glog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs) } + if ociBin == oci.Podman { + // podman prune does not support --filter + return + } + errs = oci.PruneAllVolumesByLabel(ociBin, delLabel) if len(errs) > 0 { // it will not error if there is nothing to delete glog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs) @@ -246,6 +251,11 @@ func deletePossibleKicLeftOver(cname string, driverName string) { glog.Warningf("error deleting volumes (might be okay).\nTo see the list of volumes run: 'docker volume ls'\n:%v", errs) } + if bin == oci.Podman { + // podman prune does not support --filter + return + } + errs = oci.PruneAllVolumesByLabel(bin, delLabel) if len(errs) > 0 { // it will not error if there is nothing to delete glog.Warningf("error pruning volume (might be okay):\n%v", errs)