Also delete podman containers and volumes

When deleting all minikube profiles, that is
pull/7959/head
Anders F Björklund 2020-05-09 13:40:44 +02:00
parent 934ad06a82
commit c1be17346b
1 changed files with 8 additions and 7 deletions

View File

@ -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 {