From f6d639182d6378ad93be57d2ccbf3a66a0261257 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 6 Jun 2022 16:59:41 +1000 Subject: [PATCH] fix: minikube delete exclude networks from other profiles Fixes: 12635 --- pkg/drivers/kic/oci/network_create.go | 8 ++++---- pkg/minikube/delete/delete.go | 2 +- test/integration/kic_custom_network_test.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/drivers/kic/oci/network_create.go b/pkg/drivers/kic/oci/network_create.go index fd8137fbe873..894be2ee92b4 100644 --- a/pkg/drivers/kic/oci/network_create.go +++ b/pkg/drivers/kic/oci/network_create.go @@ -133,7 +133,7 @@ func tryCreateDockerNetwork(ociBin string, subnet *network.Parameters, mtu int, args = append(args, fmt.Sprintf("com.docker.network.driver.mtu=%d", mtu)) } } - args = append(args, fmt.Sprintf("--label=%s=%s", CreatedByLabelKey, "true"), name) + args = append(args, fmt.Sprintf("--label=%s=%s", CreatedByLabelKey, "true"), fmt.Sprintf("--label=%s=%s", ProfileLabelKey, name), name) rr, err := runCmd(exec.Command(ociBin, args...)) if err != nil { @@ -320,10 +320,10 @@ func networkNamesByLabel(ociBin string, label string) ([]string, error) { return lines, nil } -// DeleteKICNetworks deletes all networks created by kic -func DeleteKICNetworks(ociBin string) []error { +// DeleteAllKICKNetworksByLabel deletes all networks that have a specific label +func DeleteKICNetworksByLabel(ociBin string, label string) []error { var errs []error - ns, err := networkNamesByLabel(ociBin, CreatedByLabelKey) + ns, err := networkNamesByLabel(ociBin, label) if err != nil { return []error{errors.Wrap(err, "list all volume")} } diff --git a/pkg/minikube/delete/delete.go b/pkg/minikube/delete/delete.go index cd6000496c26..95dc688f8e53 100644 --- a/pkg/minikube/delete/delete.go +++ b/pkg/minikube/delete/delete.go @@ -64,7 +64,7 @@ func PossibleLeftOvers(ctx context.Context, cname string, driverName string) { klog.Warningf("error deleting volumes (might be okay).\nTo see the list of volumes run: 'docker volume ls'\n:%v", errs) } - errs = oci.DeleteKICNetworks(bin) + errs = oci.DeleteKICNetworksByLabel(bin, delLabel) if errs != nil { klog.Warningf("error deleting leftover networks (might be okay).\nTo see the list of networks: 'docker network ls'\n:%v", errs) } diff --git a/test/integration/kic_custom_network_test.go b/test/integration/kic_custom_network_test.go index 6bbf3fb1d754..85d2822e09ff 100644 --- a/test/integration/kic_custom_network_test.go +++ b/test/integration/kic_custom_network_test.go @@ -78,7 +78,7 @@ func TestKicExistingNetwork(t *testing.T) { t.Fatalf("error creating network: %v", err) } defer func() { - if err := oci.DeleteKICNetworks(oci.Docker); err != nil { + if err := oci.DeleteKICNetworksByLabel(oci.Docker, networkName); err != nil { t.Logf("error deleting kic network, may need to delete manually: %v", err) } }()