Skip to content

Commit

Permalink
fix: update etcd key (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry authored Nov 4, 2024
1 parent c2f84f7 commit a2b1805
Showing 1 changed file with 6 additions and 7 deletions.
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

0 comments on commit a2b1805

Please sign in to comment.