Skip to content

Commit

Permalink
Merge pull request #615 from katexochen/nydus-overlayfs-path
Browse files Browse the repository at this point in the history
snapshotter: add flag to specify nydus-overlayfs path
  • Loading branch information
imeoer authored Sep 9, 2024
2 parents 30f3d65 + 50a833f commit d42d55a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ type ImageConfig struct {
// Configure containerd snapshots interfaces and how to process the snapshots
// requests from containerd
type SnapshotConfig struct {
EnableNydusOverlayFS bool `toml:"enable_nydus_overlayfs"`
EnableKataVolume bool `toml:"enable_kata_volume"`
SyncRemove bool `toml:"sync_remove"`
EnableNydusOverlayFS bool `toml:"enable_nydus_overlayfs"`
NydusOverlayFSPath string `toml:"nydus_overlayfs_path"`
EnableKataVolume bool `toml:"enable_kata_volume"`
SyncRemove bool `toml:"sync_remove"`
}

// Configure cache manager that manages the cache files lifecycle
Expand Down Expand Up @@ -357,7 +358,9 @@ func ParseParameters(args *flags.Args, cfg *SnapshotterConfig) error {
// empty

// --- snapshot configuration
// empty
if args.NydusOverlayFSPath != "" {
cfg.SnapshotsConfig.NydusOverlayFSPath = args.NydusOverlayFSPath
}

// --- metrics configuration
// empty
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestLoadSnapshotterTOMLConfig(t *testing.T) {
},
SnapshotsConfig: SnapshotConfig{
EnableNydusOverlayFS: false,
NydusOverlayFSPath: "nydus-overlayfs",
SyncRemove: false,
},
RemoteConfig: RemoteConfig{
Expand Down Expand Up @@ -92,7 +93,7 @@ func TestLoadSnapshotterTOMLConfig(t *testing.T) {

A.EqualValues(cfg, &exampleConfig)

var args = flags.Args{}
args := flags.Args{}
args.RootDir = "/var/lib/containerd/nydus"
exampleConfig.Root = "/var/lib/containerd/nydus"

Expand Down
6 changes: 6 additions & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Args struct {
RootDir string
NydusdPath string
NydusImagePath string
NydusOverlayFSPath string
DaemonMode string
FsDriver string
LogLevel string
Expand Down Expand Up @@ -68,6 +69,11 @@ func buildFlags(args *Args) []cli.Flag {
Destination: &args.NydusdConfigPath,
DefaultText: constant.DefaultNydusDaemonConfigPath,
},
&cli.StringFlag{
Name: "nydus-overlayfs-path",
Usage: "path of nydus-overlayfs or name of binary from $PATH, defaults to 'nydus-overlayfs'",
Destination: &args.NydusOverlayFSPath,
},
&cli.StringFlag{
Name: "daemon-mode",
Usage: "nydusd daemon working mode, possible values: \"dedicated\", \"multiple\", \"shared\" or \"none\". \"multiple\" is an alias of \"dedicated\" and will be deprecated in v1.0",
Expand Down
2 changes: 2 additions & 0 deletions misc/snapshotter/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ enable_cri_keychain = false
[snapshot]
# Let containerd use nydus-overlayfs mount helper
enable_nydus_overlayfs = false
# Path to the nydus-overlayfs binary or name of the binary in $PATH
nydus_overlayfs_path = "nydus-overlayfs"
# Insert Kata Virtual Volume option to `Mount.Options`
enable_kata_volume = false
# Whether to remove resources when a snapshot is removed
Expand Down
17 changes: 15 additions & 2 deletions snapshot/mount_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ func (o *snapshotter) remoteMountWithExtraOptions(ctx context.Context, s storage
opt := fmt.Sprintf("extraoption=%s", base64.StdEncoding.EncodeToString(no))
overlayOptions = append(overlayOptions, opt)

mountType := "fuse.nydus-overlayfs"
if o.nydusOverlayFSPath != "" {
log.G(ctx).Infof("Using nydus-overlayfs from path: %s", o.nydusOverlayFSPath)
mountType = fmt.Sprintf("fuse.%s", o.nydusOverlayFSPath)
}

return []mount.Mount{
{
Type: "fuse.nydus-overlayfs",
Type: mountType,
Source: "overlay",
Options: overlayOptions,
},
Expand Down Expand Up @@ -136,9 +142,16 @@ func (o *snapshotter) mountWithKataVolume(ctx context.Context, id string, overla

if hasVolume {
log.G(ctx).Debugf("fuse.nydus-overlayfs mount options %v", overlayOptions)

mountType := "fuse.nydus-overlayfs"
if o.nydusOverlayFSPath != "" {
log.G(ctx).Infof("Using nydus-overlayfs from path: %s", o.nydusOverlayFSPath)
mountType = fmt.Sprintf("fuse.%s", o.nydusOverlayFSPath)
}

mounts := []mount.Mount{
{
Type: "fuse.nydus-overlayfs",
Type: mountType,
Source: "overlay",
Options: overlayOptions,
},
Expand Down
11 changes: 10 additions & 1 deletion snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type snapshotter struct {
fs *filesystem.Filesystem
cgroupManager *cgroup.Manager
enableNydusOverlayFS bool
nydusOverlayFSPath string
enableKataVolume bool
syncRemove bool
cleanupOnClose bool
Expand Down Expand Up @@ -291,6 +292,7 @@ func NewSnapshotter(ctx context.Context, cfg *config.SnapshotterConfig) (snapsho
fs: nydusFs,
cgroupManager: cgroupMgr,
enableNydusOverlayFS: cfg.SnapshotsConfig.EnableNydusOverlayFS,
nydusOverlayFSPath: cfg.SnapshotsConfig.NydusOverlayFSPath,
enableKataVolume: cfg.SnapshotsConfig.EnableKataVolume,
cleanupOnClose: cfg.CleanupOnClose,
}, nil
Expand Down Expand Up @@ -877,9 +879,16 @@ func (o *snapshotter) mountProxy(ctx context.Context, s storage.Snapshot) ([]mou
overlayOptions = append(overlayOptions, options...)
}
log.G(ctx).Debugf("fuse.nydus-overlayfs mount options %v", overlayOptions)

mountType := "fuse.nydus-overlayfs"
if o.nydusOverlayFSPath != "" {
log.G(ctx).Debugf("Using nydus-overlayfs from path: %s", o.nydusOverlayFSPath)
mountType = fmt.Sprintf("fuse.%s", o.nydusOverlayFSPath)
}

mounts := []mount.Mount{
{
Type: "fuse.nydus-overlayfs",
Type: mountType,
Source: "overlay",
Options: overlayOptions,
},
Expand Down

0 comments on commit d42d55a

Please sign in to comment.