Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed save functionality to save snapshot even if snapshot does not a… #26

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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