-
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
Fix start command: return error early when instance already exists #3144
Conversation
…e exists" This reverts commit d6a6d7f. Signed-off-by: Jan Dubois <[email protected]>
Without the additional check, we would offer the user to edit the template, and only then throw an error that the instance already exists. Fixes lima-vm#2575 Signed-off-by: Jan Dubois <[email protected]>
This change points the lima submodule to the Lima PR branch for lima-vm/lima#3144 Signed-off-by: Jan Dubois <[email protected]>
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.
I don't fully understand the complicated code around the change, but this looks a reasonable minimal fix.
We need a new test to cover this use case.
@@ -149,7 +149,13 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (* | |||
if err != nil { | |||
return nil, err | |||
} | |||
if len(tmpl.Bytes) == 0 { | |||
if len(tmpl.Bytes) > 0 { |
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 is very confusing API - if the template does not exist I would expect limatmpl.Read() to return an error, not an object with empty Bytes.
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.
I agree, this was mostly to accommodate the complex logic in loadOrCreateInstance()
.
I don't think all the error checking and reporting belongs into limatmpl.Read()
, which is just code factored out from loadOrCreateInstance()
, so it can be called from other places as well. It would benefit from further refactoring, but that is not a priority right now. Please don't touch this code until #3072 is done and merged.
return nil, fmt.Errorf("instance %q already exists", tmpl.Name) | ||
} | ||
} | ||
} else { |
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 looks good for a minimal change, but we need to eliminate the complicated nesting later. If we handled the case when Bytes > 0 by returning, we don't need the else block.
I don't know how that test should work, and I don't think it needs to be in this PR, which is just fixing a regression in the latest release. |
Reproduced the original issue:
Tested the fix:
|
if len(tmpl.Bytes) == 0 { | ||
if len(tmpl.Bytes) > 0 { | ||
if createOnly { | ||
if _, err := store.Inspect(tmpl.Name); err == nil { |
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.
Maybe we need to log error if not nil?
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.
No, if createOnly
is true
, then we throw an error if the instance already exists. If the instance doesn't exist yet, then everything is fine.
Note that the only time store.Inspect()
returns a non-nil error is when the instance doesn't exist. Any other errors would be returned in *inst.Errors
. This is not always handled consistently on the caller side (see #2668).
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [lima-vm/lima](https://github.com/lima-vm/lima) | patch | `v1.0.4` -> `v1.0.5` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>lima-vm/lima (lima-vm/lima)</summary> ### [`v1.0.5`](https://github.com/lima-vm/lima/releases/tag/v1.0.5) [Compare Source](lima-vm/lima@v1.0.4...v1.0.5) #### Changes - `limactl` CLI: - Fix start command: return error early when instance already exists ([#​3144](lima-vm/lima#3144), thanks to [@​jandubois](https://github.com/jandubois)) - DNS: - Fix a regression containers/gvisor-tap-vsock#466 ([#​3189](lima-vm/lima#3189)) - QEMU: - Enable SME on macOS 15.3 running on M4 ([#​3197](lima-vm/lima#3197), [#​3203](lima-vm/lima#3203), thanks to [@​jandubois](https://github.com/jandubois)) Full changes: https://github.com/lima-vm/lima/milestone/55?closed=1 Thanks to [@​alexandear](https://github.com/alexandear) [@​arixmkii](https://github.com/arixmkii) [@​jandubois](https://github.com/jandubois) [@​msgilligan](https://github.com/msgilligan) [@​olamilekan000](https://github.com/olamilekan000) [@​rfay](https://github.com/rfay) [@​s1gnate-sync](https://github.com/s1gnate-sync) #### Usage ```console [macOS]$ limactl create [macOS]$ limactl start ... INFO[0029] READY. Run `lima` to open the shell. [macOS]$ lima uname Linux ``` *** The binaries were built automatically on GitHub Actions. The build log is available for 90 days: https://github.com/lima-vm/lima/actions/runs/13195714188 The sha256sum of the SHA256SUMS file itself is `d31365f1da7802a63c86b1e1609a19c1ce92244a4e6824d924a896b6c12810b0` . *** Release manager: [@​AkihiroSuda](https://github.com/AkihiroSuda) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNjIuMyIsInVwZGF0ZWRJblZlciI6IjM5LjE2Mi4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Without the additional check, we would offer the user to edit the template, and only then throw an error that the instance already exists.
Fixes #2575
Fixes #3142
Reverts #3120
Intentionally not squashing commits because one is a revert, and the other is new changes.