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:
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):
(--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).
The
lxd help list
(manpage) command help says that the filter passed in (we pass inname
) can be multiple things: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: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):
(
--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, returnlxdNoServerError
(just like the previouslen(sjsons) == 0
case).