From e457618d711c0a6c08d0b8e55daffe6144dd6e27 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 12 May 2020 16:00:02 -0700 Subject: [PATCH] make deleting orphaned kics optional --- pkg/minikube/machine/cluster_test.go | 8 ++++---- pkg/minikube/machine/delete.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/minikube/machine/cluster_test.go b/pkg/minikube/machine/cluster_test.go index 310f29e2eb..3dfdc303e2 100644 --- a/pkg/minikube/machine/cluster_test.go +++ b/pkg/minikube/machine/cluster_test.go @@ -339,7 +339,7 @@ func TestDeleteHost(t *testing.T) { cc := defaultClusterConfig cc.Name = viper.GetString("profile") - if err := DeleteHost(api, driver.MachineName(cc, config.Node{Name: "minikube"})); err != nil { + if err := DeleteHost(api, driver.MachineName(cc, config.Node{Name: "minikube"}), false); err != nil { t.Fatalf("Unexpected error deleting host: %v", err) } } @@ -355,7 +355,7 @@ func TestDeleteHostErrorDeletingVM(t *testing.T) { d := &tests.MockDriver{RemoveError: true, T: t} h.Driver = d - if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil { + if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil { t.Fatal("Expected error deleting host.") } } @@ -368,7 +368,7 @@ func TestDeleteHostErrorDeletingFiles(t *testing.T) { t.Errorf("createHost failed: %v", err) } - if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil { + if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil { t.Fatal("Expected error deleting host.") } } @@ -383,7 +383,7 @@ func TestDeleteHostErrMachineNotExist(t *testing.T) { t.Errorf("createHost failed: %v", err) } - if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil { + if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil { t.Fatal("Expected error deleting host.") } } diff --git a/pkg/minikube/machine/delete.go b/pkg/minikube/machine/delete.go index 4cd55d37d0..18d128aacc 100644 --- a/pkg/minikube/machine/delete.go +++ b/pkg/minikube/machine/delete.go @@ -60,9 +60,15 @@ func deleteOrphanedKIC(ociBin string, name string) { } // DeleteHost deletes the host VM. -func DeleteHost(api libmachine.API, machineName string) error { +// deleteAbandoned will will try to delete the machine even if there is no minikube config for it. +func DeleteHost(api libmachine.API, machineName string, deleteAbandoned ...bool) error { + delAbandoned := true + if len(deleteAbandoned) > 0 { + delAbandoned = deleteAbandoned[0] + } + host, err := api.Load(machineName) - if err != nil && host == nil { + if err != nil && host == nil && delAbandoned { deleteOrphanedKIC(oci.Docker, machineName) deleteOrphanedKIC(oci.Podman, machineName) // Keep going even if minikube does not know about the host