-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
snapshot: extend the ExtraOption struct
Move ExtraOption to dedicated file and extend it for more usage cases. Signed-off-by: Jiang Liu <[email protected]>
- Loading branch information
Showing
2 changed files
with
99 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2023. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package snapshot | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/containerd/containerd/log" | ||
"github.com/containerd/containerd/mount" | ||
"github.com/containerd/containerd/snapshots/storage" | ||
"github.com/containerd/nydus-snapshotter/config/daemonconfig" | ||
"github.com/containerd/nydus-snapshotter/pkg/daemon" | ||
"github.com/containerd/nydus-snapshotter/pkg/layout" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type ExtraOption struct { | ||
Source string `json:"source"` | ||
Config string `json:"config"` | ||
Snapshotdir string `json:"snapshotdir"` | ||
Version string `json:"fs_version"` | ||
} | ||
|
||
func (o *snapshotter) remoteMountWithExtraOptions(ctx context.Context, s storage.Snapshot, id string, overlayOptions []string) ([]mount.Mount, error) { | ||
source, err := o.fs.BootstrapFile(id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
instance := daemon.RafsSet.Get(id) | ||
daemon, err := o.fs.GetDaemonByID(instance.DaemonID) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "get daemon with ID %s", instance.DaemonID) | ||
} | ||
|
||
var c daemonconfig.DaemonConfig | ||
if daemon.IsSharedDaemon() { | ||
c, err = daemonconfig.NewDaemonConfig(daemon.States.FsDriver, daemon.ConfigFile(instance.SnapshotID)) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Failed to load instance configuration %s", | ||
daemon.ConfigFile(instance.SnapshotID)) | ||
} | ||
} else { | ||
c = daemon.Config | ||
} | ||
configContent, err := c.DumpString() | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "remoteMounts: failed to marshal config") | ||
} | ||
|
||
// get version from bootstrap | ||
f, err := os.Open(source) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "remoteMounts: check bootstrap version: failed to open bootstrap") | ||
} | ||
defer f.Close() | ||
header := make([]byte, 4096) | ||
sz, err := f.Read(header) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "remoteMounts: check bootstrap version: failed to read bootstrap") | ||
} | ||
version, err := layout.DetectFsVersion(header[0:sz]) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "remoteMounts: failed to detect filesystem version") | ||
} | ||
|
||
// when enable nydus-overlayfs, return unified mount slice for runc and kata | ||
extraOption := &ExtraOption{ | ||
Source: source, | ||
Config: configContent, | ||
Snapshotdir: o.snapshotDir(s.ID), | ||
Version: version, | ||
} | ||
no, err := json.Marshal(extraOption) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "remoteMounts: failed to marshal NydusOption") | ||
} | ||
// XXX: Log options without extraoptions as it might contain secrets. | ||
log.G(ctx).Debugf("fuse.nydus-overlayfs mount options %v", overlayOptions) | ||
// base64 to filter easily in `nydus-overlayfs` | ||
opt := fmt.Sprintf("extraoption=%s", base64.StdEncoding.EncodeToString(no)) | ||
overlayOptions = append(overlayOptions, opt) | ||
|
||
return []mount.Mount{ | ||
{ | ||
Type: "fuse.nydus-overlayfs", | ||
Source: "overlay", | ||
Options: overlayOptions, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters