Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ Key mechanisms (all under `pkg/sandbox/`):
rollback to the old export format requires a matching remount/new lifecycle.
Lifecycle IDs are fresh random UUIDs at create/resume and appear in mount targets
and logs. They identify stale requests, not a secret credential or new auth policy.
A mount may request a number of parallel NFS transport connections (the mount
command's `nconnect`, 0..16) with `volumeMounts[].nconnect`; one that requests none
uses the node's `NFS_MOUNT_NCONNECT` (default 1, 0 mounts without the option). envd
passes `nconnect=N` to the kernel only for a nonzero N, and the value a sandbox runs
with is resolved at each start, so the node default applies without a restart.
- **Sandbox proxy** (:5007, `pkg/proxy/`): reverse-proxies incoming traffic from client-proxy to
the sandbox's slot IP and requested port over HTTP or configured HTTPS, enforcing per-sandbox
traffic access tokens through the shared ingress policy. HTTPS backends may use self-signed certificates.
Expand Down
1,314 changes: 659 additions & 655 deletions packages/api/internal/api/api.gen.go

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions packages/api/internal/handlers/sandbox_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,22 @@ func convertAPIVolumesToOrchestratorVolumes(ctx context.Context, sqlClient *sqlc
}
usedPaths[v.Path] = struct{}{}

var nconnect uint32
if v.Nconnect != nil {
if *v.Nconnect < 0 || *v.Nconnect > 16 {
invalidVolumeMounts = append(invalidVolumeMounts, InvalidMount{Index: index, Reason: fmt.Sprintf("nconnect must be between 0 and 16, got %d", *v.Nconnect)})

continue
}
nconnect = uint32(*v.Nconnect)
}

results = append(results, &orchestrator.SandboxVolumeMount{
Id: actualVolume.ID.String(),
Path: v.Path,
Type: actualVolume.VolumeType,
Name: actualVolume.Name,
Id: actualVolume.ID.String(),
Path: v.Path,
Type: actualVolume.VolumeType,
Name: actualVolume.Name,
Nconnect: nconnect,
})
}

Expand Down
60 changes: 60 additions & 0 deletions packages/api/internal/handlers/sandbox_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,32 @@ func TestOrchestrator_convertVolumeMounts(t *testing.T) {
volumeTypes: []string{"local"},
err: InvalidVolumeMountsError{[]InvalidMount{{1, "path '/path' is already used"}}},
},
"nconnect above 16 reports error": {
expectFeatureFlag: true,
expectResources: true,
volumesEnabled: true,
input: []api.SandboxVolumeMount{
{Name: "vol1", Path: "/vol1", Nconnect: new(17)},
},
database: []queries.CreateVolumeParams{
{Name: "vol1", VolumeType: "local"},
},
volumeTypes: []string{"local"},
err: InvalidVolumeMountsError{[]InvalidMount{{0, "nconnect must be between 0 and 16, got 17"}}},
},
"negative nconnect reports error": {
expectFeatureFlag: true,
expectResources: true,
volumesEnabled: true,
input: []api.SandboxVolumeMount{
{Name: "vol1", Path: "/vol1", Nconnect: new(-1)},
},
database: []queries.CreateVolumeParams{
{Name: "vol1", VolumeType: "local"},
},
volumeTypes: []string{"local"},
err: InvalidVolumeMountsError{[]InvalidMount{{0, "nconnect must be between 0 and 16, got -1"}}},
},
"multiple invalid mounts report all errors": {
expectFeatureFlag: true,
expectResources: true,
Expand Down Expand Up @@ -688,6 +714,40 @@ func TestOrchestrator_convertVolumeMounts(t *testing.T) {
{Id: dbVolume.ID.String(), Name: "vol1", Path: "/vol1", Type: "local"},
}, actual)
})

t.Run("nconnect is passed through", func(t *testing.T) {
t.Parallel()

teamID := testutils.CreateTestTeam(t, db)

dbVolume, err := db.SqlcClient.CreateVolume(t.Context(),
queries.CreateVolumeParams{
ID: uuid.New(),
Name: "vol1",
TeamID: teamID,
VolumeType: "local",
},
)
require.NoError(t, err)

ffClient := handlersmocks.NewMockFeatureFlagsClient(t)
ffClient.EXPECT().
BoolFlag(mock.Anything, mock.Anything).
Return(true)

actual, err := convertAPIVolumesToOrchestratorVolumes(
t.Context(), db.SqlcClient, ffClient,
teamID, []api.SandboxVolumeMount{
{Name: "vol1", Path: "/vol1", Nconnect: new(4)},
{Name: "vol1", Path: "/vol2"},
}, &queries.EnvBuild{EnvdVersion: new(minEnvdVersionForVolumes)},
)
require.NoError(t, err)
assert.Equal(t, []*orchestrator.SandboxVolumeMount{
{Id: dbVolume.ID.String(), Name: "vol1", Path: "/vol1", Type: "local", Nconnect: 4},
{Id: dbVolume.ID.String(), Name: "vol1", Path: "/vol2", Type: "local"},
}, actual)
})
}

func TestNewSandboxFromV2(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions packages/api/internal/handlers/sandbox_resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ func convertDatabaseMountsToOrchestratorMounts(volumes []*types.SandboxVolumeMou

for _, item := range volumes {
results = append(results, &orchestratorgrpc.SandboxVolumeMount{
Id: item.ID,
Type: item.Type,
Name: item.Name,
Path: item.Path,
Id: item.ID,
Type: item.Type,
Name: item.Name,
Path: item.Path,
Nconnect: uint32(item.Nconnect),
})
}

Expand Down
11 changes: 9 additions & 2 deletions packages/api/internal/handlers/sandboxes_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,16 @@ func convertFromDBMountsToAPIMounts(mounts []*dbtypes.SandboxVolumeMountConfig)
continue
}

// nconnect is included only when set, so mounts stored before the
// field existed serialize exactly as they did then.
var nconnect *int
if item.Nconnect != 0 {
nconnect = &item.Nconnect
}
results = append(results, api.SandboxVolumeMount{
Name: item.Name,
Path: item.Path,
Name: item.Name,
Path: item.Path,
Nconnect: nconnect,
})
}

Expand Down
9 changes: 5 additions & 4 deletions packages/api/internal/orchestrator/nodemanager/sandboxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ func ConvertOrchestratorMountsToDatabaseMounts(mounts []*orchestrator.SandboxVol

for _, item := range mounts {
results = append(results, &types.SandboxVolumeMountConfig{
ID: item.GetId(),
Type: item.GetType(),
Name: item.GetName(),
Path: item.GetPath(),
ID: item.GetId(),
Type: item.GetType(),
Name: item.GetName(),
Path: item.GetPath(),
Nconnect: int(item.GetNconnect()),
})
}

Expand Down
3 changes: 3 additions & 0 deletions packages/envd/internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion packages/envd/internal/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,17 @@ var nfsOptions = strings.Join([]string{
"retry=0",
}, ",")

// nfsMountOptions returns the full NFS mount option list. nconnect > 0 requests
// that many parallel transport connections; 0 keeps the kernel default of one.
func nfsMountOptions(nconnect int) string {
opts := nfsOptions
if nconnect > 0 {
opts += fmt.Sprintf(",nconnect=%d", nconnect)
}

return "fg,hard," + opts
}

// nfsMountTimeout bounds one mount command. It starts when that mount starts, since
// volumes are mounted one at a time.
const nfsMountTimeout = 10 * time.Second
Expand Down Expand Up @@ -930,12 +941,18 @@ func (a *API) mountNFS(ctx context.Context, logger zerolog.Logger, volume Volume
return 0, err
}

// An absent nconnect keeps the kernel default of one connection.
nconnect := 0
if volume.Nconnect != nil {
nconnect = *volume.Nconnect
}

start := time.Now()
attempts, timeouts := 0, 0
for {
attempts++
mountCtx, cancel := context.WithTimeout(volumeCtx, nfsMountTimeout)
err = a.nfs.Mount(mountCtx, volume.NfsTarget, volume.Path)
err = a.nfs.Mount(mountCtx, volume.NfsTarget, volume.Path, nconnect)
timedOut := mountCtx.Err() != nil || errors.Is(err, context.DeadlineExceeded)
cancel()
if err == nil {
Expand Down
12 changes: 9 additions & 3 deletions packages/envd/internal/api/nfs_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (

// nfsMounter runs the mount operations; tests replace it.
type nfsMounter interface {
Mount(ctx context.Context, nfsTarget, path string) error
// Mount mounts nfsTarget at path. nconnect is the number of parallel NFS
// transport connections to request, 0..16; 0 keeps the kernel default.
Mount(ctx context.Context, nfsTarget, path string, nconnect int) error
// MakeDir creates path and its parents; ctx bounds it even when NFS stops answering.
MakeDir(ctx context.Context, path string) error
// Unmount detaches whatever is mounted at path; nothing mounted is not an error.
Expand All @@ -19,8 +21,12 @@ type nfsMounter interface {

type execNFSMounter struct{}

func (execNFSMounter) Mount(ctx context.Context, nfsTarget, path string) error {
args := []string{"-v", "-t", "nfs", "-o", "fg,hard," + nfsOptions, nfsTarget, path}
func (execNFSMounter) Mount(ctx context.Context, nfsTarget, path string, nconnect int) error {
if nconnect < 0 || nconnect > 16 {
return fmt.Errorf("nconnect must be between 0 and 16, got %d", nconnect)
}

args := []string{"-v", "-t", "nfs", "-o", nfsMountOptions(nconnect), nfsTarget, path}

if output, err := runProcessGroup(ctx, "mount", args...); err != nil {
return fmt.Errorf("`mount %s` failed: %w: %s", strings.Join(args, " "), err, output)
Expand Down
46 changes: 35 additions & 11 deletions packages/envd/internal/api/nfs_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ import (
// fakeNFS records mounts. A path's mount ID changes when it is mounted, unless the
// path is in noop, which models a mount that reports success but does nothing.
type fakeNFS struct {
ids map[string]uint64
next uint64
mounted []string
ops []string // "unmount <path>" and "mount <path>", in call order
failing map[string]error
noop map[string]bool
timeouts map[string]int // mounts of the path that time out before one succeeds
refusals map[string]int // mounts of the path that fail at once before one succeeds
untimed []string // paths whose mount point was created without a deadline
covers map[string]string // mounting the key covers the value's mount
ids map[string]uint64
next uint64
mounted []string
nconnects []int // nconnect of each recorded mount, parallel to mounted
ops []string // "unmount <path>" and "mount <path>", in call order
failing map[string]error
noop map[string]bool
timeouts map[string]int // mounts of the path that time out before one succeeds
refusals map[string]int // mounts of the path that fail at once before one succeeds
untimed []string // paths whose mount point was created without a deadline
covers map[string]string // mounting the key covers the value's mount
}

func newFakeNFS() *fakeNFS {
Expand All @@ -45,8 +46,9 @@ func newFakeNFS() *fakeNFS {
}
}

func (f *fakeNFS) Mount(_ context.Context, _, path string) error {
func (f *fakeNFS) Mount(_ context.Context, _, path string, nconnect int) error {
f.mounted = append(f.mounted, path)
f.nconnects = append(f.nconnects, nconnect)
f.ops = append(f.ops, "mount "+path)
if err := f.failing[path]; err != nil {
return err
Expand Down Expand Up @@ -118,6 +120,28 @@ func TestSetupNFSMountsParentsBeforeChildren(t *testing.T) {
assert.Equal(t, want, fake.mounted)
}

func TestNfsMountOptions(t *testing.T) {
t.Parallel()

base := "fg,hard," + nfsOptions

assert.Equal(t, base, nfsMountOptions(0), "0 keeps the kernel default")
assert.Equal(t, base+",nconnect=1", nfsMountOptions(1))
assert.Equal(t, base+",nconnect=4", nfsMountOptions(4))
}

func TestSetupNFSPassesEachVolumeNconnectToTheMount(t *testing.T) {
t.Parallel()

a, fake, root := newNFSTestAPI(t)
mounts := volumes(root, "a", "b")
mounts[0].Nconnect = new(4)

require.NoError(t, a.setupNFS(t.Context(), zerolog.Nop(), new("lc-1"), mounts))

assert.Equal(t, []int{4, 0}, fake.nconnects)
}

func TestSetupNFSRemountsOnlyForANewLifecycle(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 6 additions & 0 deletions packages/envd/spec/envd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@ components:
path:
type: string
description: Mount path inside the sandbox
nconnect:
type: integer
minimum: 0
maximum: 16
default: 0
description: Number of parallel NFS connections; zero uses the Linux default
required:
- nfs_target
- path
3 changes: 3 additions & 0 deletions packages/orchestrator/orchestrator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ message SandboxVolumeMount {
string path = 2;
string type = 3;
string name = 4;
// Number of parallel NFS transport connections (the mount command's
// nconnect), 1..16. 0 keeps the mount default.
uint32 nconnect = 5;
}

message SandboxNetworkConfig {
Expand Down
4 changes: 4 additions & 0 deletions packages/orchestrator/pkg/cfg/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ type Config struct {
NBDPoolSize int `env:"NBD_POOL_SIZE" envDefault:"64"`
Services []string `env:"ORCHESTRATOR_SERVICES" envDefault:"orchestrator"`
PersistentVolumeMounts map[string]string `env:"PERSISTENT_VOLUME_MOUNTS"`
// NFSMountNconnect is the number of parallel NFS transport connections
// used for volume mounts that do not request one, 0..16. The default of 1
// matches the kernel's; 0 mounts without the nconnect option.
NFSMountNconnect int `env:"NFS_MOUNT_NCONNECT" envDefault:"1"`

// TLS is the mutual TLS settings of the shared port and the peer hop.
TLS TLSConfig
Expand Down
1 change: 1 addition & 0 deletions packages/orchestrator/pkg/sandbox/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ func (s *Sandbox) convertMounts(mounts []VolumeMountConfig) []envd.VolumeMount {
results = append(results, envd.VolumeMount{
NfsTarget: fmt.Sprintf("%s:%s", s.config.NetworkConfig.OrchestratorInSandboxIPAddress, s.NFSMountPath(mount.Name)),
Path: mount.Path,
Nconnect: mount.Nconnect,
})
}

Expand Down
3 changes: 3 additions & 0 deletions packages/orchestrator/pkg/sandbox/envd/envd.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/orchestrator/pkg/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ type VolumeMountConfig struct {
Name string
Path string
Type string
// Nconnect is the number of parallel NFS transport connections, 0..16.
// The value is already resolved: 0 only when the node's default itself is
// 0, so envd mounts without the nconnect option.
Nconnect int
}

type EnvdMetadata struct {
Expand Down
3 changes: 2 additions & 1 deletion packages/orchestrator/pkg/sandbox/volume_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func TestEnvdInitSendsLifecycleQualifiedVolumeTargets(t *testing.T) { //nolint:paralleltest // package-global HTTP client
sbx := newTestSandboxWithBundle("")
sbx.config.NetworkConfig.OrchestratorInSandboxIPAddress = "169.254.0.21"
sbx.Config.VolumeMounts = []VolumeMountConfig{{ID: uuid.New(), Name: "data", Path: "/mnt/data", Type: "test"}}
sbx.Config.VolumeMounts = []VolumeMountConfig{{ID: uuid.New(), Name: "data", Path: "/mnt/data", Type: "test", Nconnect: 4}}
oldLifecycle, newLifecycle := uuid.NewString(), uuid.NewString()
type capture struct {
body envd.PostInitJSONBody
Expand Down Expand Up @@ -52,5 +52,6 @@ func TestEnvdInitSendsLifecycleQualifiedVolumeTargets(t *testing.T) { //nolint:p
require.Len(t, got.body.VolumeMounts, 1)
require.Equal(t, "169.254.0.21:/"+lifecycle+"/data", got.body.VolumeMounts[0].NfsTarget)
require.Equal(t, "/mnt/data", got.body.VolumeMounts[0].Path)
require.Equal(t, 4, got.body.VolumeMounts[0].Nconnect)
}
}
2 changes: 1 addition & 1 deletion packages/orchestrator/pkg/server/retained.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *Server) RestorePaused(ctx context.Context, api *orchestrator.SandboxCon

return nil, err
}
config, err := sandboxConfigOf(api, firecrackerConfigFor(meta, profile, meta.Template.KernelVersion, meta.Template.FirecrackerVersion))
config, err := sandboxConfigOf(api, firecrackerConfigFor(meta, profile, meta.Template.KernelVersion, meta.Template.FirecrackerVersion), s.config.NFSMountNconnect)
if err != nil {
releaseTemplate()

Expand Down
Loading