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 #227

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 (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)
}

Check warning on line 44 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L41-L44

Added lines #L41 - L44 were not covered by tests
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)

Check warning on line 49 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L49

Added line #L49 was not covered by tests
}

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

var objects []T
key := o.getPrefix()
key := o.getPrefix(namespace)

Check warning on line 80 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L80

Added line #L80 was not covered by tests
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