Support filtering instances by labels#3659
Support filtering instances by labels#3659AkihiroSuda wants to merge 1 commit intolima-vm:masterfrom
Conversation
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>
| 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)") |
There was a problem hiding this comment.
Why not labels?
| 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
Line 31 in f2a2b64
There was a problem hiding this comment.
Could we add an example of labels with values here?
There was a problem hiding this comment.
Why not
labels?
Because we use singular form for other flags such as --mount
| return matches | ||
| } | ||
|
|
||
| // instanceMatchesAllLabels returns true if inst matches all labels, or, labels is nil. |
There was a problem hiding this comment.
| // 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. |
| # 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". |
There was a problem hiding this comment.
| # Arbitrary labels. e.g., "category", "description". | |
| # Arbitrary labels. E.g., "category", "description". |
| 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 | ||
| } |
There was a problem hiding this comment.
Let's cover these lines with a unit test in the file validate_test.go
lima/pkg/limayaml/validate_test.go
Line 4 in f2a2b64
|
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 And if you add So I think 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. |
Originally posted by @AkihiroSuda in #3240 |
Originally posted by @jandubois in #3240 |
Usage:
identifiers, but allows '/'.limactl listinterprets multiple labels as an AND-match query.--filterflag as indockerandkubectl.