Merge pull request #4506 from dmcgowan/refactor-overlay-plugin

Separate overlay implementation from plugin
This commit is contained in:
Phil Estes 2020-08-27 08:48:58 -04:00 committed by GitHub
commit efa0e80913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 27 deletions

View File

@ -23,5 +23,5 @@ import (
_ "github.com/containerd/containerd/runtime/v2" _ "github.com/containerd/containerd/runtime/v2"
_ "github.com/containerd/containerd/runtime/v2/runc/options" _ "github.com/containerd/containerd/runtime/v2/runc/options"
_ "github.com/containerd/containerd/snapshots/native" _ "github.com/containerd/containerd/snapshots/native"
_ "github.com/containerd/containerd/snapshots/overlay" _ "github.com/containerd/containerd/snapshots/overlay/plugin"
) )

View File

@ -29,38 +29,12 @@ import (
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/storage" "github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/continuity/fs" "github.com/containerd/continuity/fs"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func init() {
plugin.Register(&plugin.Registration{
Type: plugin.SnapshotPlugin,
ID: "overlayfs",
Config: &Config{},
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
config, ok := ic.Config.(*Config)
if !ok {
return nil, errors.New("invalid overlay configuration")
}
root := ic.Root
if config.RootPath != "" {
root = config.RootPath
}
ic.Meta.Exports["root"] = root
return NewSnapshotter(root, AsynchronousRemove)
},
})
}
// SnapshotterConfig is used to configure the overlay snapshotter instance // SnapshotterConfig is used to configure the overlay snapshotter instance
type SnapshotterConfig struct { type SnapshotterConfig struct {
asyncRemove bool asyncRemove bool

View File

@ -18,8 +18,40 @@
package overlay package overlay
import (
"errors"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshots/overlay"
)
// Config represents configuration for the overlay plugin. // Config represents configuration for the overlay plugin.
type Config struct { type Config struct {
// Root directory for the plugin // Root directory for the plugin
RootPath string `toml:"root_path"` RootPath string `toml:"root_path"`
} }
func init() {
plugin.Register(&plugin.Registration{
Type: plugin.SnapshotPlugin,
ID: "overlayfs",
Config: &Config{},
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
config, ok := ic.Config.(*Config)
if !ok {
return nil, errors.New("invalid overlay configuration")
}
root := ic.Root
if config.RootPath != "" {
root = config.RootPath
}
ic.Meta.Exports["root"] = root
return overlay.NewSnapshotter(root, overlay.AsynchronousRemove)
},
})
}