diff options
author | Kevin Krakauer <krakauer@google.com> | 2018-06-19 21:42:21 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-06-19 21:44:33 -0700 |
commit | 5397963b5d4d57bd3d3668df880b5314ca2fc3d8 (patch) | |
tree | 1e56b21b1248c0d74772e7daf368a6ab91e35911 /runsc/sandbox | |
parent | db66e383c33228c43efbe16ad3b14ae9833879dc (diff) |
runsc: Enable container creation within existing sandboxes.
Containers are created as processes in the sandbox. Of the many things that
don't work yet, the biggest issue is that the fsgofer is launched with its root
as the sandbox's root directory. Thus, when a container is started and wants to
read anything (including the init binary of the container), the gofer tries to
serve from sandbox's root (which basically just has pause), not the container's.
PiperOrigin-RevId: 201294560
Change-Id: I6423aa8830538959c56ae908ce067e4199d627b1
Diffstat (limited to 'runsc/sandbox')
-rw-r--r-- | runsc/sandbox/sandbox.go | 42 | ||||
-rw-r--r-- | runsc/sandbox/sandbox_test.go | 2 |
2 files changed, 33 insertions, 11 deletions
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 0181dc9d4..90b46e247 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -81,9 +81,9 @@ func Create(id string, spec *specs.Spec, conf *boot.Config, bundleDir, consoleSo return s, nil } -// Start starts running the containerized process inside the sandbox. -func (s *Sandbox) Start(cid string, spec *specs.Spec, conf *boot.Config) error { - log.Debugf("Start sandbox %q, pid: %d", s.ID, s.Pid) +// StartRoot starts running the root container process inside the sandbox. +func (s *Sandbox) StartRoot(spec *specs.Spec, conf *boot.Config) error { + log.Debugf("Start root sandbox %q, pid: %d", s.ID, s.Pid) conn, err := s.connect() if err != nil { return err @@ -96,9 +96,7 @@ func (s *Sandbox) Start(cid string, spec *specs.Spec, conf *boot.Config) error { } // Send a message to the sandbox control server to start the root - // container.. - // - // TODO: We need a way to start non-root containers. + // container. if err := conn.Call(boot.RootContainerStart, nil, nil); err != nil { return fmt.Errorf("error starting root container %v: %v", spec.Process.Args, err) } @@ -106,6 +104,26 @@ func (s *Sandbox) Start(cid string, spec *specs.Spec, conf *boot.Config) error { return nil } +// Start starts running a non-root container inside the sandbox. +func (s *Sandbox) Start(spec *specs.Spec, conf *boot.Config) error { + log.Debugf("Start non-root container sandbox %q, pid: %d", s.ID, s.Pid) + conn, err := s.connect() + if err != nil { + return err + } + defer conn.Close() + + args := boot.StartArgs{ + Spec: spec, + Conf: conf, + } + if err := conn.Call(boot.ContainerStart, args, nil); err != nil { + return fmt.Errorf("error starting non-root container %v: %v", spec.Process.Args, err) + } + + return nil +} + // Processes retrieves the list of processes and associated metadata for a // given container in this sandbox. func (s *Sandbox) Processes(cid string) ([]*control.Process, error) { @@ -130,11 +148,11 @@ func (s *Sandbox) Execute(cid string, e *control.ExecArgs) (syscall.WaitStatus, log.Debugf("Executing new process in container %q in sandbox %q", cid, s.ID) conn, err := s.connect() if err != nil { - return 0, fmt.Errorf("error connecting to control server at pid %d: %v", s.Pid, err) + return 0, s.connError(err) } defer conn.Close() - // Send a message to the sandbox control server to start the container.. + // Send a message to the sandbox control server to start the container. var waitStatus uint32 // TODO: Pass in the container id (cid) here. The sandbox // should execute in the context of that container. @@ -168,11 +186,15 @@ func (s *Sandbox) connect() (*urpc.Client, error) { log.Debugf("Connecting to sandbox %q", s.ID) conn, err := client.ConnectTo(boot.ControlSocketAddr(s.ID)) if err != nil { - return nil, fmt.Errorf("error connecting to control server at pid %d: %v", s.Pid, err) + return nil, s.connError(err) } return conn, nil } +func (s *Sandbox) connError(err error) error { + return fmt.Errorf("error connecting to control server at pid %d: %v", s.Pid, err) +} + func (s *Sandbox) createGoferProcess(spec *specs.Spec, conf *boot.Config, bundleDir, binPath string) ([]*os.File, error) { if conf.FileAccess != boot.FileAccessProxy { // Don't start a gofer. The sandbox will access host FS directly. @@ -266,7 +288,7 @@ func (s *Sandbox) createSandboxProcess(spec *specs.Spec, conf *boot.Config, bund } // If the console control socket file is provided, then create a new - // pty master/slave pair and set the tty on the sandox process. + // pty master/slave pair and set the tty on the sandbox process. if consoleEnabled { // setupConsole will send the master on the socket, and return // the slave. diff --git a/runsc/sandbox/sandbox_test.go b/runsc/sandbox/sandbox_test.go index e25290d5e..fee2de283 100644 --- a/runsc/sandbox/sandbox_test.go +++ b/runsc/sandbox/sandbox_test.go @@ -44,7 +44,7 @@ func TestGoferExits(t *testing.T) { t.Fatalf("error creating container: %v", err) } defer s.Destroy() - if err := s.Start("123", spec, conf); err != nil { + if err := s.StartRoot(spec, conf); err != nil { t.Fatalf("error starting container: %v", err) } |