Skip to content

Commit 860c3fe

Browse files
committed
Explicitly remove podman volume and network
The --filter and --label functionality was broken, in earlier versions of podman (before version 3.0)
1 parent 47da1ff commit 860c3fe

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

cmd/minikube/cmd/delete.go

+16
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,27 @@ func deletePossibleKicLeftOver(cname string, driverName string) {
255255
}
256256
}
257257

258+
if bin == oci.Podman {
259+
// podman volume does not support --filter
260+
err := oci.RemoveVolume(bin, cname)
261+
if err != nil {
262+
klog.Warningf("error deleting volume %s (might be okay).'\n:%v", cname, err)
263+
}
264+
}
265+
258266
errs := oci.DeleteAllVolumesByLabel(bin, delLabel)
259267
if errs != nil { // it will not error if there is nothing to delete
260268
klog.Warningf("error deleting volumes (might be okay).\nTo see the list of volumes run: 'docker volume ls'\n:%v", errs)
261269
}
262270

271+
if bin == oci.Podman {
272+
// podman network does not support --filter
273+
err := oci.RemoveNetwork(bin, cname)
274+
if err != nil {
275+
klog.Warningf("error deleting network %s (might be okay).'\n:%v", cname, err)
276+
}
277+
}
278+
263279
errs = oci.DeleteKICNetworks(bin)
264280
if errs != nil {
265281
klog.Warningf("error deleting leftover networks (might be okay).\nTo see the list of networks: 'docker network ls'\n:%v", errs)

pkg/drivers/kic/oci/errors.go

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ var ErrDaemonInfo = errors.New("daemon info not responding")
5454
// ErrInsufficientDockerStorage is thrown when there is not more storage for docker
5555
var ErrInsufficientDockerStorage = &FailFastError{errors.New("insufficient docker storage, no space left on device")}
5656

57+
// ErrVolumeNotFound is when given volume was not found
58+
var ErrVolumeNotFound = errors.New("kic volume not found")
59+
5760
// ErrNetworkSubnetTaken is thrown when a subnet is taken by another network
5861
var ErrNetworkSubnetTaken = errors.New("subnet is taken")
5962

pkg/drivers/kic/oci/volumes.go

+42
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package oci
1919
import (
2020
"bufio"
2121
"bytes"
22+
"encoding/json"
2223
"fmt"
2324
"os/exec"
2425
"runtime"
@@ -29,6 +30,47 @@ import (
2930
"k8s.io/klog/v2"
3031
)
3132

33+
// RemoveVolume removes a volume
34+
func RemoveVolume(ociBin string, name string) error {
35+
if !volumeExists(ociBin, name) {
36+
return nil
37+
}
38+
rr, err := runCmd(exec.Command(ociBin, "volume", "rm", name))
39+
if err != nil {
40+
if strings.Contains(rr.Output(), "No such volume") ||
41+
strings.Contains(rr.Output(), "no such volume") {
42+
return ErrVolumeNotFound
43+
}
44+
}
45+
46+
return err
47+
}
48+
49+
func volumeExists(ociBin string, name string) bool {
50+
_, err := containerVolumeInspect(ociBin, name)
51+
if err != nil && !errors.Is(err, ErrVolumeNotFound) { // log unexpected error
52+
klog.Warningf("Error inspecting docker volume %s: %v", name, err)
53+
}
54+
return err == nil
55+
}
56+
57+
func containerVolumeInspect(ociBin string, name string) (interface{}, error) {
58+
var info interface{}
59+
cmd := exec.Command(ociBin, "volume", "inspect", name)
60+
rr, err := runCmd(cmd)
61+
if err != nil {
62+
if strings.Contains(rr.Output(), "No such volume") ||
63+
strings.Contains(rr.Output(), "no such volume") {
64+
return info, ErrVolumeNotFound
65+
}
66+
return info, err
67+
}
68+
69+
err = json.Unmarshal(rr.Stdout.Bytes(), &info)
70+
71+
return info, err
72+
}
73+
3274
// DeleteAllVolumesByLabel deletes all volumes that have a specific label
3375
// if there is no volume to delete it will return nil
3476
func DeleteAllVolumesByLabel(ociBin string, label string, warnSlow ...bool) []error {

0 commit comments

Comments
 (0)