mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
NRI: allow plugins to add mounts
Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/containerd/nri/pkg/adaptation"
|
||||
nrilog "github.com/containerd/nri/pkg/log"
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/api/types/mount"
|
||||
"github.com/moby/moby/v2/daemon/container"
|
||||
"github.com/moby/moby/v2/daemon/internal/rootless"
|
||||
"github.com/moby/moby/v2/daemon/pkg/opts"
|
||||
@@ -300,6 +301,9 @@ func applyAdjustments(ctx context.Context, ctr *container.Container, adj *adapta
|
||||
if err := applyEnvVars(ctx, ctr, adj.Env); err != nil {
|
||||
return fmt.Errorf("applying environment variable adjustments: %w", err)
|
||||
}
|
||||
if err := applyMounts(ctx, ctr, adj.Mounts); err != nil {
|
||||
return fmt.Errorf("applying mount adjustments: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -326,3 +330,25 @@ func applyEnvVars(ctx context.Context, ctr *container.Container, envVars []*adap
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyMounts(ctx context.Context, ctr *container.Container, mounts []*adaptation.Mount) error {
|
||||
for _, m := range mounts {
|
||||
var ro bool
|
||||
for _, opt := range m.Options {
|
||||
switch opt {
|
||||
case "ro", "readonly":
|
||||
ro = true
|
||||
default:
|
||||
return fmt.Errorf("mount option %q is not supported", opt)
|
||||
}
|
||||
}
|
||||
log.G(ctx).Debugf("Applying NRI mount: type=%s source=%s target=%s ro=%t", m.Type, m.Source, m.Destination, ro)
|
||||
ctr.HostConfig.Mounts = append(ctr.HostConfig.Mounts, mount.Mount{
|
||||
Type: mount.Type(m.Type),
|
||||
Source: m.Source,
|
||||
Target: m.Destination,
|
||||
ReadOnly: ro,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user