Skip to content

Commit

Permalink
Merge pull request #26 from heartofrevel/savefix
Browse files Browse the repository at this point in the history
Fixed save functionality to save snapshot even if snapshot does not a…
  • Loading branch information
Christophe VILA authored Jan 17, 2023
2 parents 5c3d17a + 0517d80 commit 72bab1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/gokube/cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions pkg/virtualbox/vbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72bab1d

Please sign in to comment.