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(kuma-cp): filtering of name prefix on K8S #5517

Merged
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
8 changes: 4 additions & 4 deletions pkg/plugins/resources/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ func (s *KubernetesStore) List(ctx context.Context, rs core_model.ResourceList,
return errors.Wrap(err, "failed to list k8s resources")
}
predicate := func(r core_model.Resource) bool {
if opts.Mesh != "" {
return r.GetMeta().GetMesh() == opts.Mesh
if opts.Mesh != "" && r.GetMeta().GetMesh() != opts.Mesh {
return false
}
if opts.NamePrefix != "" {
return strings.HasPrefix(r.GetMeta().GetName(), opts.NamePrefix)
if opts.NamePrefix != "" && !strings.HasPrefix(r.GetMeta().GetName(), opts.NamePrefix) {
return false
}
return true
}
Expand Down
27 changes: 26 additions & 1 deletion pkg/test/store/store_test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func ExecuteStoreTests(
Expect(list.Items).To(HaveLen(0))
})

It("should return a list of resources with prefix", func() {
It("should return a list of resources with prefix from all meshes", func() {
// given two resources
createResource("list-res-1.demo")
createResource("list-res-2.demo")
Expand All @@ -364,6 +364,31 @@ func ExecuteStoreTests(
}, Equal([]string{"list-res-1.demo", "list-res-2.demo"})))
})

It("should return a list of resources with prefix from the specific mesh", func() {
// given two resources
createResource("list-res-1.demo")
createResource("list-res-2.demo")
createResource("list-mes-1.demo")

list := core_mesh.TrafficRouteResourceList{}

// when
err := s.List(context.Background(), &list, store.ListByNamePrefix("list-res"), store.ListByMesh(mesh))

// then
Expect(err).ToNot(HaveOccurred())
// and
Expect(list.Pagination.Total).To(Equal(uint32(2)))
// and
Expect(list.Items).To(WithTransform(func(itms []*core_mesh.TrafficRouteResource) []string {
var res []string
for _, v := range itms {
res = append(res, v.GetMeta().GetName())
}
return res
}, Equal([]string{"list-res-1.demo", "list-res-2.demo"})))
})

Describe("Pagination", func() {
It("should list all resources using pagination", func() {
// given
Expand Down