Add comments and fix common lint issues
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
9bd1dc78cb
commit
5fd0415985
@ -449,6 +449,7 @@ func (c *Client) DiffService() diff.Differ {
|
|||||||
return diffservice.NewDiffServiceFromClient(diffapi.NewDiffClient(c.conn))
|
return diffservice.NewDiffServiceFromClient(diffapi.NewDiffClient(c.conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntrospectionService returns the underlying Introspection Client
|
||||||
func (c *Client) IntrospectionService() introspectionapi.IntrospectionClient {
|
func (c *Client) IntrospectionService() introspectionapi.IntrospectionClient {
|
||||||
return introspectionapi.NewIntrospectionClient(c.conn)
|
return introspectionapi.NewIntrospectionClient(c.conn)
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
serverC <- server
|
serverC <- server
|
||||||
if config.Debug.Address != "" {
|
if config.Debug.Address != "" {
|
||||||
l, err := sys.GetLocalListener(config.Debug.Address, config.Debug.Uid, config.Debug.Gid)
|
l, err := sys.GetLocalListener(config.Debug.Address, config.Debug.UID, config.Debug.GID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to get listener for debug endpoint")
|
return errors.Wrapf(err, "failed to get listener for debug endpoint")
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ func main() {
|
|||||||
serve(log.WithModule(ctx, "metrics"), l, server.ServeMetrics)
|
serve(log.WithModule(ctx, "metrics"), l, server.ServeMetrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := sys.GetLocalListener(address, config.GRPC.Uid, config.GRPC.Gid)
|
l, err := sys.GetLocalListener(address, config.GRPC.UID, config.GRPC.GID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to get listener for main endpoint")
|
return errors.Wrapf(err, "failed to get listener for main endpoint")
|
||||||
}
|
}
|
||||||
|
@ -70,32 +70,33 @@ type bundle struct {
|
|||||||
workDir string
|
workDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
type shimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
|
// ShimOpt specifies shim options for initialization and connection
|
||||||
|
type ShimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
|
||||||
|
|
||||||
// ShimRemote is a shimOpt for connecting and starting a remote shim
|
// ShimRemote is a ShimOpt for connecting and starting a remote shim
|
||||||
func ShimRemote(shim, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) shimOpt {
|
func ShimRemote(shim, daemonAddress, cgroup string, nonewns, 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),
|
||||||
client.WithStart(shim, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
|
client.WithStart(shim, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShimLocal is a shimOpt for using an in process shim implementation
|
// 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
|
// 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewShimClient connects to the shim managing the bundle and tasks creating it if needed
|
// NewShimClient connects to the shim managing the bundle and tasks creating it if needed
|
||||||
func (b *bundle) NewShimClient(ctx context.Context, namespace string, getClientOpts shimOpt, runcOpts *runcopts.RuncOptions) (*client.Client, error) {
|
func (b *bundle) NewShimClient(ctx context.Context, namespace string, getClientOpts ShimOpt, runcOpts *runcopts.RuncOptions) (*client.Client, error) {
|
||||||
cfg, opt := getClientOpts(b, namespace, runcOpts)
|
cfg, opt := getClientOpts(b, namespace, runcOpts)
|
||||||
return client.New(ctx, cfg, opt)
|
return client.New(ctx, cfg, opt)
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ func (cs *contentStore) garbageCollect(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cs.Store.Walk(ctx, func(info content.Info) error {
|
return cs.Store.Walk(ctx, func(info content.Info) error {
|
||||||
if _, ok := seen[info.Digest.String()]; !ok {
|
if _, ok := seen[info.Digest.String()]; !ok {
|
||||||
if err := cs.Store.Delete(ctx, info.Digest); err != nil {
|
if err := cs.Store.Delete(ctx, info.Digest); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -574,9 +574,5 @@ func (cs *contentStore) garbageCollect(ctx context.Context) error {
|
|||||||
log.G(ctx).WithField("digest", info.Digest).Debug("removed content")
|
log.G(ctx).WithField("digest", info.Digest).Debug("removed content")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -61,10 +61,13 @@ type Plugin struct {
|
|||||||
err error // will be set if there was an error initializing the plugin
|
err error // will be set if there was an error initializing the plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Err returns the errors during initialization.
|
||||||
|
// returns nil if not error was encountered
|
||||||
func (p *Plugin) Err() error {
|
func (p *Plugin) Err() error {
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instance returns the instance and any initialization error of the plugin
|
||||||
func (p *Plugin) Instance() (interface{}, error) {
|
func (p *Plugin) Instance() (interface{}, error) {
|
||||||
return p.instance, p.err
|
return p.instance, p.err
|
||||||
}
|
}
|
||||||
@ -80,12 +83,14 @@ type PluginSet struct {
|
|||||||
byTypeAndID map[Type]map[string]*Plugin
|
byTypeAndID map[Type]map[string]*Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPluginSet returns an initialized plugin set
|
||||||
func NewPluginSet() *PluginSet {
|
func NewPluginSet() *PluginSet {
|
||||||
return &PluginSet{
|
return &PluginSet{
|
||||||
byTypeAndID: make(map[Type]map[string]*Plugin),
|
byTypeAndID: make(map[Type]map[string]*Plugin),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a plugin to the set
|
||||||
func (ps *PluginSet) Add(p *Plugin) error {
|
func (ps *PluginSet) Add(p *Plugin) error {
|
||||||
if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok {
|
if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok {
|
||||||
ps.byTypeAndID[p.Registration.Type] = map[string]*Plugin{
|
ps.byTypeAndID[p.Registration.Type] = map[string]*Plugin{
|
||||||
@ -109,6 +114,7 @@ func (ps *PluginSet) Get(t Type) (interface{}, error) {
|
|||||||
return nil, errors.Wrapf(errdefs.ErrNotFound, "no plugins registered for %s", t)
|
return nil, errors.Wrapf(errdefs.ErrNotFound, "no plugins registered for %s", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAll plugins in the set
|
||||||
func (i *InitContext) GetAll() []*Plugin {
|
func (i *InitContext) GetAll() []*Plugin {
|
||||||
return i.plugins.ordered
|
return i.plugins.ordered
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TaskInfo provides task specific information
|
||||||
type TaskInfo struct {
|
type TaskInfo struct {
|
||||||
ID string
|
ID string
|
||||||
Runtime string
|
Runtime string
|
||||||
@ -14,6 +15,7 @@ type TaskInfo struct {
|
|||||||
Namespace string
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process is a runtime object for an executing process inside a container
|
||||||
type Process interface {
|
type Process interface {
|
||||||
ID() string
|
ID() string
|
||||||
// State returns the process state
|
// State returns the process state
|
||||||
@ -30,6 +32,7 @@ type Process interface {
|
|||||||
Wait(context.Context) (*Exit, error)
|
Wait(context.Context) (*Exit, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Task is the runtime object for an executing container
|
||||||
type Task interface {
|
type Task interface {
|
||||||
Process
|
Process
|
||||||
|
|
||||||
@ -55,27 +58,37 @@ type Task interface {
|
|||||||
Metrics(context.Context) (interface{}, error)
|
Metrics(context.Context) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecOpts provides additional options for additional processes running in a task
|
||||||
type ExecOpts struct {
|
type ExecOpts struct {
|
||||||
Spec *types.Any
|
Spec *types.Any
|
||||||
IO IO
|
IO IO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsoleSize of a pty or windows terminal
|
||||||
type ConsoleSize struct {
|
type ConsoleSize struct {
|
||||||
Width uint32
|
Width uint32
|
||||||
Height uint32
|
Height uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status is the runtime status of a task and/or process
|
||||||
type Status int
|
type Status int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// CreatedStatus when a process has been created
|
||||||
CreatedStatus Status = iota + 1
|
CreatedStatus Status = iota + 1
|
||||||
|
// RunningStatus when a process is running
|
||||||
RunningStatus
|
RunningStatus
|
||||||
|
// StoppedStatus when a process has stopped
|
||||||
StoppedStatus
|
StoppedStatus
|
||||||
|
// DeletedStatus when a process has been deleted
|
||||||
DeletedStatus
|
DeletedStatus
|
||||||
|
// PausedStatus when a process is paused
|
||||||
PausedStatus
|
PausedStatus
|
||||||
|
// PausingStatus when a process is currently pausing
|
||||||
PausingStatus
|
PausingStatus
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// State information for a process
|
||||||
type State struct {
|
type State struct {
|
||||||
// Status is the current status of the container
|
// Status is the current status of the container
|
||||||
Status Status
|
Status Status
|
||||||
@ -93,6 +106,7 @@ type State struct {
|
|||||||
Terminal bool
|
Terminal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessInfo holds platform specific process information
|
||||||
type ProcessInfo struct {
|
type ProcessInfo struct {
|
||||||
// Pid is the process ID
|
// Pid is the process ID
|
||||||
Pid uint32
|
Pid uint32
|
||||||
|
@ -9,21 +9,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrTaskNotExists = errors.New("task does not exist")
|
// ErrTaskNotExists is returned when a task does not exist
|
||||||
|
ErrTaskNotExists = errors.New("task does not exist")
|
||||||
|
// ErrTaskAlreadyExists is returned when a task already exists
|
||||||
ErrTaskAlreadyExists = errors.New("task already exists")
|
ErrTaskAlreadyExists = errors.New("task already exists")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewTaskList returns a new TaskList
|
||||||
func NewTaskList() *TaskList {
|
func NewTaskList() *TaskList {
|
||||||
return &TaskList{
|
return &TaskList{
|
||||||
tasks: make(map[string]map[string]Task),
|
tasks: make(map[string]map[string]Task),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TaskList holds and provides locking around tasks
|
||||||
type TaskList struct {
|
type TaskList struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
tasks map[string]map[string]Task
|
tasks map[string]map[string]Task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a task
|
||||||
func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
|
func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
@ -42,6 +47,7 @@ func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAll tasks under a namespace
|
||||||
func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
|
func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
|
||||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -58,6 +64,7 @@ func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
|
|||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a task
|
||||||
func (l *TaskList) Add(ctx context.Context, t Task) error {
|
func (l *TaskList) Add(ctx context.Context, t Task) error {
|
||||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,6 +73,7 @@ func (l *TaskList) Add(ctx context.Context, t Task) error {
|
|||||||
return l.AddWithNamespace(namespace, t)
|
return l.AddWithNamespace(namespace, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddWithNamespace adds a task with the provided namespace
|
||||||
func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
|
func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
@ -81,6 +89,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a task
|
||||||
func (l *TaskList) Delete(ctx context.Context, t Task) {
|
func (l *TaskList) Delete(ctx context.Context, t Task) {
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
|
@ -36,15 +36,15 @@ type Config struct {
|
|||||||
// GRPCConfig provides GRPC configuration for the socket
|
// GRPCConfig provides GRPC configuration for the socket
|
||||||
type GRPCConfig struct {
|
type GRPCConfig struct {
|
||||||
Address string `toml:"address"`
|
Address string `toml:"address"`
|
||||||
Uid int `toml:"uid"`
|
UID int `toml:"uid"`
|
||||||
Gid int `toml:"gid"`
|
GID int `toml:"gid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug provides debug configuration
|
// Debug provides debug configuration
|
||||||
type Debug struct {
|
type Debug struct {
|
||||||
Address string `toml:"address"`
|
Address string `toml:"address"`
|
||||||
Uid int `toml:"uid"`
|
UID int `toml:"uid"`
|
||||||
Gid int `toml:"gid"`
|
GID int `toml:"gid"`
|
||||||
Level string `toml:"level"`
|
Level string `toml:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,12 @@ func init() {
|
|||||||
Type: plugin.GRPCPlugin,
|
Type: plugin.GRPCPlugin,
|
||||||
ID: "healthcheck",
|
ID: "healthcheck",
|
||||||
InitFn: func(*plugin.InitContext) (interface{}, error) {
|
InitFn: func(*plugin.InitContext) (interface{}, error) {
|
||||||
return NewService()
|
return newService()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns the GRPC health server
|
func newService() (*service, error) {
|
||||||
func NewService() (*service, error) {
|
|
||||||
return &service{
|
return &service{
|
||||||
health.NewServer(),
|
health.NewServer(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -107,8 +107,8 @@ func (b *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, erro
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
func (b *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return snapshot.Info{}, err
|
return snapshot.Info{}, err
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,10 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshot.Snaps
|
|||||||
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
|
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
|
||||||
}
|
}
|
||||||
|
|
||||||
return snapshotter, func() (err error) {
|
return snapshotter, func() error {
|
||||||
merr := mount.UnmountAll(root, unix.MNT_DETACH)
|
err := mount.UnmountAll(root, unix.MNT_DETACH)
|
||||||
if err = cleanupDevice(); err != nil {
|
if cerr := cleanupDevice(); cerr != nil {
|
||||||
return errors.Wrap(err, "device cleanup failed")
|
err = errors.Wrap(cerr, "device cleanup failed")
|
||||||
} else {
|
|
||||||
err = merr
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -57,7 +57,7 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !supportsDType {
|
if !supportsDType {
|
||||||
return nil, fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support.", root)
|
return nil, fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support", root)
|
||||||
}
|
}
|
||||||
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
|
ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -582,7 +582,7 @@ func encodeSize(size int64) ([]byte, error) {
|
|||||||
func encodeID(id uint64) ([]byte, error) {
|
func encodeID(id uint64) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
buf [binary.MaxVarintLen64]byte
|
buf [binary.MaxVarintLen64]byte
|
||||||
idEncoded []byte = buf[:]
|
idEncoded = buf[:]
|
||||||
)
|
)
|
||||||
idEncoded = idEncoded[:binary.PutUvarint(idEncoded, id)]
|
idEncoded = idEncoded[:binary.PutUvarint(idEncoded, id)]
|
||||||
|
|
||||||
|
1
task.go
1
task.go
@ -51,6 +51,7 @@ type Status struct {
|
|||||||
ExitTime time.Time
|
ExitTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessInfo provides platform specific process information
|
||||||
type ProcessInfo struct {
|
type ProcessInfo struct {
|
||||||
// Pid is the process ID
|
// Pid is the process ID
|
||||||
Pid uint32
|
Pid uint32
|
||||||
|
@ -46,10 +46,7 @@ func NewLoopback(size int64) (string, func() error, error) {
|
|||||||
|
|
||||||
// remove file
|
// remove file
|
||||||
logrus.Debugf("Removing temporary file %s", file.Name())
|
logrus.Debugf("Removing temporary file %s", file.Name())
|
||||||
if err = os.Remove(file.Name()); err != nil {
|
return os.Remove(file.Name())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return deviceName, cleanup, nil
|
return deviceName, cleanup, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user