Skip to content

Commit 445e26f

Browse files
authored
Merge pull request #4517 from knight42/feat/native-config-root-path
feat(snapshot::native): config root_path
2 parents a5c6381 + c50ff69 commit 445e26f

4 files changed

Lines changed: 56 additions & 15 deletions

File tree

cmd/containerd/builtins_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ import (
2222
_ "github.com/containerd/containerd/runtime/v1/linux"
2323
_ "github.com/containerd/containerd/runtime/v2"
2424
_ "github.com/containerd/containerd/runtime/v2/runc/options"
25-
_ "github.com/containerd/containerd/snapshots/native"
25+
_ "github.com/containerd/containerd/snapshots/native/plugin"
2626
_ "github.com/containerd/containerd/snapshots/overlay/plugin"
2727
)

cmd/containerd/builtins_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
package main
2020

2121
import (
22-
_ "github.com/containerd/containerd/snapshots/native"
22+
_ "github.com/containerd/containerd/snapshots/native/plugin"
2323
)

snapshots/native/native.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,13 @@ import (
2424

2525
"github.com/containerd/containerd/log"
2626
"github.com/containerd/containerd/mount"
27-
"github.com/containerd/containerd/platforms"
28-
"github.com/containerd/containerd/plugin"
2927
"github.com/containerd/containerd/snapshots"
3028
"github.com/containerd/containerd/snapshots/storage"
3129

3230
"github.com/containerd/continuity/fs"
3331
"github.com/pkg/errors"
3432
)
3533

36-
func init() {
37-
plugin.Register(&plugin.Registration{
38-
Type: plugin.SnapshotPlugin,
39-
ID: "native",
40-
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
41-
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
42-
return NewSnapshotter(ic.Root)
43-
},
44-
})
45-
}
46-
4734
type snapshotter struct {
4835
root string
4936
ms *storage.MetaStore

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)