diff --git a/cmd/ctr/run_windows.go b/cmd/ctr/run_windows.go index a54780916..8a430eb3e 100644 --- a/cmd/ctr/run_windows.go +++ b/cmd/ctr/run_windows.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "runtime" "time" "github.com/Sirupsen/logrus" @@ -67,14 +66,10 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) *specs.S return &specs.Spec{ Version: specs.Version, - Platform: specs.Platform{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, - }, Root: specs.Root{ Readonly: context.Bool("readonly"), }, - Process: specs.Process{ + Process: &specs.Process{ Args: args, Terminal: tty, Cwd: cwd, @@ -82,7 +77,7 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) *specs.S User: specs.User{ Username: config.User, }, - ConsoleSize: specs.Box{ + ConsoleSize: &specs.Box{ Height: uint(w), Width: uint(h), }, diff --git a/metrics/cgroups/blkio.go b/metrics/cgroups/blkio.go index cd9ca2963..481ac3541 100644 --- a/metrics/cgroups/blkio.go +++ b/metrics/cgroups/blkio.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/cpu.go b/metrics/cgroups/cpu.go index 79e8de7e8..d6ffee94a 100644 --- a/metrics/cgroups/cpu.go +++ b/metrics/cgroups/cpu.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/hugetlb.go b/metrics/cgroups/hugetlb.go index 3540e1aa2..01c406d23 100644 --- a/metrics/cgroups/hugetlb.go +++ b/metrics/cgroups/hugetlb.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/memory.go b/metrics/cgroups/memory.go index 6780b1168..e942efbdf 100644 --- a/metrics/cgroups/memory.go +++ b/metrics/cgroups/memory.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/metric.go b/metrics/cgroups/metric.go index bc9d170b5..519e524f2 100644 --- a/metrics/cgroups/metric.go +++ b/metrics/cgroups/metric.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/metrics.go b/metrics/cgroups/metrics.go index ed170b0b5..247db4614 100644 --- a/metrics/cgroups/metrics.go +++ b/metrics/cgroups/metrics.go @@ -1,7 +1,10 @@ +// +build linux + package cgroups import ( "errors" + "fmt" "strconv" "sync" @@ -43,6 +46,10 @@ type task struct { cgroup cgroups.Cgroup } +func taskID(id, namespace string) string { + return fmt.Sprintf("%s-%s", id, namespace) +} + // Collector provides the ability to collect container stats and export // them in the prometheus format type Collector struct { @@ -86,10 +93,10 @@ func (c *Collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- p func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error { c.mu.Lock() defer c.mu.Unlock() - if _, ok := c.cgroups[id+namespace]; ok { + if _, ok := c.cgroups[taskID(id, namespace)]; ok { return ErrAlreadyCollected } - c.cgroups[id+namespace] = &task{ + c.cgroups[taskID(id, namespace)] = &task{ id: id, namespace: namespace, cgroup: cg, @@ -102,7 +109,7 @@ func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error { func (c *Collector) Get(id, namespace string) (cgroups.Cgroup, error) { c.mu.Lock() defer c.mu.Unlock() - t, ok := c.cgroups[id+namespace] + t, ok := c.cgroups[taskID(id, namespace)] if !ok { return nil, ErrCgroupNotExists } @@ -113,7 +120,7 @@ func (c *Collector) Get(id, namespace string) (cgroups.Cgroup, error) { func (c *Collector) Remove(id, namespace string) { c.mu.Lock() defer c.mu.Unlock() - delete(c.cgroups, id+namespace) + delete(c.cgroups, taskID(id, namespace)) } func blkioValues(l []cgroups.BlkioEntry) []value { diff --git a/metrics/cgroups/oom.go b/metrics/cgroups/oom.go index 493dd0be2..f38dd3e54 100644 --- a/metrics/cgroups/oom.go +++ b/metrics/cgroups/oom.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/metrics/cgroups/pids.go b/metrics/cgroups/pids.go index 3cb775404..35e7d4fd8 100644 --- a/metrics/cgroups/pids.go +++ b/metrics/cgroups/pids.go @@ -1,3 +1,5 @@ +// +build linux + package cgroups import ( diff --git a/spec_windows.go b/spec_windows.go index 7f0bae0cb..e39e34895 100644 --- a/spec_windows.go +++ b/spec_windows.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "runtime" "github.com/containerd/containerd/api/services/containers/v1" "github.com/containerd/containerd/images" @@ -18,13 +17,9 @@ const pipeRoot = `\\.\pipe` func createDefaultSpec() (*specs.Spec, error) { return &specs.Spec{ Version: specs.Version, - Platform: specs.Platform{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, - }, - Root: specs.Root{}, - Process: specs.Process{ - ConsoleSize: specs.Box{ + Root: specs.Root{}, + Process: &specs.Process{ + ConsoleSize: &specs.Box{ Width: 80, Height: 20, }, diff --git a/windows/container.go b/windows/container.go index 7102fb7c7..3e60bdb88 100644 --- a/windows/container.go +++ b/windows/container.go @@ -142,7 +142,7 @@ func (c *container) Exec(ctx context.Context, opts plugin.ExecOpts) (plugin.Proc return nil, errors.Wrap(err, "failed to unmarshal oci spec") } - p, err := c.ctr.AddProcess(ctx, procSpec, pio) + p, err := c.ctr.AddProcess(ctx, &procSpec, pio) if err != nil { return nil, err } diff --git a/windows/hcs/hcs.go b/windows/hcs/hcs.go index 41fa3caef..d1016a28a 100644 --- a/windows/hcs/hcs.go +++ b/windows/hcs/hcs.go @@ -303,7 +303,7 @@ func (c *Container) GetConfiguration() Configuration { return c.conf } -func (c *Container) AddProcess(ctx context.Context, spec specs.Process, io *IO) (*Process, error) { +func (c *Container) AddProcess(ctx context.Context, spec *specs.Process, io *IO) (*Process, error) { if len(c.processes) == 0 { return nil, errors.New("container not started") } @@ -311,7 +311,7 @@ func (c *Container) AddProcess(ctx context.Context, spec specs.Process, io *IO) return c.addProcess(ctx, spec, io) } -func (c *Container) addProcess(ctx context.Context, spec specs.Process, pio *IO) (*Process, error) { +func (c *Container) addProcess(ctx context.Context, spec *specs.Process, pio *IO) (*Process, error) { // If we don't have a process yet, reused the container pid var pid uint32 if len(c.processes) == 0 {