提交 51169d68 编写于 作者: P Priya Wadhwa

Add context to remaining necessary functions

上级 a6372b35
......@@ -110,7 +110,8 @@ func deleteContainersAndVolumes(ociBin string) {
klog.Infof("error delete containers by label %q (might be okay): %+v", delLabel, errs)
}
errs = oci.DeleteAllVolumesByLabel(ociBin, delLabel)
ctx := context.Background()
errs = oci.DeleteAllVolumesByLabel(ctx, ociBin, delLabel)
if len(errs) > 0 { // it will not error if there is nothing to delete
klog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs)
}
......@@ -120,7 +121,7 @@ func deleteContainersAndVolumes(ociBin string) {
return
}
errs = oci.PruneAllVolumesByLabel(ociBin, delLabel)
errs = oci.PruneAllVolumesByLabel(ctx, ociBin, delLabel)
if len(errs) > 0 { // it will not error if there is nothing to delete
klog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs)
}
......@@ -258,7 +259,7 @@ func deletePossibleKicLeftOver(cname string, driverName string) {
}
}
errs := oci.DeleteAllVolumesByLabel(bin, delLabel)
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)
}
......@@ -273,7 +274,7 @@ func deletePossibleKicLeftOver(cname string, driverName string) {
return
}
errs = oci.PruneAllVolumesByLabel(bin, delLabel)
errs = oci.PruneAllVolumesByLabel(ctx, bin, delLabel)
if len(errs) > 0 { // it will not error if there is nothing to delete
klog.Warningf("error pruning volume (might be okay):\n%v", errs)
}
......
......@@ -19,6 +19,7 @@ package oci
import (
"bufio"
"bytes"
"context"
"fmt"
"os/exec"
"runtime"
......@@ -31,7 +32,7 @@ import (
// DeleteAllVolumesByLabel deletes all volumes that have a specific label
// if there is no volume to delete it will return nil
func DeleteAllVolumesByLabel(ociBin string, label string, warnSlow ...bool) []error {
func DeleteAllVolumesByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) []error {
var deleteErrs []error
klog.Infof("trying to delete all %s volumes with label %s", ociBin, label)
......@@ -42,7 +43,7 @@ func DeleteAllVolumesByLabel(ociBin string, label string, warnSlow ...bool) []er
}
for _, v := range vs {
if _, err := runCmd(exec.Command(ociBin, "volume", "rm", "--force", v), warnSlow...); err != nil {
if _, err := runCmd(exec.CommandContext(ctx, ociBin, "volume", "rm", "--force", v), warnSlow...); err != nil {
deleteErrs = append(deleteErrs, fmt.Errorf("deleting %q", v))
}
}
......@@ -53,10 +54,10 @@ func DeleteAllVolumesByLabel(ociBin string, label string, warnSlow ...bool) []er
// PruneAllVolumesByLabel deletes all volumes that have a specific label
// if there is no volume to delete it will return nil
// example: docker volume prune -f --filter label=name.minikube.sigs.k8s.io=minikube
func PruneAllVolumesByLabel(ociBin string, label string, warnSlow ...bool) []error {
func PruneAllVolumesByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) []error {
var deleteErrs []error
klog.Infof("trying to prune all %s volumes with label %s", ociBin, label)
cmd := exec.Command(ociBin, "volume", "prune", "-f", "--filter", "label="+label)
cmd := exec.CommandContext(ctx, ociBin, "volume", "prune", "-f", "--filter", "label="+label)
if _, err := runCmd(cmd, warnSlow...); err != nil {
deleteErrs = append(deleteErrs, errors.Wrapf(err, "prune volume by label %s", label))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册