Comment more packages to pass go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
33e974ce99
commit
451421b615
@ -300,7 +300,7 @@ func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor,
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
manifestStack = append(manifestStack, desc)
|
manifestStack = append(manifestStack, desc)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
return nil, images.StopHandler
|
return nil, images.ErrStopHandler
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ type store struct {
|
|||||||
root string
|
root string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a local content store
|
// NewStore returns a local content store
|
||||||
func NewStore(root string) (content.Store, error) {
|
func NewStore(root string) (content.Store, error) {
|
||||||
if err := os.MkdirAll(filepath.Join(root, "ingest"), 0777); err != nil && !os.IsExist(err) {
|
if err := os.MkdirAll(filepath.Join(root, "ingest"), 0777); err != nil && !os.IsExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -383,8 +383,8 @@ func (s *store) Abort(ctx context.Context, ref string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *store) blobPath(dgst digest.Digest) string {
|
func (s *store) blobPath(dgst digest.Digest) string {
|
||||||
return filepath.Join(cs.root, "blobs", dgst.Algorithm().String(), dgst.Hex())
|
return filepath.Join(s.root, "blobs", dgst.Algorithm().String(), dgst.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) ingestRoot(ref string) string {
|
func (s *store) ingestRoot(ref string) string {
|
||||||
|
@ -137,7 +137,7 @@ We get back a list of mounts from `Snapshotter.Prepare`, with the `key`
|
|||||||
identifying the active snapshot. Mount this to the temporary location with the
|
identifying the active snapshot. Mount this to the temporary location with the
|
||||||
following:
|
following:
|
||||||
|
|
||||||
if err := MountAll(mounts, tmpDir); err != nil { ... }
|
if err := mount.All(mounts, tmpDir); err != nil { ... }
|
||||||
|
|
||||||
Once the mounts are performed, our temporary location is ready to capture
|
Once the mounts are performed, our temporary location is ready to capture
|
||||||
a diff. In practice, this works similar to a filesystem transaction. The
|
a diff. In practice, this works similar to a filesystem transaction. The
|
||||||
|
@ -25,7 +25,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.DiffPlugin,
|
Type: plugin.DiffPlugin,
|
||||||
ID: "walking",
|
ID: "walking",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.ContentPlugin,
|
plugin.ContentPlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
@ -81,7 +81,7 @@ func (s *walkingDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
if err := mount.MountAll(mounts, dir); err != nil {
|
if err := mount.All(mounts, dir); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to mount")
|
return emptyDesc, errors.Wrap(err, "failed to mount")
|
||||||
}
|
}
|
||||||
defer mount.Unmount(dir, 0)
|
defer mount.Unmount(dir, 0)
|
||||||
@ -149,12 +149,12 @@ func (s *walkingDiff) DiffMounts(ctx context.Context, lower, upper []mount.Mount
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(bDir)
|
defer os.RemoveAll(bDir)
|
||||||
|
|
||||||
if err := mount.MountAll(lower, aDir); err != nil {
|
if err := mount.All(lower, aDir); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to mount")
|
return emptyDesc, errors.Wrap(err, "failed to mount")
|
||||||
}
|
}
|
||||||
defer mount.Unmount(aDir, 0)
|
defer mount.Unmount(aDir, 0)
|
||||||
|
|
||||||
if err := mount.MountAll(upper, bDir); err != nil {
|
if err := mount.All(upper, bDir); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to mount")
|
return emptyDesc, errors.Wrap(err, "failed to mount")
|
||||||
}
|
}
|
||||||
defer mount.Unmount(bDir, 0)
|
defer mount.Unmount(bDir, 0)
|
||||||
|
@ -14,37 +14,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// SkipDesc is used to skip processing of a descriptor and
|
// ErrSkipDesc is used to skip processing of a descriptor and
|
||||||
// its descendants.
|
// its descendants.
|
||||||
SkipDesc = fmt.Errorf("skip descriptor")
|
ErrSkipDesc = fmt.Errorf("skip descriptor")
|
||||||
|
|
||||||
// StopHandler is used to signify that the descriptor
|
// ErrStopHandler is used to signify that the descriptor
|
||||||
// has been handled and should not be handled further.
|
// has been handled and should not be handled further.
|
||||||
// This applies only to a single descriptor in a handler
|
// This applies only to a single descriptor in a handler
|
||||||
// chain and does not apply to descendant descriptors.
|
// chain and does not apply to descendant descriptors.
|
||||||
StopHandler = fmt.Errorf("stop handler")
|
ErrStopHandler = fmt.Errorf("stop handler")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Handler handles image manifests
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)
|
Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandlerFunc function implementing the Handler interface
|
||||||
type HandlerFunc func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)
|
type HandlerFunc func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)
|
||||||
|
|
||||||
|
// Handle image manifests
|
||||||
func (fn HandlerFunc) Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
|
func (fn HandlerFunc) Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
|
||||||
return fn(ctx, desc)
|
return fn(ctx, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handlers returns a handler that will run the handlers in sequence.
|
// Handlers returns a handler that will run the handlers in sequence.
|
||||||
//
|
//
|
||||||
// A handler may return `StopHandler` to stop calling additional handlers
|
// A handler may return `ErrStopHandler` to stop calling additional handlers
|
||||||
func Handlers(handlers ...Handler) HandlerFunc {
|
func Handlers(handlers ...Handler) HandlerFunc {
|
||||||
return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
|
return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
|
||||||
var children []ocispec.Descriptor
|
var children []ocispec.Descriptor
|
||||||
for _, handler := range handlers {
|
for _, handler := range handlers {
|
||||||
ch, err := handler.Handle(ctx, desc)
|
ch, err := handler.Handle(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == StopHandler {
|
if errors.Cause(err) == ErrStopHandler {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -67,7 +70,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err
|
|||||||
|
|
||||||
children, err := handler.Handle(ctx, desc)
|
children, err := handler.Handle(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == SkipDesc {
|
if errors.Cause(err) == ErrSkipDesc {
|
||||||
continue // don't traverse the children.
|
continue // don't traverse the children.
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -87,7 +90,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err
|
|||||||
// If the handler decode subresources, they will be visited, as well.
|
// If the handler decode subresources, they will be visited, as well.
|
||||||
//
|
//
|
||||||
// Handlers for siblings are run in parallel on the provided descriptors. A
|
// Handlers for siblings are run in parallel on the provided descriptors. A
|
||||||
// handler may return `SkipDesc` to signal to the dispatcher to not traverse
|
// handler may return `ErrSkipDesc` to signal to the dispatcher to not traverse
|
||||||
// any children.
|
// any children.
|
||||||
//
|
//
|
||||||
// Typically, this function will be used with `FetchHandler`, often composed
|
// Typically, this function will be used with `FetchHandler`, often composed
|
||||||
@ -104,7 +107,7 @@ func Dispatch(ctx context.Context, handler Handler, descs ...ocispec.Descriptor)
|
|||||||
|
|
||||||
children, err := handler.Handle(ctx, desc)
|
children, err := handler.Handle(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == SkipDesc {
|
if errors.Cause(err) == ErrSkipDesc {
|
||||||
return nil // don't traverse the children.
|
return nil // don't traverse the children.
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -21,6 +21,7 @@ type Image struct {
|
|||||||
CreatedAt, UpdatedAt time.Time
|
CreatedAt, UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store and interact with images
|
||||||
type Store interface {
|
type Store interface {
|
||||||
Get(ctx context.Context, name string) (Image, error)
|
Get(ctx context.Context, name string) (Image, error)
|
||||||
List(ctx context.Context, filters ...string) ([]Image, error)
|
List(ctx context.Context, filters ...string) ([]Image, error)
|
||||||
@ -69,6 +70,7 @@ func (image *Image) Size(ctx context.Context, provider content.Provider, platfor
|
|||||||
}), ChildrenHandler(provider, platform)), image.Target)
|
}), ChildrenHandler(provider, platform)), image.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manifest returns the manifest for an image.
|
||||||
func Manifest(ctx context.Context, provider content.Provider, image ocispec.Descriptor, platform string) (ocispec.Manifest, error) {
|
func Manifest(ctx context.Context, provider content.Provider, image ocispec.Descriptor, platform string) (ocispec.Manifest, error) {
|
||||||
var (
|
var (
|
||||||
matcher platforms.Matcher
|
matcher platforms.Matcher
|
||||||
@ -177,7 +179,7 @@ func Platforms(ctx context.Context, provider content.Provider, image ocispec.Des
|
|||||||
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
if desc.Platform != nil {
|
if desc.Platform != nil {
|
||||||
platformSpecs = append(platformSpecs, *desc.Platform)
|
platformSpecs = append(platformSpecs, *desc.Platform)
|
||||||
return nil, SkipDesc
|
return nil, ErrSkipDesc
|
||||||
}
|
}
|
||||||
|
|
||||||
switch desc.MediaType {
|
switch desc.MediaType {
|
||||||
|
@ -9,15 +9,13 @@ const (
|
|||||||
maxSize = 4096
|
maxSize = 4096
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Validate a label's key and value are under 4096 bytes
|
||||||
func Validate(k, v string) error {
|
func Validate(k, v string) error {
|
||||||
// A label key and value should be under 4096 bytes
|
|
||||||
if (len(k) + len(v)) > maxSize {
|
if (len(k) + len(v)) > maxSize {
|
||||||
if len(k) > 10 {
|
if len(k) > 10 {
|
||||||
k = k[:10]
|
k = k[:10]
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "label key and value greater than maximum size (%d bytes), key: %s", maxSize, k)
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "label key and value greater than maximum size (%d bytes), key: %s", maxSize, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// loadBundle loads an existing bundle from disk
|
||||||
func loadBundle(id, path, workdir string) *bundle {
|
func loadBundle(id, path, workdir string) *bundle {
|
||||||
return &bundle{
|
return &bundle{
|
||||||
id: id,
|
id: id,
|
||||||
@ -71,6 +72,7 @@ type bundle struct {
|
|||||||
|
|
||||||
type shimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
|
type shimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
|
||||||
|
|
||||||
|
// ShimRemote is a shimOpt for connecting and starting a remote shim
|
||||||
func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func()) shimOpt {
|
func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func()) shimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts),
|
return b.shimConfig(ns, ropts),
|
||||||
@ -78,12 +80,14 @@ func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShimLocal is a shimOpt for using an in process shim implementation
|
||||||
func ShimLocal(exchange *events.Exchange) shimOpt {
|
func ShimLocal(exchange *events.Exchange) shimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
|
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShimConnect is a shimOpt for connecting to an existing remote shim
|
||||||
func ShimConnect() shimOpt {
|
func ShimConnect() shimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
||||||
|
@ -11,15 +11,20 @@ import (
|
|||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Process implements a linux process
|
||||||
type Process struct {
|
type Process struct {
|
||||||
id string
|
id string
|
||||||
t *Task
|
t *Task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ID of the process
|
||||||
func (p *Process) ID() string {
|
func (p *Process) ID() string {
|
||||||
return p.id
|
return p.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kill sends the provided signal to the underlying process
|
||||||
|
//
|
||||||
|
// Unable to kill all processes in the task using this method on a process
|
||||||
func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
|
func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
|
||||||
_, err := p.t.shim.Kill(ctx, &shim.KillRequest{
|
_, err := p.t.shim.Kill(ctx, &shim.KillRequest{
|
||||||
Signal: signal,
|
Signal: signal,
|
||||||
@ -31,6 +36,7 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// State of process
|
||||||
func (p *Process) State(ctx context.Context) (runtime.State, error) {
|
func (p *Process) State(ctx context.Context) (runtime.State, error) {
|
||||||
// use the container status for the status of the process
|
// use the container status for the status of the process
|
||||||
response, err := p.t.shim.State(ctx, &shim.StateRequest{
|
response, err := p.t.shim.State(ctx, &shim.StateRequest{
|
||||||
@ -63,6 +69,7 @@ func (p *Process) State(ctx context.Context) (runtime.State, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResizePty changes the side of the process's PTY to the provided width and height
|
||||||
func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||||
_, err := p.t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
|
_, err := p.t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
|
||||||
ID: p.id,
|
ID: p.id,
|
||||||
@ -75,6 +82,7 @@ func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseIO closes the provided IO pipe for the process
|
||||||
func (p *Process) CloseIO(ctx context.Context) error {
|
func (p *Process) CloseIO(ctx context.Context) error {
|
||||||
_, err := p.t.shim.CloseIO(ctx, &shim.CloseIORequest{
|
_, err := p.t.shim.CloseIO(ctx, &shim.CloseIORequest{
|
||||||
ID: p.id,
|
ID: p.id,
|
||||||
@ -86,6 +94,7 @@ func (p *Process) CloseIO(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the process
|
||||||
func (p *Process) Start(ctx context.Context) error {
|
func (p *Process) Start(ctx context.Context) error {
|
||||||
_, err := p.t.shim.Start(ctx, &shim.StartRequest{
|
_, err := p.t.shim.Start(ctx, &shim.StartRequest{
|
||||||
ID: p.id,
|
ID: p.id,
|
||||||
@ -96,6 +105,7 @@ func (p *Process) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait on the process to exit and return the exit status and timestamp
|
||||||
func (p *Process) Wait(ctx context.Context) (*runtime.Exit, error) {
|
func (p *Process) Wait(ctx context.Context) (*runtime.Exit, error) {
|
||||||
r, err := p.t.shim.Wait(ctx, &shim.WaitRequest{
|
r, err := p.t.shim.Wait(ctx, &shim.WaitRequest{
|
||||||
ID: p.id,
|
ID: p.id,
|
||||||
|
@ -52,7 +52,7 @@ func init() {
|
|||||||
Type: plugin.RuntimePlugin,
|
Type: plugin.RuntimePlugin,
|
||||||
ID: "linux",
|
ID: "linux",
|
||||||
Init: New,
|
Init: New,
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.TaskMonitorPlugin,
|
plugin.TaskMonitorPlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
@ -65,6 +65,7 @@ func init() {
|
|||||||
|
|
||||||
var _ = (runtime.Runtime)(&Runtime{})
|
var _ = (runtime.Runtime)(&Runtime{})
|
||||||
|
|
||||||
|
// Config options for the runtime
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Shim is a path or name of binary implementing the Shim GRPC API
|
// Shim is a path or name of binary implementing the Shim GRPC API
|
||||||
Shim string `toml:"shim"`
|
Shim string `toml:"shim"`
|
||||||
@ -78,6 +79,7 @@ type Config struct {
|
|||||||
ShimDebug bool `toml:"shim_debug"`
|
ShimDebug bool `toml:"shim_debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New returns a configured runtime
|
||||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -117,6 +119,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Runtime for a linux based system
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
root string
|
root string
|
||||||
state string
|
state string
|
||||||
@ -130,10 +133,12 @@ type Runtime struct {
|
|||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ID of the runtime
|
||||||
func (r *Runtime) ID() string {
|
func (r *Runtime) ID() string {
|
||||||
return pluginID
|
return pluginID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new task
|
||||||
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (_ runtime.Task, err error) {
|
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (_ runtime.Task, err error) {
|
||||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -265,6 +270,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a task removing all on disk state
|
||||||
func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, error) {
|
func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, error) {
|
||||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -305,6 +311,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tasks returns all tasks known to the runtime
|
||||||
func (r *Runtime) Tasks(ctx context.Context) ([]runtime.Task, error) {
|
func (r *Runtime) Tasks(ctx context.Context) ([]runtime.Task, error) {
|
||||||
return r.tasks.GetAll(ctx)
|
return r.tasks.GetAll(ctx)
|
||||||
}
|
}
|
||||||
@ -330,6 +337,7 @@ func (r *Runtime) restoreTasks(ctx context.Context) ([]*Task, error) {
|
|||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a specific task by task id
|
||||||
func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
|
func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
|
||||||
return r.tasks.Get(ctx, id)
|
return r.tasks.Get(ctx, id)
|
||||||
}
|
}
|
||||||
@ -491,6 +499,5 @@ func (r *Runtime) getRuncOptions(ctx context.Context, id string) (*runcopts.Runc
|
|||||||
|
|
||||||
return ropts, nil
|
return ropts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ClientOpt is an option for a shim client configuration
|
||||||
type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error)
|
type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error)
|
||||||
|
|
||||||
// WithStart executes a new shim process
|
// WithStart executes a new shim process
|
||||||
@ -180,6 +181,7 @@ func WithLocal(publisher events.Publisher) func(context.Context, Config) (shim.S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config contains shim specific configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Path string
|
Path string
|
||||||
Namespace string
|
Namespace string
|
||||||
@ -202,6 +204,7 @@ func New(ctx context.Context, config Config, opt ClientOpt) (*Client, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Client is a shim client containing the connection to a shim
|
||||||
type Client struct {
|
type Client struct {
|
||||||
shim.ShimClient
|
shim.ShimClient
|
||||||
|
|
||||||
@ -233,6 +236,7 @@ func (c *Client) KillShim(ctx context.Context) error {
|
|||||||
return c.signalShim(ctx, unix.SIGKILL)
|
return c.signalShim(ctx, unix.SIGKILL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close the cient connection
|
||||||
func (c *Client) Close() error {
|
func (c *Client) Close() error {
|
||||||
if c.c == nil {
|
if c.c == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InitPidFile name of the file that contains the init pid
|
||||||
const InitPidFile = "init.pid"
|
const InitPidFile = "init.pid"
|
||||||
|
|
||||||
type initProcess struct {
|
type initProcess struct {
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
var empty = &google_protobuf.Empty{}
|
var empty = &google_protobuf.Empty{}
|
||||||
|
|
||||||
|
// RuncRoot is the path to the root runc state directory
|
||||||
const RuncRoot = "/run/containerd/runc"
|
const RuncRoot = "/run/containerd/runc"
|
||||||
|
|
||||||
// NewService returns a new shim service that can be used via GRPC
|
// NewService returns a new shim service that can be used via GRPC
|
||||||
@ -65,6 +66,7 @@ type platform interface {
|
|||||||
close() error
|
close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Service is the shim implementation of a remote shim over GRPC
|
||||||
type Service struct {
|
type Service struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
||||||
@ -80,6 +82,7 @@ type Service struct {
|
|||||||
bundle string
|
bundle string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new initial process and container with the underlying OCI runtime
|
||||||
func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) {
|
func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -110,6 +113,7 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*sh
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start a process
|
||||||
func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.StartResponse, error) {
|
func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.StartResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -139,6 +143,7 @@ func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the initial process and container
|
||||||
func (s *Service) Delete(ctx context.Context, r *google_protobuf.Empty) (*shimapi.DeleteResponse, error) {
|
func (s *Service) Delete(ctx context.Context, r *google_protobuf.Empty) (*shimapi.DeleteResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -165,6 +170,7 @@ func (s *Service) Delete(ctx context.Context, r *google_protobuf.Empty) (*shimap
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteProcess deletes an exec'd process
|
||||||
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
|
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -186,6 +192,7 @@ func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessReq
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exec an additional process inside the container
|
||||||
func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -212,6 +219,7 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*goo
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResizePty of a process
|
||||||
func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -232,6 +240,7 @@ func (s *Service) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// State returns runtime state information for a process
|
||||||
func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) {
|
func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -271,6 +280,7 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pause the container
|
||||||
func (s *Service) Pause(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
|
func (s *Service) Pause(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -287,6 +297,7 @@ func (s *Service) Pause(ctx context.Context, r *google_protobuf.Empty) (*google_
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resume the container
|
||||||
func (s *Service) Resume(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
|
func (s *Service) Resume(ctx context.Context, r *google_protobuf.Empty) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -303,6 +314,7 @@ func (s *Service) Resume(ctx context.Context, r *google_protobuf.Empty) (*google
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kill a process with the provided signal
|
||||||
func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -327,6 +339,7 @@ func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_pro
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPids returns all pids inside the container
|
||||||
func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*shimapi.ListPidsResponse, error) {
|
func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*shimapi.ListPidsResponse, error) {
|
||||||
pids, err := s.getContainerPids(ctx, r.ID)
|
pids, err := s.getContainerPids(ctx, r.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -337,6 +350,7 @@ func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*sh
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseIO of a process
|
||||||
func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*google_protobuf.Empty, error) {
|
func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -352,6 +366,7 @@ func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*goog
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checkpoint the container
|
||||||
func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -368,12 +383,14 @@ func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskReque
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShimInfo returns shim information such as the shim's pid
|
||||||
func (s *Service) ShimInfo(ctx context.Context, r *google_protobuf.Empty) (*shimapi.ShimInfoResponse, error) {
|
func (s *Service) ShimInfo(ctx context.Context, r *google_protobuf.Empty) (*shimapi.ShimInfoResponse, error) {
|
||||||
return &shimapi.ShimInfoResponse{
|
return &shimapi.ShimInfoResponse{
|
||||||
ShimPid: uint32(os.Getpid()),
|
ShimPid: uint32(os.Getpid()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update a running container
|
||||||
func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*google_protobuf.Empty, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
@ -387,6 +404,7 @@ func (s *Service) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*go
|
|||||||
return empty, nil
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for a process to exit
|
||||||
func (s *Service) Wait(ctx context.Context, r *shimapi.WaitRequest) (*shimapi.WaitResponse, error) {
|
func (s *Service) Wait(ctx context.Context, r *shimapi.WaitRequest) (*shimapi.WaitResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
p := s.processes[r.ID]
|
p := s.processes[r.ID]
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Task on a linux based system
|
||||||
type Task struct {
|
type Task struct {
|
||||||
id string
|
id string
|
||||||
pid int
|
pid int
|
||||||
@ -45,10 +46,12 @@ func newTask(id, namespace string, pid int, shim *client.Client, monitor runtime
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ID of the task
|
||||||
func (t *Task) ID() string {
|
func (t *Task) ID() string {
|
||||||
return t.id
|
return t.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Info returns task information about the runtime and namespace
|
||||||
func (t *Task) Info() runtime.TaskInfo {
|
func (t *Task) Info() runtime.TaskInfo {
|
||||||
return runtime.TaskInfo{
|
return runtime.TaskInfo{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -57,6 +60,7 @@ func (t *Task) Info() runtime.TaskInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the task
|
||||||
func (t *Task) Start(ctx context.Context) error {
|
func (t *Task) Start(ctx context.Context) error {
|
||||||
hasCgroup := t.cg != nil
|
hasCgroup := t.cg != nil
|
||||||
r, err := t.shim.Start(ctx, &shim.StartRequest{
|
r, err := t.shim.Start(ctx, &shim.StartRequest{
|
||||||
@ -79,6 +83,7 @@ func (t *Task) Start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// State returns runtime information for the task
|
||||||
func (t *Task) State(ctx context.Context) (runtime.State, error) {
|
func (t *Task) State(ctx context.Context) (runtime.State, error) {
|
||||||
response, err := t.shim.State(ctx, &shim.StateRequest{
|
response, err := t.shim.State(ctx, &shim.StateRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -114,6 +119,7 @@ func (t *Task) State(ctx context.Context) (runtime.State, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pause the task and all processes
|
||||||
func (t *Task) Pause(ctx context.Context) error {
|
func (t *Task) Pause(ctx context.Context) error {
|
||||||
_, err := t.shim.Pause(ctx, empty)
|
_, err := t.shim.Pause(ctx, empty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -122,6 +128,7 @@ func (t *Task) Pause(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resume the task and all processes
|
||||||
func (t *Task) Resume(ctx context.Context) error {
|
func (t *Task) Resume(ctx context.Context) error {
|
||||||
if _, err := t.shim.Resume(ctx, empty); err != nil {
|
if _, err := t.shim.Resume(ctx, empty); err != nil {
|
||||||
return errdefs.FromGRPC(err)
|
return errdefs.FromGRPC(err)
|
||||||
@ -129,6 +136,9 @@ func (t *Task) Resume(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kill the task using the provided signal
|
||||||
|
//
|
||||||
|
// Optionally send the signal to all processes that are a child of the task
|
||||||
func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
|
func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
|
||||||
if _, err := t.shim.Kill(ctx, &shim.KillRequest{
|
if _, err := t.shim.Kill(ctx, &shim.KillRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -140,6 +150,7 @@ func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exec creates a new process inside the task
|
||||||
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
|
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
|
||||||
request := &shim.ExecProcessRequest{
|
request := &shim.ExecProcessRequest{
|
||||||
ID: id,
|
ID: id,
|
||||||
@ -158,6 +169,7 @@ func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runt
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pids returns all system level process ids running inside the task
|
||||||
func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
|
func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
|
||||||
resp, err := t.shim.ListPids(ctx, &shim.ListPidsRequest{
|
resp, err := t.shim.ListPids(ctx, &shim.ListPidsRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -168,6 +180,7 @@ func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
|
|||||||
return resp.Pids, nil
|
return resp.Pids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResizePty changes the side of the task's PTY to the provided width and height
|
||||||
func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||||
_, err := t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
|
_, err := t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -180,6 +193,7 @@ func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseIO closes the provided IO on the task
|
||||||
func (t *Task) CloseIO(ctx context.Context) error {
|
func (t *Task) CloseIO(ctx context.Context) error {
|
||||||
_, err := t.shim.CloseIO(ctx, &shim.CloseIORequest{
|
_, err := t.shim.CloseIO(ctx, &shim.CloseIORequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
@ -191,6 +205,7 @@ func (t *Task) CloseIO(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checkpoint creates a system level dump of the task and process information that can be later restored
|
||||||
func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any) error {
|
func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any) error {
|
||||||
r := &shim.CheckpointTaskRequest{
|
r := &shim.CheckpointTaskRequest{
|
||||||
Path: path,
|
Path: path,
|
||||||
@ -202,6 +217,7 @@ func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteProcess removes the provided process from the task and deletes all on disk state
|
||||||
func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, error) {
|
func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, error) {
|
||||||
r, err := t.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
|
r, err := t.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
|
||||||
ID: id,
|
ID: id,
|
||||||
@ -216,6 +232,7 @@ func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, err
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update changes runtime information of a running task
|
||||||
func (t *Task) Update(ctx context.Context, resources *types.Any) error {
|
func (t *Task) Update(ctx context.Context, resources *types.Any) error {
|
||||||
if _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{
|
if _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{
|
||||||
Resources: resources,
|
Resources: resources,
|
||||||
@ -225,6 +242,7 @@ func (t *Task) Update(ctx context.Context, resources *types.Any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process returns a specific process inside the task by the process id
|
||||||
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
|
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
|
||||||
// TODO: verify process exists for container
|
// TODO: verify process exists for container
|
||||||
return &Process{
|
return &Process{
|
||||||
@ -233,6 +251,7 @@ func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metrics returns runtime specific system level metric information for the task
|
||||||
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
||||||
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
|
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -241,10 +260,12 @@ func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
|||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cgroup returns the underlying cgroup for a linux task
|
||||||
func (t *Task) Cgroup() cgroups.Cgroup {
|
func (t *Task) Cgroup() cgroups.Cgroup {
|
||||||
return t.cg
|
return t.cg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the task to exit returning the status and timestamp
|
||||||
func (t *Task) Wait(ctx context.Context) (*runtime.Exit, error) {
|
func (t *Task) Wait(ctx context.Context) (*runtime.Exit, error) {
|
||||||
r, err := t.shim.Wait(ctx, &shim.WaitRequest{
|
r, err := t.shim.Wait(ctx, &shim.WaitRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
|
@ -22,6 +22,7 @@ type containerStore struct {
|
|||||||
tx *bolt.Tx
|
tx *bolt.Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewContainerStore returns a Store backed by an underlying bolt DB
|
||||||
func NewContainerStore(tx *bolt.Tx) containers.Store {
|
func NewContainerStore(tx *bolt.Tx) containers.Store {
|
||||||
return &containerStore{
|
return &containerStore{
|
||||||
tx: tx,
|
tx: tx,
|
||||||
|
@ -417,11 +417,7 @@ func (nw *namespacedWriter) commit(ctx context.Context, tx *bolt.Tx, size int64,
|
|||||||
if err := boltutil.WriteLabels(bkt, base.Labels); err != nil {
|
if err := boltutil.WriteLabels(bkt, base.Labels); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := bkt.Put(bucketKeySize, sizeEncoded); err != nil {
|
return bkt.Put(bucketKeySize, sizeEncoded)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nw *namespacedWriter) Status() (content.Status, error) {
|
func (nw *namespacedWriter) Status() (content.Status, error) {
|
||||||
@ -497,9 +493,5 @@ func writeInfo(info *content.Info, bkt *bolt.Bucket) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bkt.Put(bucketKeySize, sizeEncoded); err != nil {
|
return bkt.Put(bucketKeySize, sizeEncoded)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ type imageStore struct {
|
|||||||
tx *bolt.Tx
|
tx *bolt.Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewImageStore returns a store backed by a bolt DB
|
||||||
func NewImageStore(tx *bolt.Tx) images.Store {
|
func NewImageStore(tx *bolt.Tx) images.Store {
|
||||||
return &imageStore{tx: tx}
|
return &imageStore{tx: tx}
|
||||||
}
|
}
|
||||||
@ -281,7 +282,7 @@ func writeImage(bkt *bolt.Bucket, image *images.Image) error {
|
|||||||
func encodeSize(size int64) ([]byte, error) {
|
func encodeSize(size int64) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
buf [binary.MaxVarintLen64]byte
|
buf [binary.MaxVarintLen64]byte
|
||||||
sizeEncoded []byte = buf[:]
|
sizeEncoded = buf[:]
|
||||||
)
|
)
|
||||||
sizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]
|
sizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type namespaceStore struct {
|
|||||||
tx *bolt.Tx
|
tx *bolt.Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNamespaceStore returns a store backed by a bolt DB
|
||||||
func NewNamespaceStore(tx *bolt.Tx) namespaces.Store {
|
func NewNamespaceStore(tx *bolt.Tx) namespaces.Store {
|
||||||
return &namespaceStore{tx: tx}
|
return &namespaceStore{tx: tx}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config for the cgroups monitor
|
||||||
type Config struct {
|
type Config struct {
|
||||||
NoPrometheus bool `toml:"no_prometheus"`
|
NoPrometheus bool `toml:"no_prometheus"`
|
||||||
}
|
}
|
||||||
@ -28,14 +29,15 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New returns a new cgroups monitor
|
||||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||||
var ns *metrics.Namespace
|
var ns *metrics.Namespace
|
||||||
config := ic.Config.(*Config)
|
config := ic.Config.(*Config)
|
||||||
if !config.NoPrometheus {
|
if !config.NoPrometheus {
|
||||||
ns = metrics.NewNamespace("container", "", nil)
|
ns = metrics.NewNamespace("container", "", nil)
|
||||||
}
|
}
|
||||||
collector := NewCollector(ns)
|
collector := newCollector(ns)
|
||||||
oom, err := NewOOMCollector(ns)
|
oom, err := newOOMCollector(ns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -51,8 +53,8 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type cgroupsMonitor struct {
|
type cgroupsMonitor struct {
|
||||||
collector *Collector
|
collector *collector
|
||||||
oom *OOMCollector
|
oom *oomCollector
|
||||||
context context.Context
|
context context.Context
|
||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
}
|
}
|
||||||
|
@ -14,22 +14,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrAlreadyCollected is returned when a cgroups is already being monitored
|
||||||
ErrAlreadyCollected = errors.New("cgroup is already being collected")
|
ErrAlreadyCollected = errors.New("cgroup is already being collected")
|
||||||
ErrCgroupNotExists = errors.New("cgroup does not exist in the collector")
|
// ErrCgroupNotExists is returns when a cgroup no longer exists
|
||||||
|
ErrCgroupNotExists = errors.New("cgroup does not exist in the collector")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Trigger will be called when an event happens and provides the cgroup
|
// Trigger will be called when an event happens and provides the cgroup
|
||||||
// where the event originated from
|
// where the event originated from
|
||||||
type Trigger func(string, string, cgroups.Cgroup)
|
type Trigger func(string, string, cgroups.Cgroup)
|
||||||
|
|
||||||
// New registers the Collector with the provided namespace and returns it so
|
// newCollector registers the collector with the provided namespace and returns it so
|
||||||
// that cgroups can be added for collection
|
// that cgroups can be added for collection
|
||||||
func NewCollector(ns *metrics.Namespace) *Collector {
|
func newCollector(ns *metrics.Namespace) *collector {
|
||||||
if ns == nil {
|
if ns == nil {
|
||||||
return &Collector{}
|
return &collector{}
|
||||||
}
|
}
|
||||||
// add machine cpus and memory info
|
// add machine cpus and memory info
|
||||||
c := &Collector{
|
c := &collector{
|
||||||
ns: ns,
|
ns: ns,
|
||||||
cgroups: make(map[string]*task),
|
cgroups: make(map[string]*task),
|
||||||
}
|
}
|
||||||
@ -52,9 +54,9 @@ func taskID(id, namespace string) string {
|
|||||||
return fmt.Sprintf("%s-%s", id, namespace)
|
return fmt.Sprintf("%s-%s", id, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collector provides the ability to collect container stats and export
|
// collector provides the ability to collect container stats and export
|
||||||
// them in the prometheus format
|
// them in the prometheus format
|
||||||
type Collector struct {
|
type collector struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
|
||||||
cgroups map[string]*task
|
cgroups map[string]*task
|
||||||
@ -62,13 +64,13 @@ type Collector struct {
|
|||||||
metrics []*metric
|
metrics []*metric
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
for _, m := range c.metrics {
|
for _, m := range c.metrics {
|
||||||
ch <- m.desc(c.ns)
|
ch <- m.desc(c.ns)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
func (c *collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
for _, t := range c.cgroups {
|
for _, t := range c.cgroups {
|
||||||
@ -79,7 +81,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- prometheus.Metric, wg *sync.WaitGroup) {
|
func (c *collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- prometheus.Metric, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
stats, err := cg.Stat(cgroups.IgnoreNotExist)
|
stats, err := cg.Stat(cgroups.IgnoreNotExist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,7 +94,7 @@ func (c *Collector) collect(id, namespace string, cg cgroups.Cgroup, ch chan<- p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the provided cgroup and id so that metrics are collected and exported
|
// Add adds the provided cgroup and id so that metrics are collected and exported
|
||||||
func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
func (c *collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
||||||
if c.ns == nil {
|
if c.ns == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -110,7 +112,7 @@ func (c *Collector) Add(id, namespace string, cg cgroups.Cgroup) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes the provided cgroup by id from the collector
|
// Remove removes the provided cgroup by id from the collector
|
||||||
func (c *Collector) Remove(id, namespace string) {
|
func (c *collector) Remove(id, namespace string) {
|
||||||
if c.ns == nil {
|
if c.ns == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
func newOOMCollector(ns *metrics.Namespace) (*oomCollector, error) {
|
||||||
fd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
|
fd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -23,7 +23,7 @@ func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
|||||||
if ns != nil {
|
if ns != nil {
|
||||||
desc = ns.NewDesc("memory_oom", "The number of times a container has received an oom event", metrics.Total, "container_id", "namespace")
|
desc = ns.NewDesc("memory_oom", "The number of times a container has received an oom event", metrics.Total, "container_id", "namespace")
|
||||||
}
|
}
|
||||||
c := &OOMCollector{
|
c := &oomCollector{
|
||||||
fd: fd,
|
fd: fd,
|
||||||
desc: desc,
|
desc: desc,
|
||||||
set: make(map[uintptr]*oom),
|
set: make(map[uintptr]*oom),
|
||||||
@ -35,7 +35,7 @@ func NewOOMCollector(ns *metrics.Namespace) (*OOMCollector, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type OOMCollector struct {
|
type oomCollector struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
||||||
desc *prometheus.Desc
|
desc *prometheus.Desc
|
||||||
@ -51,7 +51,7 @@ type oom struct {
|
|||||||
count int64
|
count int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OOMCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...Trigger) error {
|
func (o *oomCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...Trigger) error {
|
||||||
o.mu.Lock()
|
o.mu.Lock()
|
||||||
defer o.mu.Unlock()
|
defer o.mu.Unlock()
|
||||||
fd, err := cg.OOMEventFD()
|
fd, err := cg.OOMEventFD()
|
||||||
@ -71,11 +71,11 @@ func (o *OOMCollector) Add(id, namespace string, cg cgroups.Cgroup, triggers ...
|
|||||||
return unix.EpollCtl(o.fd, unix.EPOLL_CTL_ADD, int(fd), &event)
|
return unix.EpollCtl(o.fd, unix.EPOLL_CTL_ADD, int(fd), &event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OOMCollector) Describe(ch chan<- *prometheus.Desc) {
|
func (o *oomCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- o.desc
|
ch <- o.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OOMCollector) Collect(ch chan<- prometheus.Metric) {
|
func (o *oomCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
o.mu.Lock()
|
o.mu.Lock()
|
||||||
defer o.mu.Unlock()
|
defer o.mu.Unlock()
|
||||||
for _, t := range o.set {
|
for _, t := range o.set {
|
||||||
@ -85,11 +85,11 @@ func (o *OOMCollector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the epoll fd
|
// Close closes the epoll fd
|
||||||
func (o *OOMCollector) Close() error {
|
func (o *oomCollector) Close() error {
|
||||||
return unix.Close(int(o.fd))
|
return unix.Close(int(o.fd))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OOMCollector) start() {
|
func (o *oomCollector) start() {
|
||||||
var events [128]unix.EpollEvent
|
var events [128]unix.EpollEvent
|
||||||
for {
|
for {
|
||||||
n, err := unix.EpollWait(o.fd, events[:], -1)
|
n, err := unix.EpollWait(o.fd, events[:], -1)
|
||||||
@ -105,7 +105,7 @@ func (o *OOMCollector) start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OOMCollector) process(fd uintptr, event uint32) {
|
func (o *oomCollector) process(fd uintptr, event uint32) {
|
||||||
// make sure to always flush the fd
|
// make sure to always flush the fd
|
||||||
flush(fd)
|
flush(fd)
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ type Mount struct {
|
|||||||
Options []string
|
Options []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MountAll mounts all the provided mounts to the provided target
|
// All mounts all the provided mounts to the provided target
|
||||||
func MountAll(mounts []Mount, target string) error {
|
func All(mounts []Mount, target string) error {
|
||||||
for _, m := range mounts {
|
for _, m := range mounts {
|
||||||
if err := m.Mount(target); err != nil {
|
if err := m.Mount(target); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mount to the provided target path
|
||||||
func (m *Mount) Mount(target string) error {
|
func (m *Mount) Mount(target string) error {
|
||||||
flags, data := parseMountOptions(m.Options)
|
flags, data := parseMountOptions(m.Options)
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ func (m *Mount) Mount(target string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unmount the provided mount path with the flags
|
||||||
func Unmount(mount string, flags int) error {
|
func Unmount(mount string, flags int) error {
|
||||||
return unix.Unmount(mount, flags)
|
return unix.Unmount(mount, flags)
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// NamespaceEnvVar is the environment variable key name
|
||||||
NamespaceEnvVar = "CONTAINERD_NAMESPACE"
|
NamespaceEnvVar = "CONTAINERD_NAMESPACE"
|
||||||
Default = "default"
|
// Default is the name of the default namespace
|
||||||
|
Default = "default"
|
||||||
)
|
)
|
||||||
|
|
||||||
type namespaceKey struct{}
|
type namespaceKey struct{}
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface{}, root, state, id string) *InitContext {
|
// NewContext returns a new plugin InitContext
|
||||||
|
func NewContext(ctx context.Context, plugins map[Type]map[string]interface{}, root, state, id string) *InitContext {
|
||||||
return &InitContext{
|
return &InitContext{
|
||||||
plugins: plugins,
|
plugins: plugins,
|
||||||
Root: filepath.Join(root, id),
|
Root: filepath.Join(root, id),
|
||||||
@ -18,6 +19,7 @@ func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitContext is used for plugin inititalization
|
||||||
type InitContext struct {
|
type InitContext struct {
|
||||||
Root string
|
Root string
|
||||||
State string
|
State string
|
||||||
@ -26,17 +28,19 @@ type InitContext struct {
|
|||||||
Config interface{}
|
Config interface{}
|
||||||
Events *events.Exchange
|
Events *events.Exchange
|
||||||
|
|
||||||
plugins map[PluginType]map[string]interface{}
|
plugins map[Type]map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InitContext) Get(t PluginType) (interface{}, error) {
|
// Get returns the first plugin by its type
|
||||||
|
func (i *InitContext) Get(t Type) (interface{}, error) {
|
||||||
for _, v := range i.plugins[t] {
|
for _, v := range i.plugins[t] {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InitContext) GetAll(t PluginType) (map[string]interface{}, error) {
|
// GetAll returns all plugins with the specific type
|
||||||
|
func (i *InitContext) GetAll(t Type) (map[string]interface{}, error) {
|
||||||
p, ok := i.plugins[t]
|
p, ok := i.plugins[t]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Differ allows the apply and creation of filesystem diffs between mounts
|
||||||
type Differ interface {
|
type Differ interface {
|
||||||
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
|
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
|
||||||
DiffMounts(ctx context.Context, lower, upper []mount.Mount, media, ref string) (ocispec.Descriptor, error)
|
DiffMounts(ctx context.Context, lower, upper []mount.Mount, media, ref string) (ocispec.Descriptor, error)
|
||||||
|
@ -9,49 +9,62 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoPluginType = errors.New("plugin: no type")
|
// ErrNoType is returned when no type is specified
|
||||||
ErrNoPluginID = errors.New("plugin: no id")
|
ErrNoType = errors.New("plugin: no type")
|
||||||
|
// ErrNoPluginID is returned when no id is specified
|
||||||
|
ErrNoPluginID = errors.New("plugin: no id")
|
||||||
|
|
||||||
// SkipPlugin is used when a plugin is not initialized and should not be loaded,
|
// ErrSkipPlugin is used when a plugin is not initialized and should not be loaded,
|
||||||
// this allows the plugin loader differentiate between a plugin which is configured
|
// this allows the plugin loader differentiate between a plugin which is configured
|
||||||
// not to load and one that fails to load.
|
// not to load and one that fails to load.
|
||||||
SkipPlugin = errors.New("skip plugin")
|
ErrSkipPlugin = errors.New("skip plugin")
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsSkipPlugin returns true if the error is skipping the plugin
|
// IsSkipPlugin returns true if the error is skipping the plugin
|
||||||
func IsSkipPlugin(err error) bool {
|
func IsSkipPlugin(err error) bool {
|
||||||
if errors.Cause(err) == SkipPlugin {
|
if errors.Cause(err) == ErrSkipPlugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginType string
|
// Type is the type of the plugin
|
||||||
|
type Type string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RuntimePlugin PluginType = "io.containerd.runtime.v1"
|
// RuntimePlugin implements a runtime
|
||||||
GRPCPlugin PluginType = "io.containerd.grpc.v1"
|
RuntimePlugin Type = "io.containerd.runtime.v1"
|
||||||
SnapshotPlugin PluginType = "io.containerd.snapshotter.v1"
|
// GRPCPlugin implements a grpc service
|
||||||
TaskMonitorPlugin PluginType = "io.containerd.monitor.v1"
|
GRPCPlugin Type = "io.containerd.grpc.v1"
|
||||||
DiffPlugin PluginType = "io.containerd.differ.v1"
|
// SnapshotPlugin implements a snapshotter
|
||||||
MetadataPlugin PluginType = "io.containerd.metadata.v1"
|
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
|
||||||
ContentPlugin PluginType = "io.containerd.content.v1"
|
// TaskMonitorPlugin implements a task monitor
|
||||||
|
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
|
||||||
|
// DiffPlugin implements a differ
|
||||||
|
DiffPlugin Type = "io.containerd.differ.v1"
|
||||||
|
// MetadataPlugin implements a metadata store
|
||||||
|
MetadataPlugin Type = "io.containerd.metadata.v1"
|
||||||
|
// ContentPlugin implements a content store
|
||||||
|
ContentPlugin Type = "io.containerd.content.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Registration contains information for registering a plugin
|
||||||
type Registration struct {
|
type Registration struct {
|
||||||
Type PluginType
|
Type Type
|
||||||
ID string
|
ID string
|
||||||
Config interface{}
|
Config interface{}
|
||||||
Requires []PluginType
|
Requires []Type
|
||||||
Init func(*InitContext) (interface{}, error)
|
Init func(*InitContext) (interface{}, error)
|
||||||
|
|
||||||
added bool
|
added bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URI returns the full plugin URI
|
||||||
func (r *Registration) URI() string {
|
func (r *Registration) URI() string {
|
||||||
return fmt.Sprintf("%s.%s", r.Type, r.ID)
|
return fmt.Sprintf("%s.%s", r.Type, r.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Service allows GRPC services to be registered with the underlying server
|
||||||
type Service interface {
|
type Service interface {
|
||||||
Register(*grpc.Server) error
|
Register(*grpc.Server) error
|
||||||
}
|
}
|
||||||
@ -75,11 +88,12 @@ func Load(path string) (err error) {
|
|||||||
return loadPlugins(path)
|
return loadPlugins(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register allows plugins to register
|
||||||
func Register(r *Registration) {
|
func Register(r *Registration) {
|
||||||
register.Lock()
|
register.Lock()
|
||||||
defer register.Unlock()
|
defer register.Unlock()
|
||||||
if r.Type == "" {
|
if r.Type == "" {
|
||||||
panic(ErrNoPluginType)
|
panic(ErrNoType)
|
||||||
}
|
}
|
||||||
if r.ID == "" {
|
if r.ID == "" {
|
||||||
panic(ErrNoPluginID)
|
panic(ErrNoPluginID)
|
||||||
@ -87,6 +101,7 @@ func Register(r *Registration) {
|
|||||||
register.r = append(register.r, r)
|
register.r = append(register.r, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Graph returns an ordered list of registered plugins for initialization
|
||||||
func Graph() (ordered []*Registration) {
|
func Graph() (ordered []*Registration) {
|
||||||
for _, r := range register.r {
|
for _, r := range register.r {
|
||||||
children(r.Requires, &ordered)
|
children(r.Requires, &ordered)
|
||||||
@ -98,7 +113,7 @@ func Graph() (ordered []*Registration) {
|
|||||||
return ordered
|
return ordered
|
||||||
}
|
}
|
||||||
|
|
||||||
func children(types []PluginType, ordered *[]*Registration) {
|
func children(types []Type, ordered *[]*Registration) {
|
||||||
for _, t := range types {
|
for _, t := range types {
|
||||||
for _, r := range register.r {
|
for _, r := range register.r {
|
||||||
if r.Type == t {
|
if r.Type == t {
|
||||||
|
@ -16,6 +16,7 @@ type Bar float64
|
|||||||
|
|
||||||
var _ fmt.Formatter = Bar(1.0)
|
var _ fmt.Formatter = Bar(1.0)
|
||||||
|
|
||||||
|
// Format the progress bar as output
|
||||||
func (h Bar) Format(state fmt.State, r rune) {
|
func (h Bar) Format(state fmt.State, r rune) {
|
||||||
switch r {
|
switch r {
|
||||||
case 'r':
|
case 'r':
|
||||||
|
@ -10,16 +10,20 @@ import (
|
|||||||
// Bytes converts a regular int64 to human readable type.
|
// Bytes converts a regular int64 to human readable type.
|
||||||
type Bytes int64
|
type Bytes int64
|
||||||
|
|
||||||
|
// String returns the string representation of bytes
|
||||||
func (b Bytes) String() string {
|
func (b Bytes) String() string {
|
||||||
return units.CustomSize("%02.1f %s", float64(b), 1024.0, []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"})
|
return units.CustomSize("%02.1f %s", float64(b), 1024.0, []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BytesPerSecond is the rate in seconds for byte operations
|
||||||
type BytesPerSecond int64
|
type BytesPerSecond int64
|
||||||
|
|
||||||
|
// NewBytesPerSecond returns the rate that n bytes were written in the provided duration
|
||||||
func NewBytesPerSecond(n int64, duration time.Duration) BytesPerSecond {
|
func NewBytesPerSecond(n int64, duration time.Duration) BytesPerSecond {
|
||||||
return BytesPerSecond(float64(n) / duration.Seconds())
|
return BytesPerSecond(float64(n) / duration.Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of the rate
|
||||||
func (bps BytesPerSecond) String() string {
|
func (bps BytesPerSecond) String() string {
|
||||||
return fmt.Sprintf("%v/s", Bytes(bps))
|
return fmt.Sprintf("%v/s", Bytes(bps))
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,14 @@ type Writer struct {
|
|||||||
lines int
|
lines int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWriter returns a writer
|
||||||
func NewWriter(w io.Writer) *Writer {
|
func NewWriter(w io.Writer) *Writer {
|
||||||
return &Writer{
|
return &Writer{
|
||||||
w: w,
|
w: w,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the provided bytes
|
||||||
func (w *Writer) Write(p []byte) (n int, err error) {
|
func (w *Writer) Write(p []byte) (n int, err error) {
|
||||||
return w.buf.Write(p)
|
return w.buf.Write(p)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FieldpathEnabled returns true if E_Fieldpath is enabled
|
||||||
func FieldpathEnabled(file *descriptor.FileDescriptorProto, message *descriptor.DescriptorProto) bool {
|
func FieldpathEnabled(file *descriptor.FileDescriptorProto, message *descriptor.DescriptorProto) bool {
|
||||||
return proto.GetBoolExtension(message.Options, E_Fieldpath, proto.GetBoolExtension(file.Options, E_FieldpathAll, false))
|
return proto.GetBoolExtension(message.Options, E_Fieldpath, proto.GetBoolExtension(file.Options, E_FieldpathAll, false))
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNoSuchProcess is returned when the process no longer exists
|
||||||
var ErrNoSuchProcess = errors.New("no such process")
|
var ErrNoSuchProcess = errors.New("no such process")
|
||||||
|
|
||||||
const bufferSize = 2048
|
const bufferSize = 2048
|
||||||
@ -36,10 +37,12 @@ func Reap() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default is the default monitor initialized for the package
|
||||||
var Default = &Monitor{
|
var Default = &Monitor{
|
||||||
subscribers: make(map[chan runc.Exit]struct{}),
|
subscribers: make(map[chan runc.Exit]struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Monitor monitors the underlying system for process status changes
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
@ -73,6 +76,7 @@ func (m *Monitor) Wait(c *exec.Cmd, ec chan runc.Exit) (int, error) {
|
|||||||
return -1, ErrNoSuchProcess
|
return -1, ErrNoSuchProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subscribe to process exit changes
|
||||||
func (m *Monitor) Subscribe() chan runc.Exit {
|
func (m *Monitor) Subscribe() chan runc.Exit {
|
||||||
c := make(chan runc.Exit, bufferSize)
|
c := make(chan runc.Exit, bufferSize)
|
||||||
m.Lock()
|
m.Lock()
|
||||||
@ -81,6 +85,7 @@ func (m *Monitor) Subscribe() chan runc.Exit {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unsubscribe to process exit changes
|
||||||
func (m *Monitor) Unsubscribe(c chan runc.Exit) {
|
func (m *Monitor) Unsubscribe(c chan runc.Exit) {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
delete(m.subscribers, c)
|
delete(m.subscribers, c)
|
||||||
|
@ -12,8 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalid = errors.New("invalid reference")
|
// ErrInvalid is returned when there is an invalid reference
|
||||||
ErrObjectRequired = errors.New("object required")
|
ErrInvalid = errors.New("invalid reference")
|
||||||
|
// ErrObjectRequired is returned when the object is required
|
||||||
|
ErrObjectRequired = errors.New("object required")
|
||||||
|
// ErrHostnameRequired is returned when the hostname is required
|
||||||
ErrHostnameRequired = errors.New("hostname required")
|
ErrHostnameRequired = errors.New("hostname required")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -138,7 +141,6 @@ func SplitObject(obj string) (tag string, dgst digest.Digest) {
|
|||||||
parts := strings.SplitAfterN(obj, "@", 2)
|
parts := strings.SplitAfterN(obj, "@", 2)
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
return parts[0], ""
|
return parts[0], ""
|
||||||
} else {
|
|
||||||
return parts[0], digest.Digest(parts[1])
|
|
||||||
}
|
}
|
||||||
|
return parts[0], digest.Digest(parts[1])
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ type Converter struct {
|
|||||||
layerBlobs map[digest.Digest]ocispec.Descriptor
|
layerBlobs map[digest.Digest]ocispec.Descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewConverter returns a new converter
|
||||||
func NewConverter(contentStore content.Store, fetcher remotes.Fetcher) *Converter {
|
func NewConverter(contentStore content.Store, fetcher remotes.Fetcher) *Converter {
|
||||||
return &Converter{
|
return &Converter{
|
||||||
contentStore: contentStore,
|
contentStore: contentStore,
|
||||||
@ -56,6 +57,7 @@ func NewConverter(contentStore content.Store, fetcher remotes.Fetcher) *Converte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle fetching descriptors for a docker media type
|
||||||
func (c *Converter) Handle(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
func (c *Converter) Handle(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
switch desc.MediaType {
|
switch desc.MediaType {
|
||||||
case images.MediaTypeDockerSchema1Manifest:
|
case images.MediaTypeDockerSchema1Manifest:
|
||||||
@ -101,6 +103,7 @@ func (c *Converter) Handle(ctx context.Context, desc ocispec.Descriptor) ([]ocis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert a docker manifest to an OCI descriptor
|
||||||
func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
|
func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
|
||||||
history, diffIDs, err := c.schema1ManifestHistory()
|
history, diffIDs, err := c.schema1ManifestHistory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Status of a content operation
|
||||||
type Status struct {
|
type Status struct {
|
||||||
content.Status
|
content.Status
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ type Status struct {
|
|||||||
UploadUUID string
|
UploadUUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatusTracker to track status of operations
|
||||||
type StatusTracker interface {
|
type StatusTracker interface {
|
||||||
GetStatus(string) (Status, error)
|
GetStatus(string) (Status, error)
|
||||||
SetStatus(string, Status)
|
SetStatus(string, Status)
|
||||||
@ -25,6 +27,7 @@ type memoryStatusTracker struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInMemoryTracker returns a StatusTracker that tracks content status in-memory
|
||||||
func NewInMemoryTracker() StatusTracker {
|
func NewInMemoryTracker() StatusTracker {
|
||||||
return &memoryStatusTracker{
|
return &memoryStatusTracker{
|
||||||
statuses: map[string]Status{},
|
statuses: map[string]Status{},
|
||||||
|
@ -32,11 +32,13 @@ type Resolver interface {
|
|||||||
Pusher(ctx context.Context, ref string) (Pusher, error)
|
Pusher(ctx context.Context, ref string) (Pusher, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetcher fetches content
|
||||||
type Fetcher interface {
|
type Fetcher interface {
|
||||||
// Fetch the resource identified by the descriptor.
|
// Fetch the resource identified by the descriptor.
|
||||||
Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error)
|
Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pusher pushes content
|
||||||
type Pusher interface {
|
type Pusher interface {
|
||||||
// Push returns a content writer for the given resource identified
|
// Push returns a content writer for the given resource identified
|
||||||
// by the descriptor.
|
// by the descriptor.
|
||||||
@ -47,6 +49,7 @@ type Pusher interface {
|
|||||||
// function.
|
// function.
|
||||||
type FetcherFunc func(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error)
|
type FetcherFunc func(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error)
|
||||||
|
|
||||||
|
// Fetch content
|
||||||
func (fn FetcherFunc) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) {
|
func (fn FetcherFunc) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) {
|
||||||
return fn(ctx, desc)
|
return fn(ctx, desc)
|
||||||
}
|
}
|
||||||
@ -55,6 +58,7 @@ func (fn FetcherFunc) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.Re
|
|||||||
// function.
|
// function.
|
||||||
type PusherFunc func(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error
|
type PusherFunc func(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error
|
||||||
|
|
||||||
func (fn PusherFunc) Pusher(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error {
|
// Push content
|
||||||
|
func (fn PusherFunc) Push(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error {
|
||||||
return fn(ctx, desc, r)
|
return fn(ctx, desc, r)
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,13 @@ var (
|
|||||||
|
|
||||||
type initializerFunc func(string) error
|
type initializerFunc func(string) error
|
||||||
|
|
||||||
|
// Mounter handles mount and unmount
|
||||||
type Mounter interface {
|
type Mounter interface {
|
||||||
Mount(target string, mounts ...mount.Mount) error
|
Mount(target string, mounts ...mount.Mount) error
|
||||||
Unmount(target string) error
|
Unmount(target string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitRootFS initializes the snapshot for use as a rootfs
|
||||||
func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]mount.Mount, error) {
|
func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]mount.Mount, error) {
|
||||||
_, err := snapshotter.Stat(ctx, name)
|
_, err := snapshotter.Stat(ctx, name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -1,15 +1,26 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TaskCreateEventTopic = "/tasks/create"
|
// TaskCreateEventTopic for task create
|
||||||
TaskStartEventTopic = "/tasks/start"
|
TaskCreateEventTopic = "/tasks/create"
|
||||||
TaskOOMEventTopic = "/tasks/oom"
|
// TaskStartEventTopic for task start
|
||||||
TaskExitEventTopic = "/tasks/exit"
|
TaskStartEventTopic = "/tasks/start"
|
||||||
TaskDeleteEventTopic = "/tasks/delete"
|
// TaskOOMEventTopic for task oom
|
||||||
TaskExecAddedEventTopic = "/tasks/exec-added"
|
TaskOOMEventTopic = "/tasks/oom"
|
||||||
TaskExecStartedEventTopic = "/tasks/exec-started"
|
// TaskExitEventTopic for task exit
|
||||||
TaskPausedEventTopic = "/tasks/paused"
|
TaskExitEventTopic = "/tasks/exit"
|
||||||
TaskResumedEventTopic = "/tasks/resumed"
|
// TaskDeleteEventTopic for task delete
|
||||||
|
TaskDeleteEventTopic = "/tasks/delete"
|
||||||
|
// TaskExecAddedEventTopic for task exec create
|
||||||
|
TaskExecAddedEventTopic = "/tasks/exec-added"
|
||||||
|
// TaskExecStartedEventTopic for task exec start
|
||||||
|
TaskExecStartedEventTopic = "/tasks/exec-started"
|
||||||
|
// TaskPausedEventTopic for task pause
|
||||||
|
TaskPausedEventTopic = "/tasks/paused"
|
||||||
|
// TaskResumedEventTopic for task resume
|
||||||
|
TaskResumedEventTopic = "/tasks/resumed"
|
||||||
|
// TaskCheckpointedEventTopic for task checkpoint
|
||||||
TaskCheckpointedEventTopic = "/tasks/checkpointed"
|
TaskCheckpointedEventTopic = "/tasks/checkpointed"
|
||||||
TaskUnknownTopic = "/tasks/?"
|
// TaskUnknownTopic for unknown task events
|
||||||
|
TaskUnknownTopic = "/tasks/?"
|
||||||
)
|
)
|
||||||
|
@ -8,12 +8,14 @@ type TaskMonitor interface {
|
|||||||
Stop(Task) error
|
Stop(Task) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMultiTaskMonitor returns a new TaskMonitor broadcasting to the provided monitors
|
||||||
func NewMultiTaskMonitor(monitors ...TaskMonitor) TaskMonitor {
|
func NewMultiTaskMonitor(monitors ...TaskMonitor) TaskMonitor {
|
||||||
return &multiTaskMonitor{
|
return &multiTaskMonitor{
|
||||||
monitors: monitors,
|
monitors: monitors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNoopMonitor is a task monitor that does nothing
|
||||||
func NewNoopMonitor() TaskMonitor {
|
func NewNoopMonitor() TaskMonitor {
|
||||||
return &noopTaskMonitor{}
|
return &noopTaskMonitor{}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IO holds process IO information
|
||||||
type IO struct {
|
type IO struct {
|
||||||
Stdin string
|
Stdin string
|
||||||
Stdout string
|
Stdout string
|
||||||
@ -15,6 +16,7 @@ type IO struct {
|
|||||||
Terminal bool
|
Terminal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateOpts contains task creation data
|
||||||
type CreateOpts struct {
|
type CreateOpts struct {
|
||||||
// Spec is the OCI runtime spec
|
// Spec is the OCI runtime spec
|
||||||
Spec *types.Any
|
Spec *types.Any
|
||||||
@ -28,6 +30,7 @@ type CreateOpts struct {
|
|||||||
Options *types.Any
|
Options *types.Any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit information for a process
|
||||||
type Exit struct {
|
type Exit struct {
|
||||||
Pid uint32
|
Pid uint32
|
||||||
Status uint32
|
Status uint32
|
||||||
|
@ -63,7 +63,7 @@ func New(ctx context.Context, config *Config) (*Server, error) {
|
|||||||
rpc: rpc,
|
rpc: rpc,
|
||||||
events: events.NewExchange(),
|
events: events.NewExchange(),
|
||||||
}
|
}
|
||||||
initialized = make(map[plugin.PluginType]map[string]interface{})
|
initialized = make(map[plugin.Type]map[string]interface{})
|
||||||
)
|
)
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
id := p.URI()
|
id := p.URI()
|
||||||
|
@ -20,7 +20,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "containers",
|
ID: "containers",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
|
@ -39,7 +39,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "content",
|
ID: "content",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.ContentPlugin,
|
plugin.ContentPlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "diff",
|
ID: "diff",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.DiffPlugin,
|
plugin.DiffPlugin,
|
||||||
},
|
},
|
||||||
Config: &config{
|
Config: &config{
|
||||||
|
@ -20,7 +20,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "images",
|
ID: "images",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
|
@ -21,7 +21,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "namespaces",
|
ID: "namespaces",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
|
@ -24,7 +24,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "snapshots",
|
ID: "snapshots",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.SnapshotPlugin,
|
plugin.SnapshotPlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,7 @@ func init() {
|
|||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "tasks",
|
ID: "tasks",
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.RuntimePlugin,
|
plugin.RuntimePlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
plugin.ContentPlugin,
|
plugin.ContentPlugin,
|
||||||
|
@ -108,7 +108,7 @@ func TestBtrfsMounts(t *testing.T) {
|
|||||||
if err := os.MkdirAll(target, 0755); err != nil {
|
if err := os.MkdirAll(target, 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := mount.MountAll(mounts, target); err != nil {
|
if err := mount.All(mounts, target); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, target)
|
defer testutil.Unmount(t, target)
|
||||||
@ -138,7 +138,7 @@ func TestBtrfsMounts(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mount.MountAll(mounts, target); err != nil {
|
if err := mount.All(mounts, target); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, target)
|
defer testutil.Unmount(t, target)
|
||||||
|
@ -221,7 +221,7 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := mount.MountAll(mounts, dest); err != nil {
|
if err := mount.All(mounts, dest); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func (u *Usage) Add(other Usage) {
|
|||||||
// the active snapshot. Mount this to the temporary location with the
|
// the active snapshot. Mount this to the temporary location with the
|
||||||
// following:
|
// following:
|
||||||
//
|
//
|
||||||
// if err := containerd.MountAll(mounts, tmpDir); err != nil { ... }
|
// if err := mount.All(mounts, tmpDir); err != nil { ... }
|
||||||
//
|
//
|
||||||
// Once the mounts are performed, our temporary location is ready to capture
|
// Once the mounts are performed, our temporary location is ready to capture
|
||||||
// a diff. In practice, this works similar to a filesystem transaction. The
|
// a diff. In practice, this works similar to a filesystem transaction. The
|
||||||
|
@ -20,7 +20,7 @@ func applyToMounts(m []mount.Mount, work string, a fstest.Applier) (err error) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(td)
|
defer os.RemoveAll(td)
|
||||||
|
|
||||||
if err := mount.MountAll(m, td); err != nil {
|
if err := mount.All(m, td); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount")
|
return errors.Wrap(err, "failed to mount")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -76,7 +76,7 @@ func checkSnapshot(ctx context.Context, sn snapshot.Snapshotter, work, name, che
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := mount.MountAll(m, td); err != nil {
|
if err := mount.All(m, td); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount")
|
return errors.Wrap(err, "failed to mount")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -119,7 +119,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
|||||||
t.Fatal("expected mounts to have entries")
|
t.Fatal("expected mounts to have entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mount.MountAll(mounts, preparing); err != nil {
|
if err := mount.All(mounts, preparing); err != nil {
|
||||||
t.Fatalf("failure reason: %+v", err)
|
t.Fatalf("failure reason: %+v", err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, preparing)
|
defer testutil.Unmount(t, preparing)
|
||||||
@ -150,7 +150,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failure reason: %+v", err)
|
t.Fatalf("failure reason: %+v", err)
|
||||||
}
|
}
|
||||||
if err := mount.MountAll(mounts, next); err != nil {
|
if err := mount.All(mounts, next); err != nil {
|
||||||
t.Fatalf("failure reason: %+v", err)
|
t.Fatalf("failure reason: %+v", err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, next)
|
defer testutil.Unmount(t, next)
|
||||||
@ -212,7 +212,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failure reason: %+v", err)
|
t.Fatalf("failure reason: %+v", err)
|
||||||
}
|
}
|
||||||
if err := mount.MountAll(mounts, nextnext); err != nil {
|
if err := mount.All(mounts, nextnext); err != nil {
|
||||||
t.Fatalf("failure reason: %+v", err)
|
t.Fatalf("failure reason: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter s
|
|||||||
t.Fatal("expected mounts to have entries")
|
t.Fatal("expected mounts to have entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mount.MountAll(mounts, preparing); err != nil {
|
if err = mount.All(mounts, preparing); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, preparing)
|
defer testutil.Unmount(t, preparing)
|
||||||
@ -279,7 +279,7 @@ func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotte
|
|||||||
t.Fatal("expected mounts to have entries")
|
t.Fatal("expected mounts to have entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mount.MountAll(mounts, preparing); err != nil {
|
if err = mount.All(mounts, preparing); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer testutil.Unmount(t, preparing)
|
defer testutil.Unmount(t, preparing)
|
||||||
@ -318,7 +318,7 @@ func snapshotterPrepareMount(ctx context.Context, snapshotter snapshot.Snapshott
|
|||||||
return "", fmt.Errorf("expected mounts to have entries")
|
return "", fmt.Errorf("expected mounts to have entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mount.MountAll(mounts, preparing); err != nil {
|
if err = mount.All(mounts, preparing); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return preparing, nil
|
return preparing, nil
|
||||||
@ -748,7 +748,7 @@ func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just checking the option string of m is not enough, we need to test real mount. (#1368)
|
// Just checking the option string of m is not enough, we need to test real mount. (#1368)
|
||||||
if err := mount.MountAll(m, viewMountPoint); err != nil {
|
if err := mount.All(m, viewMountPoint); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func init() {
|
|||||||
ID: runtimeName,
|
ID: runtimeName,
|
||||||
Type: plugin.RuntimePlugin,
|
Type: plugin.RuntimePlugin,
|
||||||
Init: New,
|
Init: New,
|
||||||
Requires: []plugin.PluginType{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user