mirror of
https://github.com/rancher/os.git
synced 2025-08-31 22:32:14 +00:00
Bump libcompose and sync dependencies
This commit is contained in:
581
vendor/github.com/docker/containerd/runtime/container.go
generated
vendored
581
vendor/github.com/docker/containerd/runtime/container.go
generated
vendored
@@ -1,581 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/specs"
|
||||
"github.com/docker/containerd/subreaper/exec"
|
||||
ocs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
type Container interface {
|
||||
// ID returns the container ID
|
||||
ID() string
|
||||
// Path returns the path to the bundle
|
||||
Path() string
|
||||
// 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, 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
|
||||
Processes() ([]Process, error)
|
||||
// State returns the containers runtime state
|
||||
State() State
|
||||
// Resume resumes a paused container
|
||||
Resume() error
|
||||
// Pause pauses a running container
|
||||
Pause() error
|
||||
// RemoveProcess removes the specified process from the container
|
||||
RemoveProcess(string) error
|
||||
// Checkpoints returns all the checkpoints for a container
|
||||
Checkpoints() ([]Checkpoint, error)
|
||||
// Checkpoint creates a new checkpoint
|
||||
Checkpoint(Checkpoint) error
|
||||
// DeleteCheckpoint deletes the checkpoint for the provided name
|
||||
DeleteCheckpoint(name string) error
|
||||
// Labels are user provided labels for the container
|
||||
Labels() []string
|
||||
// Pids returns all pids inside the container
|
||||
Pids() ([]int, error)
|
||||
// Stats returns realtime container stats and resource information
|
||||
Stats() (*Stat, error)
|
||||
// Name or path of the OCI compliant runtime used to execute the container
|
||||
Runtime() string
|
||||
// OOM signals the channel if the container received an OOM notification
|
||||
OOM() (OOM, error)
|
||||
// UpdateResource updates the containers resources to new values
|
||||
UpdateResources(*Resource) error
|
||||
|
||||
// Status return the current status of the container.
|
||||
Status() (State, error)
|
||||
}
|
||||
|
||||
type OOM interface {
|
||||
io.Closer
|
||||
FD() int
|
||||
ContainerID() string
|
||||
Flush()
|
||||
Removed() bool
|
||||
}
|
||||
|
||||
type Stdio struct {
|
||||
Stdin string
|
||||
Stdout string
|
||||
Stderr string
|
||||
}
|
||||
|
||||
func NewStdio(stdin, stdout, stderr string) Stdio {
|
||||
for _, s := range []*string{
|
||||
&stdin, &stdout, &stderr,
|
||||
} {
|
||||
if *s == "" {
|
||||
*s = "/dev/null"
|
||||
}
|
||||
}
|
||||
return Stdio{
|
||||
Stdin: stdin,
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
}
|
||||
}
|
||||
|
||||
type ContainerOpts struct {
|
||||
Root string
|
||||
ID string
|
||||
Bundle string
|
||||
Runtime string
|
||||
RuntimeArgs []string
|
||||
Shim string
|
||||
Labels []string
|
||||
NoPivotRoot bool
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// New returns a new container
|
||||
func New(opts ContainerOpts) (Container, error) {
|
||||
c := &container{
|
||||
root: opts.Root,
|
||||
id: opts.ID,
|
||||
bundle: opts.Bundle,
|
||||
labels: opts.Labels,
|
||||
processes: make(map[string]Process),
|
||||
runtime: opts.Runtime,
|
||||
runtimeArgs: opts.RuntimeArgs,
|
||||
shim: opts.Shim,
|
||||
noPivotRoot: opts.NoPivotRoot,
|
||||
timeout: opts.Timeout,
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(c.root, c.id), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(c.root, c.id, StateFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
if err := json.NewEncoder(f).Encode(state{
|
||||
Bundle: c.bundle,
|
||||
Labels: c.labels,
|
||||
Runtime: c.runtime,
|
||||
RuntimeArgs: c.runtimeArgs,
|
||||
Shim: c.shim,
|
||||
NoPivotRoot: opts.NoPivotRoot,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func Load(root, id string, timeout time.Duration) (Container, error) {
|
||||
var s state
|
||||
f, err := os.Open(filepath.Join(root, id, StateFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
if err := json.NewDecoder(f).Decode(&s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &container{
|
||||
root: root,
|
||||
id: id,
|
||||
bundle: s.Bundle,
|
||||
labels: s.Labels,
|
||||
runtime: s.Runtime,
|
||||
runtimeArgs: s.RuntimeArgs,
|
||||
shim: s.Shim,
|
||||
noPivotRoot: s.NoPivotRoot,
|
||||
processes: make(map[string]Process),
|
||||
timeout: timeout,
|
||||
}
|
||||
dirs, err := ioutil.ReadDir(filepath.Join(root, id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, d := range dirs {
|
||||
if !d.IsDir() {
|
||||
continue
|
||||
}
|
||||
pid := d.Name()
|
||||
s, err := readProcessState(filepath.Join(root, id, pid))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := loadProcess(filepath.Join(root, id, pid), pid, c, s)
|
||||
if err != nil {
|
||||
logrus.WithField("id", id).WithField("pid", pid).Debug("containerd: error loading process %s", err)
|
||||
continue
|
||||
}
|
||||
c.processes[pid] = p
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func readProcessState(dir string) (*ProcessState, error) {
|
||||
f, err := os.Open(filepath.Join(dir, "process.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
var s ProcessState
|
||||
if err := json.NewDecoder(f).Decode(&s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
type container struct {
|
||||
// path to store runtime state information
|
||||
root string
|
||||
id string
|
||||
bundle string
|
||||
runtime string
|
||||
runtimeArgs []string
|
||||
shim string
|
||||
processes map[string]Process
|
||||
labels []string
|
||||
oomFds []int
|
||||
noPivotRoot bool
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (c *container) ID() string {
|
||||
return c.id
|
||||
}
|
||||
|
||||
func (c *container) Path() string {
|
||||
return c.bundle
|
||||
}
|
||||
|
||||
func (c *container) Labels() []string {
|
||||
return c.labels
|
||||
}
|
||||
|
||||
func (c *container) readSpec() (*specs.Spec, error) {
|
||||
var spec specs.Spec
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
return &spec, nil
|
||||
}
|
||||
|
||||
func (c *container) Delete() error {
|
||||
err := os.RemoveAll(filepath.Join(c.root, c.id))
|
||||
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "delete", c.id)
|
||||
if derr := exec.Command(c.runtime, args...).Run(); err == nil {
|
||||
err = derr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *container) Processes() ([]Process, error) {
|
||||
out := []Process{}
|
||||
for _, p := range c.processes {
|
||||
out = append(out, p)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *container) RemoveProcess(pid string) error {
|
||||
delete(c.processes, pid)
|
||||
return os.RemoveAll(filepath.Join(c.root, c.id, pid))
|
||||
}
|
||||
|
||||
func (c *container) State() State {
|
||||
proc := c.processes["init"]
|
||||
if proc == nil {
|
||||
return Stopped
|
||||
}
|
||||
return proc.State()
|
||||
}
|
||||
|
||||
func (c *container) Runtime() string {
|
||||
return c.runtime
|
||||
}
|
||||
|
||||
func (c *container) Pause() error {
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "pause", c.id)
|
||||
b, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %q", err.Error(), string(b))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *container) Resume() error {
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "resume", c.id)
|
||||
b, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %q", err.Error(), string(b))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *container) Checkpoints() ([]Checkpoint, error) {
|
||||
dirs, err := ioutil.ReadDir(filepath.Join(c.bundle, "checkpoints"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []Checkpoint
|
||||
for _, d := range dirs {
|
||||
if !d.IsDir() {
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(c.bundle, "checkpoints", d.Name(), "config.json")
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cpt Checkpoint
|
||||
if err := json.Unmarshal(data, &cpt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, cpt)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *container) Checkpoint(cpt Checkpoint) error {
|
||||
if err := os.MkdirAll(filepath.Join(c.bundle, "checkpoints"), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
path := filepath.Join(c.bundle, "checkpoints", cpt.Name)
|
||||
if err := os.Mkdir(path, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(path, "config.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cpt.Created = time.Now()
|
||||
err = json.NewEncoder(f).Encode(cpt)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{
|
||||
"checkpoint",
|
||||
"--image-path", path,
|
||||
}
|
||||
add := func(flags ...string) {
|
||||
args = append(args, flags...)
|
||||
}
|
||||
add(c.runtimeArgs...)
|
||||
if !cpt.Exit {
|
||||
add("--leave-running")
|
||||
}
|
||||
if cpt.Shell {
|
||||
add("--shell-job")
|
||||
}
|
||||
if cpt.Tcp {
|
||||
add("--tcp-established")
|
||||
}
|
||||
if cpt.UnixSockets {
|
||||
add("--ext-unix-sk")
|
||||
}
|
||||
add(c.id)
|
||||
out, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %q", err.Error(), string(out))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *container) DeleteCheckpoint(name string) error {
|
||||
return os.RemoveAll(filepath.Join(c.bundle, "checkpoints", name))
|
||||
}
|
||||
|
||||
func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
|
||||
processRoot := filepath.Join(c.root, c.id, InitProcessID)
|
||||
if err := os.Mkdir(processRoot, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spec, err := c.readSpec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := &processConfig{
|
||||
checkpoint: checkpoint,
|
||||
root: processRoot,
|
||||
id: InitProcessID,
|
||||
c: c,
|
||||
stdio: s,
|
||||
spec: spec,
|
||||
processSpec: specs.ProcessSpec(spec.Process),
|
||||
}
|
||||
p, err := c.newProcess(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := p.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.processes[InitProcessID] = p
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (c *container) Exec(pid string, pspec specs.ProcessSpec, s Stdio) (pp Process, err error) {
|
||||
processRoot := filepath.Join(c.root, c.id, pid)
|
||||
if err := os.Mkdir(processRoot, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
c.RemoveProcess(pid)
|
||||
}
|
||||
}()
|
||||
spec, err := c.readSpec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := &processConfig{
|
||||
exec: true,
|
||||
id: pid,
|
||||
root: processRoot,
|
||||
c: c,
|
||||
processSpec: pspec,
|
||||
spec: spec,
|
||||
stdio: s,
|
||||
}
|
||||
p, err := c.newProcess(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := p.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.processes[pid] = p
|
||||
return p, nil
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *container) Pids() ([]int, error) {
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "ps", "--format=json", c.id)
|
||||
out, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %q", err.Error(), out)
|
||||
}
|
||||
var pids []int
|
||||
if err := json.Unmarshal(out, &pids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
func (c *container) Stats() (*Stat, error) {
|
||||
now := time.Now()
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "events", "--stats", c.id)
|
||||
out, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %q", err.Error(), out)
|
||||
}
|
||||
s := struct {
|
||||
Data *Stat `json:"data"`
|
||||
}{}
|
||||
if err := json.Unmarshal(out, &s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Data.Timestamp = now
|
||||
return s.Data, nil
|
||||
}
|
||||
|
||||
// Status implements the runtime Container interface.
|
||||
func (c *container) Status() (State, error) {
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "state", c.id)
|
||||
|
||||
out, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s: %q", err.Error(), out)
|
||||
}
|
||||
|
||||
// We only require the runtime json output to have a top level Status field.
|
||||
var s struct {
|
||||
Status State `json:"status"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &s); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.Status, nil
|
||||
}
|
||||
|
||||
func (c *container) writeEventFD(root string, cfd, efd int) error {
|
||||
f, err := os.OpenFile(filepath.Join(root, "cgroup.event_control"), os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(fmt.Sprintf("%d %d", efd, cfd))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *container) newProcess(config *processConfig) (Process, error) {
|
||||
if c.shim == "" {
|
||||
return newDirectProcess(config)
|
||||
}
|
||||
return newProcess(config)
|
||||
}
|
||||
|
||||
type waitArgs struct {
|
||||
pid int
|
||||
err error
|
||||
}
|
||||
|
||||
// isAlive checks if the shim that launched the container is still alive
|
||||
func isAlive(cmd *exec.Cmd) (bool, error) {
|
||||
if err := syscall.Kill(cmd.Process.Pid, 0); err != nil {
|
||||
if err == syscall.ESRCH {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
type oom struct {
|
||||
id string
|
||||
root string
|
||||
control *os.File
|
||||
eventfd int
|
||||
}
|
||||
|
||||
func (o *oom) ContainerID() string {
|
||||
return o.id
|
||||
}
|
||||
|
||||
func (o *oom) FD() int {
|
||||
return o.eventfd
|
||||
}
|
||||
|
||||
func (o *oom) Flush() {
|
||||
buf := make([]byte, 8)
|
||||
syscall.Read(o.eventfd, buf)
|
||||
}
|
||||
|
||||
func (o *oom) Removed() bool {
|
||||
_, err := os.Lstat(filepath.Join(o.root, "cgroup.event_control"))
|
||||
return os.IsNotExist(err)
|
||||
}
|
||||
|
||||
func (o *oom) Close() error {
|
||||
err := syscall.Close(o.eventfd)
|
||||
if cerr := o.control.Close(); err == nil {
|
||||
err = cerr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type message struct {
|
||||
Level string `json:"level"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func readLogMessages(path string) ([]message, error) {
|
||||
var out []message
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
dec := json.NewDecoder(f)
|
||||
for {
|
||||
var m message
|
||||
if err := dec.Decode(&m); err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
return out, nil
|
||||
}
|
134
vendor/github.com/docker/containerd/runtime/container_linux.go
generated
vendored
134
vendor/github.com/docker/containerd/runtime/container_linux.go
generated
vendored
@@ -1,134 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
"github.com/docker/containerd/subreaper/exec"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
ocs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
func (c *container) getLibctContainer() (libcontainer.Container, error) {
|
||||
runtimeRoot := "/run/runc"
|
||||
|
||||
// Check that the root wasn't changed
|
||||
for _, opt := range c.runtimeArgs {
|
||||
if strings.HasPrefix(opt, "--root=") {
|
||||
runtimeRoot = strings.TrimPrefix(opt, "--root=")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
f, err := libcontainer.New(runtimeRoot, libcontainer.Cgroupfs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.Load(c.id)
|
||||
}
|
||||
|
||||
func (c *container) OOM() (OOM, error) {
|
||||
container, err := c.getLibctContainer()
|
||||
if err != nil {
|
||||
if lerr, ok := err.(libcontainer.Error); ok {
|
||||
// with oom registration sometimes the container can run, exit, and be destroyed
|
||||
// faster than we can get the state back so we can just ignore this
|
||||
if lerr.Code() == libcontainer.ContainerNotExists {
|
||||
return nil, ErrContainerExited
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
state, err := container.State()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
memoryPath := state.CgroupPaths["memory"]
|
||||
return c.getMemeoryEventFD(memoryPath)
|
||||
}
|
||||
|
||||
func u64Ptr(i uint64) *uint64 { return &i }
|
||||
|
||||
func (c *container) UpdateResources(r *Resource) error {
|
||||
sr := ocs.Resources{
|
||||
Memory: &ocs.Memory{
|
||||
Limit: u64Ptr(uint64(r.Memory)),
|
||||
Reservation: u64Ptr(uint64(r.MemoryReservation)),
|
||||
Swap: u64Ptr(uint64(r.MemorySwap)),
|
||||
Kernel: u64Ptr(uint64(r.KernelMemory)),
|
||||
},
|
||||
CPU: &ocs.CPU{
|
||||
Shares: u64Ptr(uint64(r.CPUShares)),
|
||||
Quota: u64Ptr(uint64(r.CPUQuota)),
|
||||
Period: u64Ptr(uint64(r.CPUPeriod)),
|
||||
Cpus: &r.CpusetCpus,
|
||||
Mems: &r.CpusetMems,
|
||||
},
|
||||
BlockIO: &ocs.BlockIO{
|
||||
Weight: &r.BlkioWeight,
|
||||
},
|
||||
}
|
||||
|
||||
srStr := bytes.NewBuffer(nil)
|
||||
if err := json.NewEncoder(srStr).Encode(&sr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "update", "-r", "-", c.id)
|
||||
cmd := exec.Command(c.runtime, args...)
|
||||
cmd.Stdin = srStr
|
||||
b, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf(string(b))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRootIDs(s *specs.Spec) (int, int, error) {
|
||||
if s == nil {
|
||||
return 0, 0, nil
|
||||
}
|
||||
var hasUserns bool
|
||||
for _, ns := range s.Linux.Namespaces {
|
||||
if ns.Type == ocs.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 (c *container) getMemeoryEventFD(root string) (*oom, error) {
|
||||
f, err := os.Open(filepath.Join(root, "memory.oom_control"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fd, _, serr := syscall.RawSyscall(syscall.SYS_EVENTFD2, 0, syscall.FD_CLOEXEC, 0)
|
||||
if serr != 0 {
|
||||
f.Close()
|
||||
return nil, serr
|
||||
}
|
||||
if err := c.writeEventFD(root, int(f.Fd()), int(fd)); err != nil {
|
||||
syscall.Close(int(fd))
|
||||
f.Close()
|
||||
return nil, err
|
||||
}
|
||||
return &oom{
|
||||
root: root,
|
||||
id: c.id,
|
||||
eventfd: int(fd),
|
||||
control: f,
|
||||
}, nil
|
||||
}
|
19
vendor/github.com/docker/containerd/runtime/container_solaris.go
generated
vendored
19
vendor/github.com/docker/containerd/runtime/container_solaris.go
generated
vendored
@@ -1,19 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
)
|
||||
|
||||
func (c *container) OOM() (OOM, error) {
|
||||
return nil, errors.New("runtime OOM() not implemented on Solaris")
|
||||
}
|
||||
|
||||
func (c *container) UpdateResources(r *Resource) error {
|
||||
return errors.New("runtime UpdateResources() not implemented on Solaris")
|
||||
}
|
||||
|
||||
func getRootIDs(s *specs.Spec) (int, int, error) {
|
||||
return 0, 0, errors.New("runtime getRootIDs() not implemented on Solaris")
|
||||
}
|
283
vendor/github.com/docker/containerd/runtime/direct_process.go
generated
vendored
283
vendor/github.com/docker/containerd/runtime/direct_process.go
generated
vendored
@@ -1,283 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
"github.com/docker/containerd/subreaper"
|
||||
"github.com/docker/containerd/subreaper/exec"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
)
|
||||
|
||||
type directProcess struct {
|
||||
*process
|
||||
sync.WaitGroup
|
||||
|
||||
io stdio
|
||||
console libcontainer.Console
|
||||
consolePath string
|
||||
exec bool
|
||||
checkpoint string
|
||||
specs *specs.Spec
|
||||
}
|
||||
|
||||
func newDirectProcess(config *processConfig) (*directProcess, error) {
|
||||
lp, err := newProcess(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &directProcess{
|
||||
specs: config.spec,
|
||||
process: lp,
|
||||
exec: config.exec,
|
||||
checkpoint: config.checkpoint,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *directProcess) CloseStdin() error {
|
||||
if d.io.stdin != nil {
|
||||
return d.io.stdin.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *directProcess) Resize(w, h int) error {
|
||||
if d.console == nil {
|
||||
return nil
|
||||
}
|
||||
ws := term.Winsize{
|
||||
Width: uint16(w),
|
||||
Height: uint16(h),
|
||||
}
|
||||
return term.SetWinsize(d.console.Fd(), &ws)
|
||||
}
|
||||
|
||||
func (d *directProcess) openIO() (*os.File, *os.File, *os.File, error) {
|
||||
uid, gid, err := getRootIDs(d.specs)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
if d.spec.Terminal {
|
||||
console, err := libcontainer.NewConsole(uid, gid)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
d.console = console
|
||||
d.consolePath = console.Path()
|
||||
stdin, err := os.OpenFile(d.stdio.Stdin, syscall.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
go io.Copy(console, stdin)
|
||||
stdout, err := os.OpenFile(d.stdio.Stdout, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
d.Add(1)
|
||||
go func() {
|
||||
io.Copy(stdout, console)
|
||||
console.Close()
|
||||
d.Done()
|
||||
}()
|
||||
d.io.stdin = stdin
|
||||
d.io.stdout = stdout
|
||||
d.io.stderr = stdout
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
|
||||
stdin, err := os.OpenFile(d.stdio.Stdin, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
stdout, err := os.OpenFile(d.stdio.Stdout, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
stderr, err := os.OpenFile(d.stdio.Stderr, syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
d.io.stdin = stdin
|
||||
d.io.stdout = stdout
|
||||
d.io.stderr = stderr
|
||||
return stdin, stdout, stderr, nil
|
||||
}
|
||||
|
||||
func (d *directProcess) loadCheckpoint(bundle string) (*Checkpoint, error) {
|
||||
if d.checkpoint == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
f, err := os.Open(filepath.Join(bundle, "checkpoints", d.checkpoint, "config.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
var cpt Checkpoint
|
||||
if err := json.NewDecoder(f).Decode(&cpt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cpt, nil
|
||||
}
|
||||
|
||||
func (d *directProcess) Start() error {
|
||||
cwd, err := filepath.Abs(d.root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stdin, stdout, stderr, err := d.openIO()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
checkpoint, err := d.loadCheckpoint(d.container.bundle)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logPath := filepath.Join(cwd, "log.json")
|
||||
args := append([]string{
|
||||
"--log", logPath,
|
||||
"--log-format", "json",
|
||||
}, d.container.runtimeArgs...)
|
||||
if d.exec {
|
||||
args = append(args, "exec",
|
||||
"--process", filepath.Join(cwd, "process.json"),
|
||||
"--console", d.consolePath,
|
||||
)
|
||||
} else if checkpoint != nil {
|
||||
args = append(args, "restore",
|
||||
"--image-path", filepath.Join(d.container.bundle, "checkpoints", checkpoint.Name),
|
||||
)
|
||||
add := func(flags ...string) {
|
||||
args = append(args, flags...)
|
||||
}
|
||||
if checkpoint.Shell {
|
||||
add("--shell-job")
|
||||
}
|
||||
if checkpoint.Tcp {
|
||||
add("--tcp-established")
|
||||
}
|
||||
if checkpoint.UnixSockets {
|
||||
add("--ext-unix-sk")
|
||||
}
|
||||
if d.container.noPivotRoot {
|
||||
add("--no-pivot")
|
||||
}
|
||||
} else {
|
||||
args = append(args, "start",
|
||||
"--bundle", d.container.bundle,
|
||||
"--console", d.consolePath,
|
||||
)
|
||||
if d.container.noPivotRoot {
|
||||
args = append(args, "--no-pivot")
|
||||
}
|
||||
}
|
||||
args = append(args,
|
||||
"-d",
|
||||
"--pid-file", filepath.Join(cwd, "pid"),
|
||||
d.container.id,
|
||||
)
|
||||
cmd := exec.Command(d.container.runtime, args...)
|
||||
cmd.Dir = d.container.bundle
|
||||
cmd.Stdin = stdin
|
||||
cmd.Stdout = stdout
|
||||
cmd.Stderr = stderr
|
||||
// set the parent death signal to SIGKILL so that if containerd dies the container
|
||||
// process also dies
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
||||
exitSubscription := subreaper.Subscribe()
|
||||
err = d.startCmd(cmd)
|
||||
if err != nil {
|
||||
subreaper.Unsubscribe(exitSubscription)
|
||||
d.delete()
|
||||
return err
|
||||
}
|
||||
|
||||
go d.watch(cmd, exitSubscription)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *directProcess) watch(cmd *exec.Cmd, exitSubscription *subreaper.Subscription) {
|
||||
defer subreaper.Unsubscribe(exitSubscription)
|
||||
defer d.delete()
|
||||
|
||||
f, err := os.OpenFile(path.Join(d.root, ExitFile), syscall.O_WRONLY, 0)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
exitCode := 0
|
||||
if err = cmd.Wait(); err != nil {
|
||||
if exitError, ok := err.(exec.ExitCodeError); ok {
|
||||
exitCode = exitError.Code
|
||||
}
|
||||
}
|
||||
|
||||
if exitCode == 0 {
|
||||
pid, err := d.getPidFromFile()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
exitSubscription.SetPid(pid)
|
||||
exitCode = exitSubscription.Wait()
|
||||
}
|
||||
|
||||
writeInt(path.Join(d.root, ExitStatusFile), exitCode)
|
||||
}
|
||||
|
||||
func (d *directProcess) delete() {
|
||||
if d.console != nil {
|
||||
d.console.Close()
|
||||
}
|
||||
d.io.Close()
|
||||
d.Wait()
|
||||
if !d.exec {
|
||||
exec.Command(d.container.runtime, append(d.container.runtimeArgs, "delete", d.container.id)...).Run()
|
||||
}
|
||||
}
|
||||
|
||||
func writeInt(path string, i int) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = fmt.Fprintf(f, "%d", i)
|
||||
return err
|
||||
}
|
||||
|
||||
type stdio struct {
|
||||
stdin *os.File
|
||||
stdout *os.File
|
||||
stderr *os.File
|
||||
}
|
||||
|
||||
func (s stdio) Close() error {
|
||||
err := s.stdin.Close()
|
||||
if oerr := s.stdout.Close(); err == nil {
|
||||
err = oerr
|
||||
}
|
||||
if oerr := s.stderr.Close(); err == nil {
|
||||
err = oerr
|
||||
}
|
||||
return err
|
||||
}
|
340
vendor/github.com/docker/containerd/runtime/process.go
generated
vendored
340
vendor/github.com/docker/containerd/runtime/process.go
generated
vendored
@@ -1,340 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
"github.com/docker/containerd/subreaper/exec"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type Process interface {
|
||||
io.Closer
|
||||
|
||||
// ID of the process.
|
||||
// This is either "init" when it is the container's init process or
|
||||
// it is a user provided id for the process similar to the container id
|
||||
ID() string
|
||||
CloseStdin() error
|
||||
Resize(int, int) error
|
||||
// ExitFD returns the fd the provides an event when the process exits
|
||||
ExitFD() int
|
||||
// ExitStatus returns the exit status of the process or an error if it
|
||||
// has not exited
|
||||
ExitStatus() (int, error)
|
||||
// Spec returns the process spec that created the process
|
||||
Spec() specs.ProcessSpec
|
||||
// Signal sends the provided signal to the process
|
||||
Signal(os.Signal) error
|
||||
// Container returns the container that the process belongs to
|
||||
Container() Container
|
||||
// Stdio of the container
|
||||
Stdio() Stdio
|
||||
// SystemPid is the pid on the system
|
||||
SystemPid() int
|
||||
// State returns if the process is running or not
|
||||
State() State
|
||||
// Start executes the process
|
||||
Start() error
|
||||
}
|
||||
|
||||
type processConfig struct {
|
||||
id string
|
||||
root string
|
||||
processSpec specs.ProcessSpec
|
||||
spec *specs.Spec
|
||||
c *container
|
||||
stdio Stdio
|
||||
exec bool
|
||||
checkpoint string
|
||||
}
|
||||
|
||||
func newProcess(config *processConfig) (*process, error) {
|
||||
p := &process{
|
||||
root: config.root,
|
||||
id: config.id,
|
||||
container: config.c,
|
||||
spec: config.processSpec,
|
||||
stdio: config.stdio,
|
||||
}
|
||||
uid, gid, err := getRootIDs(config.spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(config.root, "process.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
ps := ProcessState{
|
||||
ProcessSpec: config.processSpec,
|
||||
Exec: config.exec,
|
||||
PlatformProcessState: PlatformProcessState{
|
||||
Checkpoint: config.checkpoint,
|
||||
RootUID: uid,
|
||||
RootGID: gid,
|
||||
},
|
||||
Stdin: config.stdio.Stdin,
|
||||
Stdout: config.stdio.Stdout,
|
||||
Stderr: config.stdio.Stderr,
|
||||
RuntimeArgs: config.c.runtimeArgs,
|
||||
NoPivotRoot: config.c.noPivotRoot,
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(f).Encode(ps); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exit, err := getExitPipe(filepath.Join(config.root, ExitFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
control, err := getControlPipe(filepath.Join(config.root, ControlFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.exitPipe = exit
|
||||
p.controlPipe = control
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *process) Start() error {
|
||||
cmd := exec.Command(p.container.shim,
|
||||
p.container.id, p.container.bundle, p.container.runtime,
|
||||
)
|
||||
cmd.Dir = p.root
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
|
||||
return p.startCmd(cmd)
|
||||
}
|
||||
|
||||
func loadProcess(root, id string, c *container, s *ProcessState) (*process, error) {
|
||||
p := &process{
|
||||
root: root,
|
||||
id: id,
|
||||
container: c,
|
||||
spec: s.ProcessSpec,
|
||||
stdio: Stdio{
|
||||
Stdin: s.Stdin,
|
||||
Stdout: s.Stdout,
|
||||
Stderr: s.Stderr,
|
||||
},
|
||||
}
|
||||
if _, err := p.getPidFromFile(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := p.ExitStatus(); err != nil {
|
||||
if err == ErrProcessNotExited {
|
||||
exit, err := getExitPipe(filepath.Join(root, ExitFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.exitPipe = exit
|
||||
return p, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
type process struct {
|
||||
root string
|
||||
id string
|
||||
pid int
|
||||
exitPipe *os.File
|
||||
controlPipe *os.File
|
||||
container *container
|
||||
spec specs.ProcessSpec
|
||||
stdio Stdio
|
||||
}
|
||||
|
||||
func (p *process) ID() string {
|
||||
return p.id
|
||||
}
|
||||
|
||||
func (p *process) Container() Container {
|
||||
return p.container
|
||||
}
|
||||
|
||||
func (p *process) SystemPid() int {
|
||||
return p.pid
|
||||
}
|
||||
|
||||
// ExitFD returns the fd of the exit pipe
|
||||
func (p *process) ExitFD() int {
|
||||
return int(p.exitPipe.Fd())
|
||||
}
|
||||
|
||||
func (p *process) CloseStdin() error {
|
||||
_, err := fmt.Fprintf(p.controlPipe, "%d %d %d\n", 0, 0, 0)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *process) Resize(w, h int) error {
|
||||
_, err := fmt.Fprintf(p.controlPipe, "%d %d %d\n", 1, w, h)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *process) ExitStatus() (int, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, ExitStatusFile))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return -1, ErrProcessNotExited
|
||||
}
|
||||
return -1, err
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return -1, ErrProcessNotExited
|
||||
}
|
||||
return strconv.Atoi(string(data))
|
||||
}
|
||||
|
||||
func (p *process) Spec() specs.ProcessSpec {
|
||||
return p.spec
|
||||
}
|
||||
|
||||
func (p *process) Stdio() Stdio {
|
||||
return p.stdio
|
||||
}
|
||||
|
||||
// Close closes any open files and/or resouces on the process
|
||||
func (p *process) Close() error {
|
||||
return p.exitPipe.Close()
|
||||
}
|
||||
|
||||
func (p *process) State() State {
|
||||
if p.pid == 0 {
|
||||
return Stopped
|
||||
}
|
||||
err := syscall.Kill(p.pid, 0)
|
||||
if err != nil && err == syscall.ESRCH {
|
||||
return Stopped
|
||||
}
|
||||
return Running
|
||||
}
|
||||
|
||||
func (p *process) getPidFromFile() (int, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, "pid"))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
i, err := strconv.Atoi(string(data))
|
||||
if err != nil {
|
||||
return -1, errInvalidPidInt
|
||||
}
|
||||
p.pid = i
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func getExitPipe(path string) (*os.File, error) {
|
||||
if err := unix.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
// add NONBLOCK in case the other side has already closed or else
|
||||
// this function would never return
|
||||
return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
|
||||
}
|
||||
|
||||
func getControlPipe(path string) (*os.File, error) {
|
||||
if err := unix.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
return os.OpenFile(path, syscall.O_RDWR|syscall.O_NONBLOCK, 0)
|
||||
}
|
||||
|
||||
// Signal sends the provided signal to the process
|
||||
func (p *process) Signal(s os.Signal) error {
|
||||
return syscall.Kill(p.pid, s.(syscall.Signal))
|
||||
}
|
||||
|
||||
func (p *process) startCmd(cmd *exec.Cmd) error {
|
||||
if err := cmd.Start(); err != nil {
|
||||
if exErr, ok := err.(*exec.Error); ok {
|
||||
if exErr.Err == exec.ErrNotFound || exErr.Err == os.ErrNotExist {
|
||||
return fmt.Errorf("%s not installed on system", p.container.shim)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
if err := p.waitForStart(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *process) waitForStart(cmd *exec.Cmd) error {
|
||||
wc := make(chan error, 1)
|
||||
go func() {
|
||||
for {
|
||||
if _, err := p.getPidFromFile(); err != nil {
|
||||
if os.IsNotExist(err) || err == errInvalidPidInt {
|
||||
alive, err := isAlive(cmd)
|
||||
if err != nil {
|
||||
wc <- err
|
||||
return
|
||||
}
|
||||
if !alive {
|
||||
// runc could have failed to run the container so lets get the error
|
||||
// out of the logs or the shim could have encountered an error
|
||||
messages, err := readLogMessages(filepath.Join(p.root, "shim-log.json"))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
wc <- err
|
||||
return
|
||||
}
|
||||
for _, m := range messages {
|
||||
if m.Level == "error" {
|
||||
wc <- fmt.Errorf("shim error: %v", m.Msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
// no errors reported back from shim, check for runc/runtime errors
|
||||
messages, err = readLogMessages(filepath.Join(p.root, "log.json"))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
err = ErrContainerNotStarted
|
||||
}
|
||||
wc <- err
|
||||
return
|
||||
}
|
||||
for _, m := range messages {
|
||||
if m.Level == "error" {
|
||||
wc <- fmt.Errorf("oci runtime error: %v", m.Msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
wc <- ErrContainerNotStarted
|
||||
return
|
||||
}
|
||||
time.Sleep(15 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
wc <- err
|
||||
return
|
||||
}
|
||||
// the pid file was read successfully
|
||||
wc <- nil
|
||||
return
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case err := <-wc:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case <-time.After(p.container.timeout):
|
||||
cmd.Process.Kill()
|
||||
cmd.Wait()
|
||||
return ErrContainerStartTimeout
|
||||
}
|
||||
}
|
99
vendor/github.com/docker/containerd/runtime/runtime.go
generated
vendored
99
vendor/github.com/docker/containerd/runtime/runtime.go
generated
vendored
@@ -1,99 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotChildProcess = errors.New("containerd: not a child process for container")
|
||||
ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime")
|
||||
ErrCheckpointNotExists = errors.New("containerd: checkpoint does not exist for container")
|
||||
ErrCheckpointExists = errors.New("containerd: checkpoint already exists")
|
||||
ErrContainerExited = errors.New("containerd: container has exited")
|
||||
ErrTerminalsNotSupported = errors.New("containerd: terminals are not supported for runtime")
|
||||
ErrProcessNotExited = errors.New("containerd: process has not exited")
|
||||
ErrProcessExited = errors.New("containerd: process has exited")
|
||||
ErrContainerNotStarted = errors.New("containerd: container not started")
|
||||
ErrContainerStartTimeout = errors.New("containerd: container did not start before the specified timeout")
|
||||
|
||||
errNoPidFile = errors.New("containerd: no process pid file found")
|
||||
errInvalidPidInt = errors.New("containerd: process pid is invalid")
|
||||
errNotImplemented = errors.New("containerd: not implemented")
|
||||
)
|
||||
|
||||
const (
|
||||
ExitFile = "exit"
|
||||
ExitStatusFile = "exitStatus"
|
||||
StateFile = "state.json"
|
||||
ControlFile = "control"
|
||||
InitProcessID = "init"
|
||||
)
|
||||
|
||||
type Checkpoint struct {
|
||||
// Timestamp is the time that checkpoint happened
|
||||
Created time.Time `json:"created"`
|
||||
// Name is the name of the checkpoint
|
||||
Name string `json:"name"`
|
||||
// Tcp checkpoints open tcp connections
|
||||
Tcp bool `json:"tcp"`
|
||||
// UnixSockets persists unix sockets in the checkpoint
|
||||
UnixSockets bool `json:"unixSockets"`
|
||||
// Shell persists tty sessions in the checkpoint
|
||||
Shell bool `json:"shell"`
|
||||
// Exit exits the container after the checkpoint is finished
|
||||
Exit bool `json:"exit"`
|
||||
}
|
||||
|
||||
// PlatformProcessState container platform-specific fields in the ProcessState structure
|
||||
type PlatformProcessState struct {
|
||||
Checkpoint string `json:"checkpoint"`
|
||||
RootUID int `json:"rootUID"`
|
||||
RootGID int `json:"rootGID"`
|
||||
}
|
||||
type State string
|
||||
|
||||
type Resource struct {
|
||||
CPUShares int64
|
||||
BlkioWeight uint16
|
||||
CPUPeriod int64
|
||||
CPUQuota int64
|
||||
CpusetCpus string
|
||||
CpusetMems string
|
||||
KernelMemory int64
|
||||
Memory int64
|
||||
MemoryReservation int64
|
||||
MemorySwap int64
|
||||
}
|
||||
|
||||
const (
|
||||
Paused = State("paused")
|
||||
Stopped = State("stopped")
|
||||
Running = State("running")
|
||||
)
|
||||
|
||||
type state struct {
|
||||
Bundle string `json:"bundle"`
|
||||
Labels []string `json:"labels"`
|
||||
Stdin string `json:"stdin"`
|
||||
Stdout string `json:"stdout"`
|
||||
Stderr string `json:"stderr"`
|
||||
Runtime string `json:"runtime"`
|
||||
RuntimeArgs []string `json:"runtimeArgs"`
|
||||
Shim string `json:"shim"`
|
||||
NoPivotRoot bool `json:"noPivotRoot"`
|
||||
}
|
||||
|
||||
type ProcessState struct {
|
||||
specs.ProcessSpec
|
||||
Exec bool `json:"exec"`
|
||||
Stdin string `json:"containerdStdin"`
|
||||
Stdout string `json:"containerdStdout"`
|
||||
Stderr string `json:"containerdStderr"`
|
||||
RuntimeArgs []string `json:"runtimeArgs"`
|
||||
NoPivotRoot bool `json:"noPivotRoot"`
|
||||
|
||||
PlatformProcessState
|
||||
}
|
77
vendor/github.com/docker/containerd/runtime/stats.go
generated
vendored
77
vendor/github.com/docker/containerd/runtime/stats.go
generated
vendored
@@ -1,77 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import "time"
|
||||
|
||||
type Stat struct {
|
||||
// Timestamp is the time that the statistics where collected
|
||||
Timestamp time.Time
|
||||
Cpu Cpu `json:"cpu"`
|
||||
Memory Memory `json:"memory"`
|
||||
Pids Pids `json:"pids"`
|
||||
Blkio Blkio `json:"blkio"`
|
||||
Hugetlb map[string]Hugetlb `json:"hugetlb"`
|
||||
}
|
||||
|
||||
type Hugetlb struct {
|
||||
Usage uint64 `json:"usage,omitempty"`
|
||||
Max uint64 `json:"max,omitempty"`
|
||||
Failcnt uint64 `json:"failcnt"`
|
||||
}
|
||||
|
||||
type BlkioEntry struct {
|
||||
Major uint64 `json:"major,omitempty"`
|
||||
Minor uint64 `json:"minor,omitempty"`
|
||||
Op string `json:"op,omitempty"`
|
||||
Value uint64 `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
type Blkio struct {
|
||||
IoServiceBytesRecursive []BlkioEntry `json:"ioServiceBytesRecursive,omitempty"`
|
||||
IoServicedRecursive []BlkioEntry `json:"ioServicedRecursive,omitempty"`
|
||||
IoQueuedRecursive []BlkioEntry `json:"ioQueueRecursive,omitempty"`
|
||||
IoServiceTimeRecursive []BlkioEntry `json:"ioServiceTimeRecursive,omitempty"`
|
||||
IoWaitTimeRecursive []BlkioEntry `json:"ioWaitTimeRecursive,omitempty"`
|
||||
IoMergedRecursive []BlkioEntry `json:"ioMergedRecursive,omitempty"`
|
||||
IoTimeRecursive []BlkioEntry `json:"ioTimeRecursive,omitempty"`
|
||||
SectorsRecursive []BlkioEntry `json:"sectorsRecursive,omitempty"`
|
||||
}
|
||||
|
||||
type Pids struct {
|
||||
Current uint64 `json:"current,omitempty"`
|
||||
Limit uint64 `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
type Throttling struct {
|
||||
Periods uint64 `json:"periods,omitempty"`
|
||||
ThrottledPeriods uint64 `json:"throttledPeriods,omitempty"`
|
||||
ThrottledTime uint64 `json:"throttledTime,omitempty"`
|
||||
}
|
||||
|
||||
type CpuUsage struct {
|
||||
// Units: nanoseconds.
|
||||
Total uint64 `json:"total,omitempty"`
|
||||
Percpu []uint64 `json:"percpu,omitempty"`
|
||||
Kernel uint64 `json:"kernel"`
|
||||
User uint64 `json:"user"`
|
||||
}
|
||||
|
||||
type Cpu struct {
|
||||
Usage CpuUsage `json:"usage,omitempty"`
|
||||
Throttling Throttling `json:"throttling,omitempty"`
|
||||
}
|
||||
|
||||
type MemoryEntry struct {
|
||||
Limit uint64 `json:"limit"`
|
||||
Usage uint64 `json:"usage,omitempty"`
|
||||
Max uint64 `json:"max,omitempty"`
|
||||
Failcnt uint64 `json:"failcnt"`
|
||||
}
|
||||
|
||||
type Memory struct {
|
||||
Cache uint64 `json:"cache,omitempty"`
|
||||
Usage MemoryEntry `json:"usage,omitempty"`
|
||||
Swap MemoryEntry `json:"swap,omitempty"`
|
||||
Kernel MemoryEntry `json:"kernel,omitempty"`
|
||||
KernelTCP MemoryEntry `json:"kernelTCP,omitempty"`
|
||||
Raw map[string]uint64 `json:"raw,omitempty"`
|
||||
}
|
Reference in New Issue
Block a user