Skip to content
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

feat: ability to list microvms based on name #369

Merged
merged 4 commits into from
Jan 26, 2022
Merged

Conversation

yitsushi
Copy link
Contributor

@yitsushi yitsushi commented Jan 26, 2022

What this PR does / why we need it:

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.

Fix list results

List endpoints returned only one of the MicroVMs when we have multiple MicroVMs with the same ns/name.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #368
Fixes #370

Special notes for your reviewer:

== 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
@yitsushi yitsushi added kind/feature New feature or request area/api Indicates an issue or PR relates to the APIs labels Jan 26, 2022
@yitsushi
Copy link
Contributor Author

--- PASS: TestE2E (30.16s)
PASS
ok      github.com/weaveworks/flintlock/test/e2e        30.162s
?       github.com/weaveworks/flintlock/test/e2e/utils  [no test files]

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2022

Codecov Report

Merging #369 (8665b52) into main (74e4999) will increase coverage by 0.00%.
The diff coverage is 73.52%.

❗ Current head 8665b52 differs from pull request most recent head 4d97e1e. Consider uploading reports for the commit 4d97e1e to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main     #369   +/-   ##
=======================================
  Coverage   57.37%   57.38%           
=======================================
  Files          51       51           
  Lines        2550     2567   +17     
=======================================
+ Hits         1463     1473   +10     
- Misses        964      970    +6     
- Partials      123      124    +1     
Impacted Files Coverage Δ
core/application/errors.go 0.00% <ø> (ø)
core/application/reconcile.go 0.00% <0.00%> (ø)
infrastructure/containerd/repo.go 73.27% <70.00%> (-1.24%) ⬇️
infrastructure/grpc/server.go 88.59% <75.00%> (-1.22%) ⬇️
core/application/query.go 100.00% <100.00%> (ø)
pkg/process/process.go 39.62% <0.00%> (+1.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74e4999...4d97e1e. Read the comment docs.

@yitsushi
Copy link
Contributor Author

❯ cat hack/scripts/payload/ListMicroVMs.json \
  && echo "----" \
  && ./hack/scripts/send.sh -m ListMicroVMs \
    | dasel -p json --multiple '.microvm.[*].spec.id'
{
  "namespace": "ns1"
}
----
"mvm1"
"mvm2"

❯ cat hack/scripts/payload/ListMicroVMs.json \
  && echo "----" \
  && ./hack/scripts/send.sh -m ListMicroVMs \
    | dasel -p json --multiple '.microvm.[*].spec.id'
{
  "namespace": "ns1",
  "name": "mvm2"
}
----
"mvm2"

    ❯ 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
@yitsushi
Copy link
Contributor Author

❯ 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"

@@ -409,11 +409,18 @@ func TestApp_GetAllMicroVM(t *testing.T) {
expect func(rm *mock.MockMicroVMRepositoryMockRecorder, em *mock.MockEventServiceMockRecorder, im *mock.MockIDServiceMockRecorder, pm *mock.MockMicroVMServiceMockRecorder)
}{
{
name: "empty namespace should return an error",
name: "empty namespace should not return an error",
Copy link
Member

Choose a reason for hiding this comment

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

do we want equivalent test for name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of them are testing that. And actually there is not test that receives the name.

core/application/app_test.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Indicates an issue or PR relates to the APIs kind/feature New feature or request size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List MicroVMs only returns one per namespace/name Ability to list microvms based on namespace and name
3 participants