Skip to content

Commit

Permalink
fix: uid related issues
Browse files Browse the repository at this point in the history
* e2e path was not updated.
* Get tried to use empty name and namespace as a filter, not it does not
  use those values if they are empty.
* UpdateMicroVM required all fields.

Related to #291 (issue)
Related to #327 (pr)
  • Loading branch information
yitsushi committed Jan 26, 2022
1 parent 054c6c3 commit 5d0281d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
4 changes: 3 additions & 1 deletion core/application/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func (a *app) DeleteMicroVM(ctx context.Context, uid string) error {
}

if err := a.ports.EventService.Publish(ctx, defaults.TopicMicroVMEvents, &events.MicroVMSpecUpdated{
UID: foundMvm.ID.UID(),
ID: foundMvm.ID.Name(),
Namespace: foundMvm.ID.Namespace(),
UID: foundMvm.ID.UID(),
}); err != nil {
return fmt.Errorf("publishing microvm updated event: %w", err)
}
Expand Down
19 changes: 13 additions & 6 deletions infrastructure/containerd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,22 @@ func (r *containerdRepo) findDigestForSpec(ctx context.Context,
) (*digest.Digest, error) {
var digest *digest.Digest

idLabelFilter := labelFilter(NameLabel(), options.Name)
nsFilter := labelFilter(NamespaceLabel(), options.Namespace)
uidLabelFilter := labelFilter(UIDLabel(), options.UID)
versionFilter := labelFilter(VersionLabel(), options.Version)
combinedFilters := []string{}

combinedFilters := []string{idLabelFilter, nsFilter, uidLabelFilter}
if options.Name != "" {
combinedFilters = append(combinedFilters, labelFilter(NameLabel(), options.Name))
}

if options.Namespace != "" {
combinedFilters = append(combinedFilters, labelFilter(NamespaceLabel(), options.Namespace))
}

if options.UID != "" {
combinedFilters = append(combinedFilters, labelFilter(UIDLabel(), options.UID))
}

if options.Version != "" {
combinedFilters = append(combinedFilters, versionFilter)
combinedFilters = append(combinedFilters, labelFilter(VersionLabel(), options.Version))
}

allFilters := strings.Join(combinedFilters, ",")
Expand Down
18 changes: 11 additions & 7 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestE2E(t *testing.T) {
mvmID = "mvm0"
secondMvmID = "mvm1"
mvmNS = "ns0"
fcPath = "/var/lib/flintlock/vm/%s/%s"
fcPath = "/var/lib/flintlock/vm/%s/%s/%s"

mvmPid1 int
mvmPid2 int
Expand All @@ -47,13 +47,15 @@ func TestE2E(t *testing.T) {
created := u.CreateMVM(flintlockClient, mvmID, mvmNS)
Expect(created.Microvm.Spec.Id).To(Equal(mvmID))

firstMicroVMPath := fmt.Sprintf(fcPath, mvmNS, mvmID, *created.Microvm.Spec.Uid)

log.Println("TEST STEP: getting (and verifying) existing MicroVM")
Eventually(func(g Gomega) error {
g.Expect(fmt.Sprintf(fcPath, mvmNS, mvmID) + "/firecracker.pid").To(BeAnExistingFile())
g.Expect(firstMicroVMPath + "/firecracker.pid").To(BeAnExistingFile())

// verify that firecracker has started and that a pid has been saved
// and that there is actually a running process
mvmPid1 = u.ReadPID(fmt.Sprintf(fcPath, mvmNS, mvmID))
mvmPid1 = u.ReadPID(firstMicroVMPath)
g.Expect(u.PidRunning(mvmPid1)).To(BeTrue())

// get the mVM and check the status
Expand All @@ -67,13 +69,15 @@ func TestE2E(t *testing.T) {
createdSecond := u.CreateMVM(flintlockClient, secondMvmID, mvmNS)
Expect(createdSecond.Microvm.Spec.Id).To(Equal(secondMvmID))

secondMicroVMPath := fmt.Sprintf(fcPath, mvmNS, secondMvmID, *createdSecond.Microvm.Spec.Uid)

log.Println("TEST STEP: listing all MicroVMs")
Eventually(func(g Gomega) error {
g.Expect(fmt.Sprintf(fcPath, mvmNS, secondMvmID) + "/firecracker.pid").To(BeAnExistingFile())
g.Expect(secondMicroVMPath + "/firecracker.pid").To(BeAnExistingFile())

// verify that firecracker has started and that a pid has been saved
// and that there is actually a running process for the new mVM
mvmPid2 = u.ReadPID(fmt.Sprintf(fcPath, mvmNS, secondMvmID))
mvmPid2 = u.ReadPID(secondMicroVMPath)
g.Expect(u.PidRunning(mvmPid2)).To(BeTrue())

// get both the mVMs and check the statuses
Expand All @@ -97,8 +101,8 @@ func TestE2E(t *testing.T) {

Eventually(func(g Gomega) error {
// verify that the vm state dirs have been removed
g.Expect(fmt.Sprintf(fcPath, mvmNS, mvmID)).ToNot(BeAnExistingFile())
g.Expect(fmt.Sprintf(fcPath, mvmNS, secondMvmID)).ToNot(BeAnExistingFile())
g.Expect(firstMicroVMPath).ToNot(BeAnExistingFile())
g.Expect(secondMicroVMPath).ToNot(BeAnExistingFile())

// verify that the firecracker processes are no longer running
g.Expect(u.PidRunning(mvmPid1)).To(BeFalse())
Expand Down

0 comments on commit 5d0281d

Please sign in to comment.