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

fix: uid related issues #367

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/application/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ func TestApp_DeleteMicroVM(t *testing.T) {
gomock.AssignableToTypeOf(context.Background()),
gomock.Eq(defaults.TopicMicroVMEvents),
gomock.Eq(&events.MicroVMSpecUpdated{
UID: testUID,
ID: "id1234",
Namespace: "default",
UID: testUID,
}),
)
},
Expand Down
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