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

Fix start command: return error early when instance already exists #3144

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

jandubois
Copy link
Member

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.

…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]>
jandubois added a commit to jandubois/rancher-desktop-lima that referenced this pull request Jan 23, 2025
This change points the lima submodule to the Lima PR branch for
lima-vm/lima#3144

Signed-off-by: Jan Dubois <[email protected]>
@jandubois jandubois requested a review from a team January 23, 2025 18:02
Copy link
Member

@nirs nirs left a 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 {
Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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.

@jandubois
Copy link
Member Author

We need a new test to cover this use case.

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.

@nirs
Copy link
Member

nirs commented Jan 23, 2025

Reproduced the original issue:

% rm -rf _output/share/lima/templates

% _output/bin/limactl create --tty=0 test.yaml
...
INFO[0019] Run `limactl start test` to start the instance. 

% _output/bin/limactl start test                  
INFO[0000] Creating an instance "test" from template://default (Not from template://test) 
WARN[0000] This form is deprecated. Use `limactl create --name=test template://default` instead 
FATA[0000] open /Users/nsoffer/src/lima/_output/share/lima/templates/default.yaml: no such file or directory 

Tested the fix:

% rm -rf _output/share/lima/templates         
% _output/bin/limactl create --tty=0 test.yaml 
...

% _output/bin/limactl start test              
INFO[0000] Using the existing instance "test"           
INFO[0000] Starting the instance "test" with VM driver "vz" 
INFO[0000] [hostagent] hostagent socket created at /Users/nsoffer/.lima/test/ha.sock 
INFO[0000] [hostagent] Starting VZ (hint: to watch the boot progress, see "/Users/nsoffer/.lima/test/serial*.log") 
INFO[0000] [hostagent] reloading dns nameservers to [192.168.50.1:53] 
INFO[0000] SSH Local Port: 63710                        
INFO[0000] [hostagent] [VZ] - vm state change: running  
INFO[0000] [hostagent] Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running. 
INFO[0000] [hostagent] Waiting for the essential requirement 1 of 1: "ssh" 
INFO[0010] [hostagent] Waiting for the essential requirement 1 of 1: "ssh" 
INFO[0011] [hostagent] The essential requirement 1 of 1 is satisfied 
INFO[0011] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished" 
INFO[0011] [hostagent] The final requirement 1 of 1 is satisfied 
INFO[0011] READY. Run `ssh -F "/Users/nsoffer/.lima/test/ssh.config" lima-test` to open the shell.

if len(tmpl.Bytes) == 0 {
if len(tmpl.Bytes) > 0 {
if createOnly {
if _, err := store.Inspect(tmpl.Name); err == nil {
Copy link
Member

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?

Copy link
Member Author

@jandubois jandubois Jan 23, 2025

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).

@jandubois jandubois merged commit 4456efc into lima-vm:master Jan 23, 2025
29 checks passed
@jandubois jandubois deleted the fix-start-command branch January 23, 2025 19:36
@jandubois jandubois added this to the v1.1.0 (tentative) milestone Jan 24, 2025
@jandubois jandubois mentioned this pull request Feb 5, 2025
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 10, 2025
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 ([#&#8203;3144](lima-vm/lima#3144), thanks to [@&#8203;jandubois](https://github.com/jandubois))
-   DNS:
    -   Fix a regression containers/gvisor-tap-vsock#466 ([#&#8203;3189](lima-vm/lima#3189))
-   QEMU:
    -   Enable SME on macOS 15.3 running on M4 ([#&#8203;3197](lima-vm/lima#3197), [#&#8203;3203](lima-vm/lima#3203), thanks to [@&#8203;jandubois](https://github.com/jandubois))

Full changes: https://github.com/lima-vm/lima/milestone/55?closed=1
Thanks to [@&#8203;alexandear](https://github.com/alexandear) [@&#8203;arixmkii](https://github.com/arixmkii) [@&#8203;jandubois](https://github.com/jandubois) [@&#8203;msgilligan](https://github.com/msgilligan) [@&#8203;olamilekan000](https://github.com/olamilekan000) [@&#8203;rfay](https://github.com/rfay) [@&#8203;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: [@&#8203;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=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants