From 50a833f545d76b414780c2f45e33ded6dc58afdf Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:05:38 +0200 Subject: [PATCH] snapshotter: add flag to specify nydus-overlayfs path This allows installation of multiple nydus-overlayfs versions on the same machine. Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- config/config.go | 11 +++++++---- config/config_test.go | 3 ++- internal/flags/flags.go | 6 ++++++ misc/snapshotter/config.toml | 2 ++ snapshot/mount_option.go | 17 +++++++++++++++-- snapshot/snapshot.go | 11 ++++++++++- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 59f2c102fe..f91bb676b5 100644 --- a/config/config.go +++ b/config/config.go @@ -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 @@ -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 diff --git a/config/config_test.go b/config/config_test.go index 28b67a9a8c..5a513dffed 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -51,6 +51,7 @@ func TestLoadSnapshotterTOMLConfig(t *testing.T) { }, SnapshotsConfig: SnapshotConfig{ EnableNydusOverlayFS: false, + NydusOverlayFSPath: "nydus-overlayfs", SyncRemove: false, }, RemoteConfig: RemoteConfig{ @@ -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" diff --git a/internal/flags/flags.go b/internal/flags/flags.go index ef28387081..4358f6cf3c 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -19,6 +19,7 @@ type Args struct { RootDir string NydusdPath string NydusImagePath string + NydusOverlayFSPath string DaemonMode string FsDriver string LogLevel string @@ -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", diff --git a/misc/snapshotter/config.toml b/misc/snapshotter/config.toml index 78dc230e9d..613add3877 100644 --- a/misc/snapshotter/config.toml +++ b/misc/snapshotter/config.toml @@ -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 diff --git a/snapshot/mount_option.go b/snapshot/mount_option.go index 0ac6a0e510..b4c7e56711 100644 --- a/snapshot/mount_option.go +++ b/snapshot/mount_option.go @@ -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, }, @@ -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, }, diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go index 93c72d576f..ca3e7ffedd 100644 --- a/snapshot/snapshot.go +++ b/snapshot/snapshot.go @@ -55,6 +55,7 @@ type snapshotter struct { fs *filesystem.Filesystem cgroupManager *cgroup.Manager enableNydusOverlayFS bool + nydusOverlayFSPath string enableKataVolume bool syncRemove bool cleanupOnClose bool @@ -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 @@ -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, },