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(storage): add resourceVersion to list #51

Merged
Merged
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
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