Generalize the plugin package

Remove containerd specific parts of the plugin package to prepare its
move out of the main repository. Separate the plugin registration
singleton into a separate package.

Separating out the plugin package and registration makes it easier to
implement external plugins without creating a dependency loop.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2023-10-12 15:36:02 -07:00
parent a80606bc2d
commit 7b2a918213
65 changed files with 363 additions and 299 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/pkg/timeout"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/plugin/registry"
"github.com/containerd/containerd/plugins"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/log"
@@ -82,7 +83,7 @@ func (bc *BoltConfig) Validate() error {
}
func init() {
plugin.Register(&plugin.Registration{
registry.Register(&plugin.Registration{
Type: plugins.MetadataPlugin,
ID: "bolt",
Requires: []plugin.Type{
@@ -94,7 +95,8 @@ func init() {
ContentSharingPolicy: SharingPolicyShared,
},
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
if err := os.MkdirAll(ic.Root, 0711); err != nil {
root := ic.Properties[plugins.PropertyRootDir]
if err := os.MkdirAll(root, 0711); err != nil {
return nil, err
}
cs, err := ic.Get(plugins.ContentPlugin)
@@ -141,7 +143,7 @@ func init() {
}
}
path := filepath.Join(ic.Root, "meta.db")
path := filepath.Join(root, "meta.db")
ic.Meta.Exports["path"] = path
options := *bolt.DefaultOptions