Skip to content

Support filtering in store.Store.List(ctx) #55

Description

@gonzolino

Summary

When listing objects in a store.Store it is currently not possible to filter the results. The List(context.Context) method always lists all objects. The method should be extended to something like List(ctx context.Context, opts ...ListOption) to support filtering.

See List(context.Context, ObjectList, ...ListOption) in controller-runtime as inspiration.

Basic example

How to filter objects currently:

all, err := store.List(ctx)
if err != nil {
	return nil, err
}
filtered []E
sel := labels.SelectorFromSet(labels.Set(map[string]string{"foo": "bar"}))
for _, obj := range all {
	if !sel.Matches(labels.Set(obj.Metadata.Labels)) {
		continue
	}
	filtered = append(filtered, obj)
}
return filtered, nil

How to filter with the new List(ctx context.Context, opts ...ListOption) method:

filtered, err := store.List(ctx, store.MatchingLabels{"foo": "bar"})
return filtered, err

Motivation

Filtering the list of objects is a common use-case and always fetching all objects in the store and then filtering in the client is inefficient. Supporting filtering directly in the store simplifies client code using store.Store, and allows to build optimizations into the store (e.g. indexing labels, caching objects).

This should simplify the implementation of ironcore-dev/ceph-provider#857

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Fields

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions