Commit 1e52881
authored
feat: ability to list microvms based on name (#369)
* feat: ability to list microvms based on name
== Background
I considered two routes:
1. Create a new Find() method
2. Add the name field on the List() method
The second option sounds better because it's already a List method, so
makes sense to list mirovms that way.
The extra name field is optional, if it's not provided it works the same
way as before, but if it's provided it will filter based on namespace
and name.
== Changes
=== proto and gRPC server
Changing the definition to use name in List queries.
=== tests
* Update all unit tests.
* Update e2e tests.
* Add extra case to e2e test: List request with name field and expect
only one MicroVM in the response.
=== GetAll function chain
In the background I change the whole GetAll function chain to use a
filter `map[string]string`, that way we can use them to filter based on
different filters.
I considered doing a much cleaner solution something like this:
// WithNamespace is a namespace filter for queries.
func WithNamespace(namespace string) models.ListMicroVMQuery {
return func() (string, string) {
return NamespaceLabel(), namespace
}
}
// WithName is a name filter for queries.
func WithName(name string) models.ListMicroVMQuery {
return func() (string, string) {
return NameLabel(), namespace
}
}
But at the end, I couldn't find a good place for it becasue that should
live under containerd as those labels are containerd specific formats,
but then I couldn't think of an easy way to astract it through ports and
creating an outer layer for filters and put it in ports seems
unnecessary and overkill, so I stuck with the simple key-value map.
Fixes #368
* fix linting issues
* fix: list MicroVMs should return with all namespace/name specs
❯ cat hack/scripts/payload/ListMicroVMs.json \
&& echo "----" \
&& ./hack/scripts/send.sh -m ListMicroVMs \
| dasel -p json --multiple '.microvm.[*].spec.uid'
{
"namespace": "ns1",
"name": "mvm2"
}
----
"01FTBC5ZEKE79FGYNRHPC8MME5"
"01FTBFG9KAC46TVDYGH1JMH665"
❯ cat hack/scripts/payload/ListMicroVMs.json \
&& echo "----" \
&& ./hack/scripts/send.sh -m ListMicroVMs \
| dasel -p json --multiple '.microvm.[*].spec.uid'
{
"namespace": "ns1"
}
----
"01FTBFG9KAC46TVDYGH1JMH665"
"01FTBC51BK5V82XEDBASXAF61Z"
"01FTBC5ZEKE79FGYNRHPC8MME5"
Fixes #370
* Add test case for multiple vms with the same ns/name1 parent 74e4999 commit 1e52881
File tree
21 files changed
+254
-124
lines changed- api/services/microvm/v1alpha1
- core
- application
- models
- ports
- infrastructure
- containerd
- grpc
- mock
- test/e2e
- utils
- userdocs/docs/grpc/services/microvm/v1alpha1
21 files changed
+254
-124
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
0 commit comments