Add shared content label to namespaces

Signed-off-by: Henry Wang <henwang@amazon.com>
This commit is contained in:
Henry Wang
2022-01-26 19:25:18 +00:00
parent d4641e1ce1
commit 2e080bf491
6 changed files with 121 additions and 9 deletions

View File

@@ -398,7 +398,7 @@ func (cs *contentStore) Writer(ctx context.Context, opts ...content.WriterOpt) (
return nil
}
if cs.shared {
if cs.shared || isSharedContent(tx, wOpts.Desc.Digest) {
if st, err := cs.Store.Info(ctx, wOpts.Desc.Digest); err == nil {
// Ensure the expected size is the same, it is likely
// an error if the size is mismatched but the caller
@@ -706,6 +706,33 @@ func (cs *contentStore) checkAccess(ctx context.Context, dgst digest.Digest) err
})
}
func isSharedContent(tx *bolt.Tx, dgst digest.Digest) bool {
v1bkt := tx.Bucket(bucketKeyVersion)
if v1bkt == nil {
return false
}
// iterate through each namespace
v1c := v1bkt.Cursor()
for nk, _ := v1c.First(); nk != nil; nk, _ = v1c.Next() {
ns := string(nk)
lbkt := getNamespaceLabelsBucket(tx, ns)
if lbkt == nil {
continue
}
// iterate through each label
lbc := lbkt.Cursor()
for k, v := lbc.First(); k != nil; k, v = lbc.Next() {
if string(k) == labels.LabelSharedNamespace {
if string(v) == "true" && getBlobBucket(tx, ns, dgst) != nil {
return true
}
break
}
}
}
return false
}
func validateInfo(info *content.Info) error {
for k, v := range info.Labels {
if err := labels.Validate(k, v); err != nil {