Skip to content

Commit dab0cbe

Browse files
authored
Merge pull request #21 from sedflix/seperate-package-add-root-path
separate implementation pkg from plugin pkg and add root_path in config
2 parents 76944a9 + a7aca26 commit dab0cbe

2 files changed

Lines changed: 61 additions & 14 deletions

File tree

aufs.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,12 @@ import (
3232

3333
"github.com/containerd/containerd/log"
3434
"github.com/containerd/containerd/mount"
35-
"github.com/containerd/containerd/platforms"
36-
"github.com/containerd/containerd/plugin"
3735
"github.com/containerd/containerd/snapshots"
3836
"github.com/containerd/containerd/snapshots/storage"
3937
"github.com/containerd/continuity/fs"
4038
"github.com/pkg/errors"
4139
)
4240

43-
func init() {
44-
plugin.Register(&plugin.Registration{
45-
Type: plugin.SnapshotPlugin,
46-
ID: "aufs",
47-
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
48-
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
49-
ic.Meta.Exports["root"] = ic.Root
50-
return New(ic.Root)
51-
},
52-
})
53-
}
5441

5542
var (
5643
dirperm sync.Once
@@ -65,7 +52,7 @@ type snapshotter struct {
6552
// New creates a new snapshotter using aufs
6653
func New(root string) (snapshots.Snapshotter, error) {
6754
if err := supported(); err != nil {
68-
return nil, errors.Wrap(plugin.ErrSkipPlugin, err.Error())
55+
return nil, err
6956
}
7057
if err := os.MkdirAll(root, 0700); err != nil {
7158
return nil, err

plugin/plugin.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package plugin
18+
19+
import (
20+
"github.com/containerd/aufs"
21+
"github.com/containerd/containerd/platforms"
22+
"github.com/containerd/containerd/plugin"
23+
"github.com/pkg/errors"
24+
)
25+
26+
27+
// Config represents configuration for the zfs plugin
28+
type Config struct {
29+
// Root directory for the plugin
30+
RootPath string `toml:"root_path"`
31+
}
32+
33+
func init() {
34+
plugin.Register(&plugin.Registration{
35+
Type: plugin.SnapshotPlugin,
36+
ID: "aufs",
37+
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
38+
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
39+
40+
// get config
41+
config, ok := ic.Config.(*Config)
42+
if !ok {
43+
return nil, errors.New("invalid aufs configuration")
44+
}
45+
46+
// use default ic.Root as root path if config doesn't have a valid root path
47+
root := ic.Root
48+
if len(config.RootPath) != 0 {
49+
root = config.RootPath
50+
}
51+
ic.Meta.Exports["root"] = root
52+
53+
snapshotter, err := aufs.New(root)
54+
if err != nil {
55+
return nil, errors.Wrap(plugin.ErrSkipPlugin, err.Error())
56+
}
57+
return snapshotter, nil
58+
},
59+
})
60+
}

0 commit comments

Comments
 (0)