daemon: configureLocalContentStore: return concrete types
The interface is defined on the receiver-side, and returning concrete types makes it more transparent what we're creating. As these namespaced wrappers were not exported, let's inline them, so that it's clear at a glance what it's doing. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
375c4eb31c
commit
468d6616bf
1 changed files with 10 additions and 18 deletions
|
@ -16,7 +16,7 @@ import (
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leases.Manager, error) {
|
func (daemon *Daemon) configureLocalContentStore(ns string) (*namespacedContent, *namespacedLeases, error) {
|
||||||
if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil {
|
if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "error creating dir for content store")
|
return nil, nil, errors.Wrap(err, "error creating dir for content store")
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,15 @@ func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leas
|
||||||
}
|
}
|
||||||
md := metadata.NewDB(db, cs, nil)
|
md := metadata.NewDB(db, cs, nil)
|
||||||
daemon.mdDB = db
|
daemon.mdDB = db
|
||||||
return namespacedContentProvider(md.ContentStore(), ns), namespacedLeaseManager(metadata.NewLeaseManager(md), ns), nil
|
cp := &namespacedContent{
|
||||||
|
ns: ns,
|
||||||
|
provider: md.ContentStore(),
|
||||||
|
}
|
||||||
|
lm := &namespacedLeases{
|
||||||
|
ns: ns,
|
||||||
|
manager: metadata.NewLeaseManager(md),
|
||||||
|
}
|
||||||
|
return cp, lm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// withDefaultNamespace sets the given namespace on the context if the current
|
// withDefaultNamespace sets the given namespace on the context if the current
|
||||||
|
@ -105,14 +113,6 @@ func (cp namespacedContent) ReaderAt(ctx context.Context, desc ocispec.Descripto
|
||||||
return cp.provider.ReaderAt(withDefaultNamespace(ctx, cp.ns), desc)
|
return cp.provider.ReaderAt(withDefaultNamespace(ctx, cp.ns), desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// namespacedContentProvider sets the namespace if missing before calling the inner provider
|
|
||||||
func namespacedContentProvider(provider content.Store, ns string) content.Store {
|
|
||||||
return namespacedContent{
|
|
||||||
ns,
|
|
||||||
provider,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type namespacedLeases struct {
|
type namespacedLeases struct {
|
||||||
ns string
|
ns string
|
||||||
manager leases.Manager
|
manager leases.Manager
|
||||||
|
@ -147,11 +147,3 @@ func (nl namespacedLeases) List(ctx context.Context, filter ...string) ([]leases
|
||||||
func (nl namespacedLeases) ListResources(ctx context.Context, lease leases.Lease) ([]leases.Resource, error) {
|
func (nl namespacedLeases) ListResources(ctx context.Context, lease leases.Lease) ([]leases.Resource, error) {
|
||||||
return nl.manager.ListResources(withDefaultNamespace(ctx, nl.ns), lease)
|
return nl.manager.ListResources(withDefaultNamespace(ctx, nl.ns), lease)
|
||||||
}
|
}
|
||||||
|
|
||||||
// namespacedLeaseManager sets the namespace if missing before calling the inner manager
|
|
||||||
func namespacedLeaseManager(manager leases.Manager, ns string) leases.Manager {
|
|
||||||
return namespacedLeases{
|
|
||||||
ns,
|
|
||||||
manager,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue