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(lxd): Select server based on name from result (fixes #151) #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thp-canonical
Copy link
Contributor

@thp-canonical thp-canonical commented Feb 22, 2024

The lxd help list (manpage) command help says that the filter passed in (we pass in name) can be multiple things:

  • A prefix of the instance name
  • A regular expression on the instance name
  • A key/value pair referring to a configuration item
  • A key/value pair with a shorthand key
  • A regular expression matching a config item

To reproduce the issue, just create an LXD instance that has the same prefix as the LXD instance used, by spread, e.g. if spread creates spread-34-ubuntu-20-04, run in a separate terminal:

lxc launch ubuntu:20.04 spread-34-ubuntu-20-04-foo

After that, listing the instances might match more than one (sometimes the order appears "just right", meaning it happens that the one we're looking for just happens to be the first item):

% lxc list --format=csv spread-34-ubuntu-20-04
spread-34-ubuntu-20-04-bar,RUNNING,10.... (eth0),... (eth0),CONTAINER,0
spread-34-ubuntu-20-04,RUNNING,10.... (eth0),... (eth0),CONTAINER (EPHEMERAL),0

(--format=csv used here to make it easier to read)

Alternatively, appending a $ to the name (so it will match as a regex) would also do the trick, but this assumes that the regex-matching will always work like this, and it wouldn't accidentally match other things.

See also: #151, #154 -- I tested this on LXD 5.20

tl;dr: It could be that our exec.Command("lxc", "list", "--format=json", name) matches multiple instances. To account for that, instead of assuming it will always return a slice where the first item is the one we're interested in, iterate over the result and pick the one that matches the name exactly. If no such match exists, return lxdNoServerError (just like the previous len(sjsons) == 0 case).

Copy link

@ZeyadYasser ZeyadYasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants