|
| 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