Skip to content

Commit

Permalink
Merge pull request #51 from fabriziosestito/fix/list-resource-version
Browse files Browse the repository at this point in the history
fix(storage): add resourceVersion to list
  • Loading branch information
flavio authored Dec 2, 2024
2 parents 1ce439f + aa94789 commit a9b73d5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (s *store) Delete(
// If resource version is "0", this interface will get current object at given key
// and send it in an "ADDED" event, before watch starts.
func (s *store) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error) {
s.logger.DebugContext(ctx, "Watching object", "key", key, "options", opts)
s.logger.DebugContext(ctx, "Watching object", "key", key, "resourceVersion", opts.ResourceVersion, "progressNotify", opts.ProgressNotify)

if opts.ResourceVersion == "" {
return s.broadcaster.Watch()
Expand Down Expand Up @@ -224,7 +224,7 @@ func (s *store) Watch(ctx context.Context, key string, opts storage.ListOptions)
// The returned contents may be delayed, but it is guaranteed that they will
// match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'.
func (s *store) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error {
s.logger.DebugContext(ctx, "Getting object", "key", key, "options", opts)
s.logger.DebugContext(ctx, "Getting object", "key", key, "ignoreNotFound", opts.IgnoreNotFound, "resourceVersion", opts.ResourceVersion)

name, namespace := extractNameAndNamespace(key)
if name == "" || namespace == "" {
Expand Down Expand Up @@ -268,7 +268,14 @@ func (s *store) Get(ctx context.Context, key string, opts storage.GetOptions, ob
// The returned contents may be delayed, but it is guaranteed that they will
// match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'.
func (s *store) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error {
s.logger.DebugContext(ctx, "Getting list", "key", key, "options", opts)
s.logger.DebugContext(ctx, "Getting list",
"key", key,
"resourceVersion", opts.ResourceVersion,
"labelSelector", opts.Predicate.Label.String(),
"fieldSelector", opts.Predicate.Field.String(),
"limit", opts.Predicate.Limit,
"continue", opts.Predicate.Continue,
)

queryBuilder := sq.Select("*").From(s.table)
namespace := extractNamespace(key)
Expand Down Expand Up @@ -308,6 +315,11 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
itemsValue.Set(reflect.Append(itemsValue, reflect.ValueOf(obj).Elem()))
}

// TODO: Implement pagination and use a proper resourceVersion
if err := s.Versioner().UpdateList(listObj, 1, "", nil); err != nil {
return storage.NewInternalError(err.Error())
}

return nil
}

Expand Down

0 comments on commit a9b73d5

Please sign in to comment.