diff --git a/cmd/gokube/cmd/save.go b/cmd/gokube/cmd/save.go index 03b7447..9060065 100644 --- a/cmd/gokube/cmd/save.go +++ b/cmd/gokube/cmd/save.go @@ -65,6 +65,7 @@ func saveRun(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("cannot take minikube VM snapshot %s: %w", savedSnapshotName, err) } + fmt.Printf("Snapshot '%s' created of minikube VM...\n", savedSnapshotName) if running { return start() } else { diff --git a/pkg/virtualbox/vbm.go b/pkg/virtualbox/vbm.go index dcee730..e5d6a11 100644 --- a/pkg/virtualbox/vbm.go +++ b/pkg/virtualbox/vbm.go @@ -18,6 +18,7 @@ const ( retryCountOnObjectNotReadyError = 5 objectNotReady = "error: The object is not ready" retryDelay = 100 * time.Millisecond + snapshotNotExist = "Could not find a snapshot named" ) var ( @@ -26,10 +27,10 @@ var ( reEqualQuoteLine = regexp.MustCompile(`"(.+)"="(.*)"`) reMachineNotFound = regexp.MustCompile(`Could not find a registered machine named '(.+)'`) - ErrMachineNotExist = errors.New("machine does not exist") - ErrVBMNotFound = errors.New("VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path") - - vboxManageCmd = detectVBoxManageCmd() + ErrMachineNotExist = errors.New("machine does not exist") + ErrVBMNotFound = errors.New("VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path") + ErrVBMSnapshotNotFound = errors.New("snapshot does not exist") + vboxManageCmd = detectVBoxManageCmd() ) // VBoxManager defines the interface to communicate to VirtualBox. @@ -82,6 +83,10 @@ func (v *VBoxCmdManager) vbmOutErrRetry(retry int, args ...string) (string, stri } } + if strings.Contains(stderrStr, snapshotNotExist) { + err = ErrVBMSnapshotNotFound + } + // Sometimes, we just need to retry... if retry > 1 { if strings.Contains(stderrStr, objectNotReady) { diff --git a/pkg/virtualbox/virtualbox.go b/pkg/virtualbox/virtualbox.go index 825f87a..c8fe7f3 100644 --- a/pkg/virtualbox/virtualbox.go +++ b/pkg/virtualbox/virtualbox.go @@ -136,6 +136,10 @@ func ResetHostOnlyNetworkLeases(hostOnlyCIDR string, verbose bool) error { func DeleteSnapshot(name string) error { err := vboxManager.vbm("snapshot", "minikube", "delete", name) if err != nil { + if err == ErrVBMSnapshotNotFound { + fmt.Printf("Existing snapshot '%s' not found, no delete required...\n", name) + return nil + } return errors.New("not able to delete VM snapshot") } return nil