-
Notifications
You must be signed in to change notification settings - Fork 625
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
vz: implement auto save/restore #2900
base: master
Are you sure you want to change the base?
Changes from 1 commit
4fc95cd
349ccd1
929c7e5
c5305c0
1d533a7
de78015
7f4df6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ var knownYamlProperties = []string{ | |
"PropagateProxyEnv", | ||
"Provision", | ||
"Rosetta", | ||
"SaveOnStop", | ||
"SSH", | ||
"TimeZone", | ||
"UpgradePackages", | ||
|
@@ -67,11 +68,22 @@ type LimaVzDriver struct { | |
*driver.BaseDriver | ||
|
||
machine *virtualMachineWrapper | ||
|
||
// Runtime configuration | ||
config LimaVzDriverRuntimeConfig | ||
} | ||
|
||
type LimaVzDriverRuntimeConfig struct { | ||
// SaveOnStop is a flag to save the VM state on stop | ||
SaveOnStop bool `json:"saveOnStop"` | ||
} | ||
|
||
func New(driver *driver.BaseDriver) *LimaVzDriver { | ||
return &LimaVzDriver{ | ||
BaseDriver: driver, | ||
config: LimaVzDriverRuntimeConfig{ | ||
SaveOnStop: *driver.Instance.Config.SaveOnStop, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preparing for more config options? |
||
} | ||
} | ||
|
||
|
@@ -193,11 +205,13 @@ func (l *LimaVzDriver) RunGUI() error { | |
} | ||
|
||
func (l *LimaVzDriver) Stop(_ context.Context) error { | ||
machineStatePath := filepath.Join(l.Instance.Dir, filenames.VzMachineState) | ||
if err := saveVM(l.machine.VirtualMachine, machineStatePath); err != nil { | ||
logrus.WithError(err).Warn("Failed to save VZ. Falling back to shutdown") | ||
} else { | ||
return nil | ||
if l.config.SaveOnStop { | ||
machineStatePath := filepath.Join(l.Instance.Dir, filenames.VzMachineState) | ||
if err := saveVM(l.machine.VirtualMachine, machineStatePath); err != nil { | ||
logrus.WithError(err).Warn("Failed to save VZ. Falling back to shutdown") | ||
} else { | ||
return nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code to add saveOnStop must be added before you change Stop(). Each commit should be correct so we can easily bisect issues. The order of commits should be:
If you don't want to add unused option, add the internal flag defaulting to false in the first commit, and expose the option in the second. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That should already be the case. Could you double-check to ensure you're not looking at an outdated commit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still the case - the first commit ignore the option added in the second commit. If we need to revert the second commit we change the behavior to always save. |
||
} | ||
|
||
logrus.Info("Shutting down VZ") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will more clear if we extract all the checks to a helper like:
In the helper can do something like: