Skip to content

runsc/do: add the option to specify a pre-create network namespace #11586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions runsc/cmd/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Do struct {
ip string
quiet bool
overlay bool
netns string
uidMap idMapSlice
gidMap idMapSlice
}
Expand Down Expand Up @@ -128,6 +129,7 @@ func (c *Do) SetFlags(f *flag.FlagSet) {
f.BoolVar(&c.overlay, "force-overlay", true, "use an overlay. WARNING: disabling gives the command write access to the host")
f.Var(&c.uidMap, "uid-map", "Add a user id mapping [ContainerID, HostID, Size]")
f.Var(&c.gidMap, "gid-map", "Add a group id mapping [ContainerID, HostID, Size]")
f.StringVar(&c.netns, "netns", "", "path to the pre-created network namespace")
}

// Execute implements subcommands.Command.Execute.
Expand Down Expand Up @@ -198,6 +200,12 @@ func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommand
conf.Network = config.NetworkHost
}

} else if c.netns != "" {
netns := specs.LinuxNamespace{
Type: specs.NetworkNamespace,
Path: c.netns,
}
addNamespace(spec, netns)
} else {
switch clean, err := c.setupNet(cid, spec); err {
case errNoDefaultInterface:
Expand Down