Skip to content

Commit

Permalink
fix(kuma-cp): memory store cannot delete a parent (#4194)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <[email protected]>
  • Loading branch information
jakubdyszkiewicz authored Apr 19, 2022
1 parent 11b966d commit 8135fdb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/plugins/resources/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (c *memoryStore) delete(r model.Resource, fs ...store.DeleteOptionsFunc) er
for _, child := range record.Children {
_, childRecord := c.findRecord(child.ResourceType, child.Name, child.Mesh)
if childRecord == nil {
return store.ErrorResourceNotFound(model.ResourceType(child.ResourceType), child.Name, child.Mesh)
continue // resource was already deleted
}
obj, err := registry.Global().NewObject(model.ResourceType(child.ResourceType))
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions pkg/test/store/owner_test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,35 @@ func ExecuteOwnerTests(
Expect(err).ToNot(HaveOccurred())
Expect(actual.Items).To(BeEmpty())
})

It("should delete a parent after children is deleted", func() {
// given
meshRes := core_mesh.NewMeshResource()
err := s.Create(context.Background(), meshRes, store.CreateByKey(mesh, model.NoMesh))
Expect(err).ToNot(HaveOccurred())

name := "resource-1"
trRes := &sample_model.TrafficRouteResource{
Spec: &sample_proto.TrafficRoute{
Path: "demo",
},
}
err = s.Create(context.Background(), trRes,
store.CreateByKey(name, mesh),
store.CreatedAt(time.Now()),
store.CreateWithOwner(meshRes))
Expect(err).ToNot(HaveOccurred())

// when children is deleted
err = s.Delete(context.Background(), sample_model.NewTrafficRouteResource(), store.DeleteByKey(name, mesh))

// then
Expect(err).ToNot(HaveOccurred())

// when parent is deleted
err = s.Delete(context.Background(), core_mesh.NewMeshResource(), store.DeleteByKey(mesh, model.NoMesh))

// then
Expect(err).ToNot(HaveOccurred())
})
}

0 comments on commit 8135fdb

Please sign in to comment.