Skip to content

Commit 98b0b2a

Browse files
committed
feat: make native root_path configurable
Part of #4514 Signed-off-by: Jian Zeng <[email protected]>
1 parent efa0e80 commit 98b0b2a

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

snapshots/native/plugin/plugin.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
"errors"
21+
22+
"github.com/containerd/containerd/platforms"
23+
"github.com/containerd/containerd/plugin"
24+
"github.com/containerd/containerd/snapshots/native"
25+
)
26+
27+
// Config represents configuration for the native 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: "native",
37+
Config: &Config{},
38+
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
39+
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
40+
41+
config, ok := ic.Config.(*Config)
42+
if !ok {
43+
return nil, errors.New("invalid native configuration")
44+
}
45+
46+
root := ic.Root
47+
if len(config.RootPath) != 0 {
48+
root = config.RootPath
49+
}
50+
51+
return native.NewSnapshotter(root)
52+
},
53+
})
54+
}

0 commit comments

Comments
 (0)