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: update etcd key #24

Merged
merged 1 commit into from
Nov 4, 2024
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
13 changes: 6 additions & 7 deletions pkg/storage/etcd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ func NewObjectStoreNamespaced[T metav1.Object](client clientv3.KV, gvk schema.Gr
}
}

func (o *objectStoreNamespaced[T]) getPrefix() string {
func (o *objectStoreNamespaced[T]) getPrefix(namespace string) string {
if len(namespace) != 0 {
return fmt.Sprintf("%s/%s/%s/%s/", o.gvk.Group, o.gvk.Version, o.gvk.Kind, namespace)
}
return fmt.Sprintf("%s/%s/%s/", o.gvk.Group, o.gvk.Version, o.gvk.Kind)
}

func (o *objectStoreNamespaced[T]) getKey(name, namespace string) string {
if o.namespaced {
return fmt.Sprintf("%s %s/%s", o.getPrefix(), namespace, name)
} else {
return fmt.Sprintf("%s %s", o.getPrefix(), name)
}
return fmt.Sprintf("%s%s", o.getPrefix(namespace), name)
}

func (o *objectStoreNamespaced[T]) Get(ctx context.Context, name, namespace string) (T, error) {
Expand Down Expand Up @@ -78,7 +77,7 @@ func (o *objectStoreNamespaced[T]) List(ctx context.Context, namespace string) (
defer o.Unlock()

var objects []T
key := o.getPrefix()
key := o.getPrefix(namespace)
resp, err := o.etcdclient.Get(ctx, key, clientv3.WithPrefix())
if err != nil {
klog.ErrorS(err, "failed to list report kind=%s", o.gvk.String())
Expand Down
Loading