Skip to content

Support filtering instances by labels #3659

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

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

Conversation

AkihiroSuda
Copy link
Member

Usage:

limactl create --name foo --label category=tmp

limactl list --label category=tmp
  • The allowed characters are similar to identifiers, but allows '/'.
  • limactl list interprets multiple labels as an AND-match query.
  • No support for negative match. Eventually we may add the more sophisticated --filter flag as in docker and kubectl.

@AkihiroSuda AkihiroSuda added this to the v1.1.2 milestone Jun 27, 2025
@AkihiroSuda AkihiroSuda added enhancement New feature or request area/cli limactl CLI user experience labels Jun 27, 2025
Usage:
```
limactl create --name foo --label category=tmp

limactl list --label category=tmp
```

- The allowed characters are similar to `identifiers`, but allows '/'.
- `limactl list` interprets multiple labels as an AND-match query.
- No support for negative match. Eventually we may add the more
  sophisticated `--filter` flag as in `docker` and `kubectl`.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@@ -63,6 +63,7 @@ The following legacy flags continue to function:
listCommand.Flags().Bool("json", false, "JSONify output")
listCommand.Flags().BoolP("quiet", "q", false, "Only show names")
listCommand.Flags().Bool("all-fields", false, "Show all fields")
listCommand.Flags().StringToString("label", nil, "Filter instances by labels. Multiple labels can be specified (AND-match)")
Copy link
Member

Choose a reason for hiding this comment

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

Why not labels?

Suggested change
listCommand.Flags().StringToString("label", nil, "Filter instances by labels. Multiple labels can be specified (AND-match)")
listCommand.Flags().StringToString("labels", nil, "Filter instances by labels. Multiple labels can be specified (AND-match)")

For consistency with

hostagentCommand.Flags().StringToString("leases", nil, "Pass default static leases for startup. Eg: '192.168.104.1=52:55:55:b3:bc:d9,192.168.104.2=5a:94:ef:e4:0c:df' ")

Copy link
Member

Choose a reason for hiding this comment

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

Could we add an example of labels with values here?

@@ -77,6 +78,16 @@ func instanceMatches(arg string, instances []string) []string {
return matches
}

// instanceMatchesAllLabels returns true if inst matches all labels, or, labels is nil.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// instanceMatchesAllLabels returns true if inst matches all labels, or, labels is nil.
// instanceMatchesAllLabels returns true if inst matches all labels, or if labels is nil.

@@ -5,6 +5,11 @@
# Default values in this YAML file are specified by `null` instead of Lima's "builtin default" values,
# so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file.

# Arbitrary labels. e.g., "category", "description".
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Arbitrary labels. e.g., "category", "description".
# Arbitrary labels. E.g., "category", "description".

Comment on lines +58 to +63
for k := range y.Labels {
if err := labels.Validate(k); err != nil {
errs = errors.Join(errs, fmt.Errorf("field `labels` has an invalid label %q: %w", k, err))
}
// No validation for label values
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's cover these lines with a unit test in the file validate_test.go

package limayaml

@jandubois
Copy link
Member

I'm not sure if there is really a strong use-case for this functionality.

I've argued before that this filtering is already possible with env and param settings (the latter has some restrictions that I think we should just drop). See #3240 (comment) for previous discussion.

And if you add labels I'm sure sooner or later we will have to make them available to provisioning scripts too, at which point they will be identical to params.

So I think --param category=tmp and --label category=tmp are redundant (once --param is actually implemented). And --env category=tmp would too be very similar (and has the advantage of being available inside the VM as well).

It is kind of like having both labels and annotations, which are really only different in when they are supposed to be used, and keeps confusing people about Kubernetes metadata.

So I guess I'm not convinced we really need this.

@AkihiroSuda AkihiroSuda removed this from the v1.1.2 milestone Jun 28, 2025
@AkihiroSuda AkihiroSuda marked this pull request as draft June 28, 2025 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli limactl CLI user experience enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants