1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| plugin.Register(&plugin.Registration{ Type: plugin.MetadataPlugin, ID: "bolt", Requires: []plugin.Type{ plugin.ContentPlugin, plugin.SnapshotPlugin, }, Config: &srvconfig.BoltConfig{ ContentSharingPolicy: srvconfig.SharingPolicyShared, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { cs, err := ic.Get(plugin.ContentPlugin)
snapshottersRaw, err := ic.GetByType(plugin.SnapshotPlugin)
snapshotters := make(map[string]snapshots.Snapshotter) for name, sn := range snapshottersRaw { sn, err := sn.Instance() if err != nil { if !plugin.IsSkipPlugin(err) { log.G(ic.Context).WithError(err). Warnf("could not use snapshotter %v in metadata plugin", name) } continue } snapshotters[name] = sn.(snapshots.Snapshotter) } shared := true ic.Meta.Exports["policy"] = srvconfig.SharingPolicyShared if cfg, ok := ic.Config.(*srvconfig.BoltConfig); ok { if cfg.ContentSharingPolicy != "" { if err := cfg.Validate(); err != nil { return nil, err } if cfg.ContentSharingPolicy == srvconfig.SharingPolicyIsolated { ic.Meta.Exports["policy"] = srvconfig.SharingPolicyIsolated shared = false }
log.L.WithField("policy", cfg.ContentSharingPolicy).Info("metadata content store policy set") } }
path := filepath.Join(ic.Root, "meta.db") ic.Meta.Exports["path"] = path db, err := bolt.Open(path, 0644, nil) if err != nil { return nil, err }
var dbopts []metadata.DBOpt if !shared { dbopts = append(dbopts, metadata.WithPolicyIsolated) } mdb := metadata.NewDB(db, cs.(content.Store), snapshotters, dbopts...) if err := mdb.Init(ic.Context); err != nil { return nil, err } return mdb, nil }, }) ...
|