-
Notifications
You must be signed in to change notification settings - Fork 0
Make the snapshotter configurable #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package containerd | ||
|
|
||
| import "github.com/containerd/containerd" | ||
|
|
||
| // SnapshotterFromGraphDriver returns the containerd snapshotter name based on | ||
| // the supplied graphdriver name. It handles both legacy names and translates | ||
| // them into corresponding containerd snapshotter names. | ||
| func SnapshotterFromGraphDriver(graphDriver string) string { | ||
| switch graphDriver { | ||
| case "overlay", "overlay2": | ||
| return "overlayfs" | ||
| case "windowsfilter": | ||
| return "windows" | ||
| case "": | ||
| return containerd.DefaultSnapshotter | ||
| default: | ||
| return graphDriver | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package containerd | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/containerd/containerd" | ||
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| func TestSnapshotterFromGraphDriver(t *testing.T) { | ||
| testCases := []struct { | ||
| desc string | ||
| input string | ||
| expected string | ||
| }{ | ||
| { | ||
| desc: "empty defaults to containerd default", | ||
| input: "", | ||
| expected: containerd.DefaultSnapshotter, | ||
| }, | ||
| { | ||
| desc: "overlay -> overlayfs", | ||
| input: "overlay", | ||
| expected: "overlayfs", | ||
| }, | ||
| { | ||
| desc: "overlay2 -> overlayfs", | ||
| input: "overlay2", | ||
| expected: "overlayfs", | ||
| }, | ||
| { | ||
| desc: "windowsfilter -> windows", | ||
| input: "windowsfilter", | ||
| expected: "windows", | ||
| }, | ||
| { | ||
| desc: "containerd overlayfs", | ||
| input: "overlayfs", | ||
| expected: "overlayfs", | ||
| }, | ||
| { | ||
| desc: "containerd zfs", | ||
| input: "zfs", | ||
| expected: "zfs", | ||
| }, | ||
| { | ||
| desc: "unknown is unchanged", | ||
| input: "somefuturesnapshotter", | ||
| expected: "somefuturesnapshotter", | ||
| }, | ||
| } | ||
| for _, tc := range testCases { | ||
| tc := tc | ||
| t.Run(tc.desc, func(t *testing.T) { | ||
| assert.Equal(t, SnapshotterFromGraphDriver(tc.input), tc.expected) | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -838,21 +838,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S | |
| } | ||
| } | ||
|
|
||
| if isWindows { | ||
| // On Windows we don't support the environment variable, or a user supplied graphdriver | ||
| d.graphDriver = "windowsfilter" | ||
| } else { | ||
| // Unix platforms however run a single graphdriver for all containers, and it can | ||
| // be set through an environment variable, a daemon start parameter, or chosen through | ||
| // initialization of the layerstore through driver priority order for example. | ||
| if drv := os.Getenv("DOCKER_DRIVER"); drv != "" { | ||
| d.graphDriver = drv | ||
| logrus.Infof("Setting the storage driver from the $DOCKER_DRIVER environment variable (%s)", drv) | ||
| } else { | ||
| d.graphDriver = config.GraphDriver // May still be empty. Layerstore init determines instead. | ||
| } | ||
| } | ||
|
|
||
| d.registryService = registryService | ||
| logger.RegisterPluginGetter(d.PluginStore) | ||
|
|
||
|
|
@@ -942,30 +927,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S | |
| return nil, err | ||
| } | ||
|
|
||
| layerStore, err := layer.NewStoreFromOptions(layer.StoreOptions{ | ||
| Root: config.Root, | ||
| MetadataStorePathTemplate: filepath.Join(config.Root, "image", "%s", "layerdb"), | ||
| GraphDriver: d.graphDriver, | ||
| GraphDriverOptions: config.GraphOptions, | ||
| IDMapping: idMapping, | ||
| PluginGetter: d.PluginStore, | ||
| ExperimentalEnabled: config.Experimental, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // As layerstore initialization may set the driver | ||
| d.graphDriver = layerStore.DriverName() | ||
|
|
||
| // Configure and validate the kernels security support. Note this is a Linux/FreeBSD | ||
| // operation only, so it is safe to pass *just* the runtime OS graphdriver. | ||
| if err := configureKernelSecuritySupport(config, d.graphDriver); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| imageRoot := filepath.Join(config.Root, "image", d.graphDriver) | ||
|
|
||
| d.volumes, err = volumesservice.NewVolumeService(config.Root, d.PluginStore, rootIDs, d) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -979,23 +940,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S | |
| logrus.WithError(err).Warnf("unable to migrate engine ID; a new engine ID will be generated") | ||
| } | ||
|
|
||
| // We have a single tag/reference store for the daemon globally. However, it's | ||
| // stored under the graphdriver. On host platforms which only support a single | ||
| // container OS, but multiple selectable graphdrivers, this means depending on which | ||
| // graphdriver is chosen, the global reference store is under there. For | ||
| // platforms which support multiple container operating systems, this is slightly | ||
| // more problematic as where does the global ref store get located? Fortunately, | ||
| // for Windows, which is currently the only daemon supporting multiple container | ||
| // operating systems, the list of graphdrivers available isn't user configurable. | ||
| // For backwards compatibility, we just put it under the windowsfilter | ||
| // directory regardless. | ||
| refStoreLocation := filepath.Join(imageRoot, `repositories.json`) | ||
| rs, err := refstore.NewReferenceStore(refStoreLocation) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Couldn't create reference store repository: %s", err) | ||
| } | ||
| d.ReferenceStore = rs | ||
|
|
||
| // Check if Devices cgroup is mounted, it is hard requirement for container security, | ||
| // on Linux. | ||
| // | ||
|
|
@@ -1026,14 +970,74 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S | |
|
|
||
| d.linkIndex = newLinkIndex() | ||
|
|
||
| // On Windows we don't support the environment variable, or a user supplied graphdriver | ||
| // Unix platforms however run a single graphdriver for all containers, and it can | ||
| // be set through an environment variable, a daemon start parameter, or chosen through | ||
| // initialization of the layerstore through driver priority order for example. | ||
| graphDriver := os.Getenv("DOCKER_DRIVER") | ||
| if isWindows { | ||
| graphDriver = "windowsfilter" | ||
| } else if graphDriver != "" { | ||
| logrus.Infof("Setting the storage driver from the $DOCKER_DRIVER environment variable (%s)", graphDriver) | ||
| } else { | ||
| graphDriver = config.GraphDriver | ||
| } | ||
|
|
||
| if d.UsesSnapshotter() { | ||
| d.imageService = ctrd.NewService(d.containerdCli, d.containers) | ||
| snapshotter := ctrd.SnapshotterFromGraphDriver(graphDriver) | ||
| // Configure and validate the kernels security support. Note this is a Linux/FreeBSD | ||
| // operation only, so it is safe to pass *just* the runtime OS graphdriver. | ||
| if err := configureKernelSecuritySupport(config, snapshotter); err != nil { | ||
| return nil, err | ||
| } | ||
| d.imageService = ctrd.NewService(d.containerdCli, d.containers, snapshotter) | ||
| d.graphDriver = snapshotter | ||
| } else { | ||
| layerStore, err := layer.NewStoreFromOptions(layer.StoreOptions{ | ||
| Root: config.Root, | ||
| MetadataStorePathTemplate: filepath.Join(config.Root, "image", "%s", "layerdb"), | ||
| GraphDriver: graphDriver, | ||
| GraphDriverOptions: config.GraphOptions, | ||
| IDMapping: idMapping, | ||
| PluginGetter: d.PluginStore, | ||
| ExperimentalEnabled: config.Experimental, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // As layerstore initialization may set the driver | ||
| d.graphDriver = layerStore.DriverName() | ||
|
vvoland marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, somewhat orthogonal to this PR, but I'm actually looking at I'm having a look if we can get rid of it; have some local changes that do so, but it may need a bit of splitting up into commits for easier review (and to get some parts merged in upstream already). |
||
|
|
||
| // Configure and validate the kernels security support. Note this is a Linux/FreeBSD | ||
| // operation only, so it is safe to pass *just* the runtime OS graphdriver. | ||
| if err := configureKernelSecuritySupport(config, d.graphDriver); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| imageRoot := filepath.Join(config.Root, "image", d.graphDriver) | ||
| ifs, err := image.NewFSStoreBackend(filepath.Join(imageRoot, "imagedb")) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // We have a single tag/reference store for the daemon globally. However, it's | ||
| // stored under the graphdriver. On host platforms which only support a single | ||
| // container OS, but multiple selectable graphdrivers, this means depending on which | ||
| // graphdriver is chosen, the global reference store is under there. For | ||
| // platforms which support multiple container operating systems, this is slightly | ||
| // more problematic as where does the global ref store get located? Fortunately, | ||
| // for Windows, which is currently the only daemon supporting multiple container | ||
| // operating systems, the list of graphdrivers available isn't user configurable. | ||
| // For backwards compatibility, we just put it under the windowsfilter | ||
| // directory regardless. | ||
| refStoreLocation := filepath.Join(imageRoot, `repositories.json`) | ||
| rs, err := refstore.NewReferenceStore(refStoreLocation) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("Couldn't create reference store repository: %s", err) | ||
| } | ||
| d.ReferenceStore = rs | ||
|
|
||
| imageStore, err := image.NewImageStore(ifs, layerStore) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.