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

Explicitly remove podman volume and network #10435

Merged
merged 1 commit into from
Feb 11, 2021
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
16 changes: 16 additions & 0 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,27 @@ func deletePossibleKicLeftOver(ctx context.Context, cname string, driverName str
}
}

if bin == oci.Podman {
// podman volume does not support --filter
err := oci.RemoveVolume(bin, cname)
if err != nil {
klog.Warningf("error deleting volume %s (might be okay).'\n:%v", cname, err)
}
}

errs := oci.DeleteAllVolumesByLabel(ctx, bin, delLabel)
if errs != nil { // it will not error if there is nothing to delete
klog.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 network does not support --filter
err := oci.RemoveNetwork(bin, cname)
if err != nil {
klog.Warningf("error deleting network %s (might be okay).'\n:%v", cname, err)
}
}

errs = oci.DeleteKICNetworks(bin)
if errs != nil {
klog.Warningf("error deleting leftover networks (might be okay).\nTo see the list of networks: 'docker network ls'\n:%v", errs)
Expand Down
3 changes: 3 additions & 0 deletions pkg/drivers/kic/oci/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ var ErrDaemonInfo = errors.New("daemon info not responding")
// ErrInsufficientDockerStorage is thrown when there is not more storage for docker
var ErrInsufficientDockerStorage = &FailFastError{errors.New("insufficient docker storage, no space left on device")}

// ErrVolumeNotFound is when given volume was not found
var ErrVolumeNotFound = errors.New("kic volume not found")

// ErrNetworkSubnetTaken is thrown when a subnet is taken by another network
var ErrNetworkSubnetTaken = errors.New("subnet is taken")

Expand Down
42 changes: 42 additions & 0 deletions pkg/drivers/kic/oci/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"os/exec"
"runtime"
Expand All @@ -30,6 +31,47 @@ import (
"k8s.io/klog/v2"
)

// RemoveVolume removes a volume
func RemoveVolume(ociBin string, name string) error {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if !volumeExists(ociBin, name) {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
rr, err := runCmd(exec.Command(ociBin, "volume", "rm", name))
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
if strings.Contains(rr.Output(), "No such volume") ||
strings.Contains(rr.Output(), "no such volume") {
return ErrVolumeNotFound
}
}

return err
}

func volumeExists(ociBin string, name string) bool {
_, err := containerVolumeInspect(ociBin, name)
if err != nil && !errors.Is(err, ErrVolumeNotFound) { // log unexpected error
klog.Warningf("Error inspecting docker volume %s: %v", name, err)
}
return err == nil
}

func containerVolumeInspect(ociBin string, name string) (interface{}, error) {
var info interface{}
cmd := exec.Command(ociBin, "volume", "inspect", name)
rr, err := runCmd(cmd)
if err != nil {
if strings.Contains(rr.Output(), "No such volume") ||
strings.Contains(rr.Output(), "no such volume") {
return info, ErrVolumeNotFound
}
return info, err
}

err = json.Unmarshal(rr.Stdout.Bytes(), &info)

return info, err
}

// DeleteAllVolumesByLabel deletes all volumes that have a specific label
// if there is no volume to delete it will return nil
func DeleteAllVolumesByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) []error {
Expand Down