Getting ctr closer to compiling on Windows

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-02-29 10:48:39 -08:00
parent 8d2051232a
commit d4ca79c978
18 changed files with 115 additions and 83 deletions

View file

@ -5,9 +5,9 @@ import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"github.com/Sirupsen/logrus"
"github.com/docker/containerd/specs"
)
type Container interface {
@ -18,7 +18,7 @@ type Container interface {
// Start starts the init process of the container
Start(checkpoint string, s Stdio) (Process, error)
// Exec starts another process in an existing container
Exec(string, ProcessSpec, Stdio) (Process, error)
Exec(string, specs.ProcessSpec, Stdio) (Process, error)
// Delete removes the container's state and any resources
Delete() error
// Processes returns all the containers processes that have been added
@ -175,8 +175,8 @@ func (c *container) Labels() []string {
return c.labels
}
func (c *container) readSpec() (*PlatformSpec, error) {
var spec PlatformSpec
func (c *container) readSpec() (*specs.PlatformSpec, error) {
var spec specs.PlatformSpec
f, err := os.Open(filepath.Join(c.bundle, "config.json"))
if err != nil {
return nil, err
@ -188,18 +188,6 @@ func (c *container) readSpec() (*PlatformSpec, error) {
return &spec, nil
}
func (c *container) State() State {
proc := c.processes["init"]
if proc == nil || proc.pid == 0 {
return Stopped
}
err := syscall.Kill(proc.pid, 0)
if err != nil && err == syscall.ESRCH {
return Stopped
}
return Running
}
func (c *container) Delete() error {
return os.RemoveAll(filepath.Join(c.root, c.id))
}

View file

@ -9,17 +9,18 @@ import (
"syscall"
"time"
"github.com/docker/containerd/specs"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/specs"
ocs "github.com/opencontainers/specs"
)
func getRootIDs(s *PlatformSpec) (int, int, error) {
func getRootIDs(s *specs.PlatformSpec) (int, int, error) {
if s == nil {
return 0, 0, nil
}
var hasUserns bool
for _, ns := range s.Linux.Namespaces {
if ns.Type == specs.UserNamespace {
if ns.Type == ocs.UserNamespace {
hasUserns = true
break
}
@ -32,6 +33,18 @@ func getRootIDs(s *PlatformSpec) (int, int, error) {
return uid, gid, nil
}
func (c *container) State() State {
proc := c.processes["init"]
if proc == nil || proc.pid == 0 {
return Stopped
}
err := syscall.Kill(proc.pid, 0)
if err != nil && err == syscall.ESRCH {
return Stopped
}
return Running
}
func (c *container) Runtime() string {
return c.runtime
}
@ -136,7 +149,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
c: c,
stdio: s,
spec: spec,
processSpec: ProcessSpec(spec.Process),
processSpec: specs.ProcessSpec(spec.Process),
}
p, err := newProcess(config)
if err != nil {
@ -152,7 +165,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
return p, nil
}
func (c *container) Exec(pid string, spec ProcessSpec, s Stdio) (Process, error) {
func (c *container) Exec(pid string, spec specs.ProcessSpec, s Stdio) (Process, error) {
processRoot := filepath.Join(c.root, c.id, pid)
if err := os.Mkdir(processRoot, 0755); err != nil {
return nil, err
@ -187,14 +200,14 @@ func (c *container) Exec(pid string, spec ProcessSpec, s Stdio) (Process, error)
}
func (c *container) getLibctContainer() (libcontainer.Container, error) {
f, err := libcontainer.New(specs.LinuxStateDirectory, libcontainer.Cgroupfs)
f, err := libcontainer.New(ocs.LinuxStateDirectory, libcontainer.Cgroupfs)
if err != nil {
return nil, err
}
return f.Load(c.id)
}
func hostIDFromMap(id uint32, mp []specs.IDMapping) int {
func hostIDFromMap(id uint32, mp []ocs.IDMapping) int {
for _, m := range mp {
if (id >= m.ContainerID) && (id <= (m.ContainerID + m.Size - 1)) {
return int(m.HostID + (id - m.ContainerID))

View file

@ -1,11 +1,20 @@
package runtime
import "errors"
import (
"errors"
func getRootIDs(s *PlatformSpec) (int, int, error) {
"github.com/docker/containerd/specs"
)
func getRootIDs(s *specs.PlatformSpec) (int, int, error) {
return 0, 0, nil
}
// TODO Windows: This will have a different implementation
func (c *container) State() State {
return Running // HACK HACK HACK
}
func (c *container) Runtime() string {
return "windows"
}
@ -38,7 +47,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
// TODO Windows: Implement me.
// This will have a very different implementation on Windows.
func (c *container) Exec(pid string, spec ProcessSpec, s Stdio) (Process, error) {
func (c *container) Exec(pid string, spec specs.ProcessSpec, s Stdio) (Process, error) {
return nil, errors.New("Exec not yet implemented on Windows")
}

View file

@ -8,6 +8,8 @@ import (
"os"
"path/filepath"
"strconv"
"github.com/docker/containerd/specs"
)
type Process interface {
@ -25,7 +27,7 @@ type Process interface {
// has not exited
ExitStatus() (int, error)
// Spec returns the process spec that created the process
Spec() ProcessSpec
Spec() specs.ProcessSpec
// Signal sends the provided signal to the process
Signal(os.Signal) error
// Container returns the container that the process belongs to
@ -39,8 +41,8 @@ type Process interface {
type processConfig struct {
id string
root string
processSpec ProcessSpec
spec *PlatformSpec
processSpec specs.ProcessSpec
spec *specs.PlatformSpec
c *container
stdio Stdio
exec bool
@ -118,7 +120,7 @@ type process struct {
exitPipe *os.File
controlPipe *os.File
container *container
spec ProcessSpec
spec specs.ProcessSpec
stdio Stdio
}
@ -163,7 +165,7 @@ func (p *process) ExitStatus() (int, error) {
return strconv.Atoi(string(data))
}
func (p *process) Spec() ProcessSpec {
func (p *process) Spec() specs.ProcessSpec {
return p.spec
}

View file

@ -3,6 +3,8 @@ package runtime
import (
"errors"
"time"
"github.com/docker/containerd/specs"
)
var (
@ -46,7 +48,7 @@ type state struct {
}
type ProcessState struct {
ProcessSpec
specs.ProcessSpec
Exec bool `json:"exec"`
Stdin string `json:"containerdStdin"`
Stdout string `json:"containerdStdout"`

View file

@ -1,8 +0,0 @@
package runtime
import "github.com/opencontainers/specs"
type (
PlatformSpec specs.LinuxSpec
ProcessSpec specs.Process
)

View file

@ -1,8 +0,0 @@
package runtime
// Temporary Windows version of the spec in lieu of opencontainers/specs having
// Windows support currently.
import "github.com/docker/containerd/specs"
type PlatformSpec specs.WindowsSpec
type ProcessSpec specs.Process