From 817c2089aa0e85a3b711d4f93a3dcb97ecd93740 Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 25 Feb 2016 11:23:37 -0800 Subject: [PATCH] Refactors getRootIDs Signed-off-by: John Howard --- runtime/container.go | 25 +++---------------------- runtime/container_linux.go | 22 ++++++++++++++++++++++ runtime/container_windows.go | 5 +++++ runtime/process.go | 2 +- runtime/spec_linux.go | 5 +++++ runtime/spec_windows.go | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 runtime/container_linux.go create mode 100644 runtime/container_windows.go create mode 100644 runtime/spec_linux.go create mode 100644 runtime/spec_windows.go diff --git a/runtime/container.go b/runtime/container.go index a8795c4..f0b6db4 100644 --- a/runtime/container.go +++ b/runtime/container.go @@ -246,14 +246,14 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro return p, nil } -func (c *container) readSpec() (*specs.LinuxSpec, error) { - var spec specs.LinuxSpec +func (c *container) readSpec() (*platformSpec, error) { + var spec platformSpec f, err := os.Open(filepath.Join(c.bundle, "config.json")) if err != nil { return nil, err } defer f.Close() - if err := json.NewDecoder(f).Decode(&spec); err != nil { + if err := json.NewDecoder(f).Decode(&spec.Spec); err != nil { return nil, err } return &spec, nil @@ -389,25 +389,6 @@ func (c *container) getLibctContainer() (libcontainer.Container, error) { return f.Load(c.id) } -func getRootIDs(s *specs.LinuxSpec) (int, int, error) { - if s == nil { - return 0, 0, nil - } - var hasUserns bool - for _, ns := range s.Linux.Namespaces { - if ns.Type == specs.UserNamespace { - hasUserns = true - break - } - } - if !hasUserns { - return 0, 0, nil - } - uid := hostIDFromMap(0, s.Linux.UIDMappings) - gid := hostIDFromMap(0, s.Linux.GIDMappings) - return uid, gid, nil -} - func hostIDFromMap(id uint32, mp []specs.IDMapping) int { for _, m := range mp { if (id >= m.ContainerID) && (id <= (m.ContainerID + m.Size - 1)) { diff --git a/runtime/container_linux.go b/runtime/container_linux.go new file mode 100644 index 0000000..1c0fbef --- /dev/null +++ b/runtime/container_linux.go @@ -0,0 +1,22 @@ +package runtime + +import "github.com/opencontainers/specs" + +func getRootIDs(s *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 { + hasUserns = true + break + } + } + if !hasUserns { + return 0, 0, nil + } + uid := hostIDFromMap(0, s.Linux.UIDMappings) + gid := hostIDFromMap(0, s.Linux.GIDMappings) + return uid, gid, nil +} diff --git a/runtime/container_windows.go b/runtime/container_windows.go new file mode 100644 index 0000000..d9ae7a0 --- /dev/null +++ b/runtime/container_windows.go @@ -0,0 +1,5 @@ +package runtime + +func getRootIDs(s *platformSpec) (int, int, error) { + return 0, 0, nil +} diff --git a/runtime/process.go b/runtime/process.go index 3aa5654..8a6a917 100644 --- a/runtime/process.go +++ b/runtime/process.go @@ -44,7 +44,7 @@ type processConfig struct { id string root string processSpec specs.Process - spec *specs.LinuxSpec + spec *platformSpec c *container stdio Stdio exec bool diff --git a/runtime/spec_linux.go b/runtime/spec_linux.go new file mode 100644 index 0000000..3c6bc22 --- /dev/null +++ b/runtime/spec_linux.go @@ -0,0 +1,5 @@ +package runtime + +import "github.com/opencontainers/specs" + +type platformSpec specs.LinuxSpec diff --git a/runtime/spec_windows.go b/runtime/spec_windows.go new file mode 100644 index 0000000..7273041 --- /dev/null +++ b/runtime/spec_windows.go @@ -0,0 +1,32 @@ +package runtime + +type Spec struct { + // Version is the version of the specification that is supported. + Version string `json:"ociVersion"` + // Platform is the host information for OS and Arch. + // TEMPORARY HACK Platform Platform `json:"platform"` + // Process is the container's main process. + // TEMPORARY HACK Process Process `json:"process"` + // Root is the root information for the container's filesystem. + // TEMPORARY HACK Root Root `json:"root"` + // Hostname is the container's host name. + // TEMPORARY HACK Hostname string `json:"hostname,omitempty"` + // Mounts profile configuration for adding mounts to the container's filesystem. + // TEMPORARY HACK Mounts []Mount `json:"mounts"` + // Hooks are the commands run at various lifecycle events of the container. + // TEMPORARY HACK Hooks Hooks `json:"hooks"` +} + +// TODO Windows - Interim hack. Needs implementing. +type WindowsSpec struct { + Spec + + // Windows is platform specific configuration for Windows based containers. + Windows Windows `json:"windows"` +} + +// Windows contains platform specific configuration for Windows based containers. +type Windows struct { +} + +type platformSpec WindowsSpec