Skip to content

Commit 1e52881

Browse files
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/name
1 parent 74e4999 commit 1e52881

File tree

21 files changed

+254
-124
lines changed

21 files changed

+254
-124
lines changed

api/services/microvm/v1alpha1/microvms.pb.go

Lines changed: 77 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/microvm/v1alpha1/microvms.pb.gw.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/microvm/v1alpha1/microvms.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ message GetMicroVMResponse {
6969

7070
message ListMicroVMsRequest {
7171
string namespace = 1;
72+
optional string name = 2;
7273
}
7374

7475
message ListMicroVMsResponse {

api/services/microvm/v1alpha1/microvms.swagger.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
"in": "path",
6363
"required": true,
6464
"type": "string"
65+
},
66+
{
67+
"name": "name",
68+
"in": "query",
69+
"required": false,
70+
"type": "string"
6571
}
6672
],
6773
"tags": [

buf.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ deps:
55
owner: googleapis
66
repository: googleapis
77
branch: main
8-
commit: 6f119269f95240afb69b052c93992f46
9-
digest: b1-FqoWvdt8ivSWpqSHtadcv6cG7ZzejzQHuj7G5CAUg80=
10-
create_time: 2022-01-22T15:05:34.236772Z
8+
commit: 2b0d6fcd34b440efaa9b46a3513615c0
9+
digest: b1-uGQsCpk4Gpy9kF4336m_551-Zl16v7bI8q1cpWp69j8=
10+
create_time: 2022-01-25T15:12:10.603702Z
1111
- remote: buf.build
1212
owner: grpc-ecosystem
1313
repository: grpc-gateway

0 commit comments

Comments
 (0)