-
Notifications
You must be signed in to change notification settings - Fork 673
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
base: master
Are you sure you want to change the base?
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>
@@ -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)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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' ") |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
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
lima/pkg/limayaml/validate_test.go
Line 4 in f2a2b64
package limayaml |
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. |
Usage:
identifiers
, but allows '/'.limactl list
interprets multiple labels as an AND-match query.--filter
flag as indocker
andkubectl
.