未验证 提交 afab7c87 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #7959 from afbjorklund/podman-prompt

Use noninteractive sudo when running podman
...@@ -90,26 +90,31 @@ func init() { ...@@ -90,26 +90,31 @@ func init() {
} }
// shotgun cleanup to delete orphaned docker container data // shotgun cleanup to delete orphaned docker container data
func deleteContainersAndVolumes() { func deleteContainersAndVolumes(ociBin string) {
if _, err := exec.LookPath(oci.Docker); err != nil { if _, err := exec.LookPath(ociBin); err != nil {
glog.Infof("skipping deleteContainersAndVolumes for %s: %v", oci.Docker, err) glog.Infof("skipping deleteContainersAndVolumes for %s: %v", ociBin, err)
return return
} }
glog.Infof("deleting containers and volumes ...") glog.Infof("deleting containers and volumes ...")
delLabel := fmt.Sprintf("%s=%s", oci.CreatedByLabelKey, "true") 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 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) 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 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) glog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs)
} }
errs = oci.PruneAllVolumesByLabel(oci.Docker, delLabel) 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 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) glog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs)
} }
...@@ -137,7 +142,8 @@ func runDelete(cmd *cobra.Command, args []string) { ...@@ -137,7 +142,8 @@ func runDelete(cmd *cobra.Command, args []string) {
} }
if deleteAll { if deleteAll {
deleteContainersAndVolumes() deleteContainersAndVolumes(oci.Docker)
deleteContainersAndVolumes(oci.Podman)
errs := DeleteProfiles(profilesToDelete) errs := DeleteProfiles(profilesToDelete)
if len(errs) > 0 { if len(errs) > 0 {
...@@ -167,6 +173,7 @@ func runDelete(cmd *cobra.Command, args []string) { ...@@ -167,6 +173,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if orphan { if orphan {
// TODO: generalize for non-KIC drivers: #8040 // TODO: generalize for non-KIC drivers: #8040
deletePossibleKicLeftOver(cname, driver.Docker) deletePossibleKicLeftOver(cname, driver.Docker)
deletePossibleKicLeftOver(cname, driver.Podman)
} }
} }
...@@ -209,8 +216,6 @@ func DeleteProfiles(profiles []*config.Profile) []error { ...@@ -209,8 +216,6 @@ func DeleteProfiles(profiles []*config.Profile) []error {
// TODO: remove and/or move to delete package: #8040 // TODO: remove and/or move to delete package: #8040
func deletePossibleKicLeftOver(cname string, driverName string) { func deletePossibleKicLeftOver(cname string, driverName string) {
glog.Infof("deleting possible KIC leftovers for %s (driver=%s) ...", cname, driverName)
bin := "" bin := ""
switch driverName { switch driverName {
case driver.Docker: case driver.Docker:
...@@ -221,6 +226,13 @@ func deletePossibleKicLeftOver(cname string, driverName string) { ...@@ -221,6 +226,13 @@ func deletePossibleKicLeftOver(cname string, driverName string) {
return 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) delLabel := fmt.Sprintf("%s=%s", oci.ProfileLabelKey, cname)
cs, err := oci.ListContainersByLabel(bin, delLabel) cs, err := oci.ListContainersByLabel(bin, delLabel)
if err == nil && len(cs) > 0 { if err == nil && len(cs) > 0 {
...@@ -239,6 +251,11 @@ func deletePossibleKicLeftOver(cname string, driverName string) { ...@@ -239,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) 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) errs = oci.PruneAllVolumesByLabel(bin, delLabel)
if len(errs) > 0 { // it will not error if there is nothing to delete 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) glog.Warningf("error pruning volume (might be okay):\n%v", errs)
......
...@@ -67,7 +67,7 @@ func (rr RunResult) Output() string { ...@@ -67,7 +67,7 @@ func (rr RunResult) Output() string {
// PrefixCmd adds any needed prefix (such as sudo) to the command // PrefixCmd adds any needed prefix (such as sudo) to the command
func PrefixCmd(cmd *exec.Cmd) *exec.Cmd { func PrefixCmd(cmd *exec.Cmd) *exec.Cmd {
if cmd.Args[0] == Podman && runtime.GOOS == "linux" { // want sudo when not running podman-remote 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.Env = cmd.Env
cmdWithSudo.Dir = cmd.Dir cmdWithSudo.Dir = cmd.Dir
cmdWithSudo.Stdin = cmd.Stdin cmdWithSudo.Stdin = cmd.Stdin
......
...@@ -90,7 +90,7 @@ func status() registry.State { ...@@ -90,7 +90,7 @@ func status() registry.State {
cmd := exec.CommandContext(ctx, oci.Podman, "version", "--format", "{{.Server.Version}}") cmd := exec.CommandContext(ctx, oci.Podman, "version", "--format", "{{.Server.Version}}")
// Run with sudo on linux (local), otherwise podman-remote (as podman) // Run with sudo on linux (local), otherwise podman-remote (as podman)
if runtime.GOOS == "linux" { 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 cmd.Env = append(os.Environ(), "LANG=C", "LC_ALL=C") // sudo is localized
} }
o, err := cmd.Output() o, err := cmd.Output()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册