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))
|
||||
}
|
||||
|
||||
// IntrospectionService returns the underlying Introspection Client
|
||||
func (c *Client) IntrospectionService() introspectionapi.IntrospectionClient {
|
||||
return introspectionapi.NewIntrospectionClient(c.conn)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func main() {
|
||||
}
|
||||
serverC <- server
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
return errors.Wrapf(err, "failed to get listener for main endpoint")
|
||||
}
|
||||
|
@ -70,32 +70,33 @@ type bundle struct {
|
||||
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
|
||||
func ShimRemote(shim, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) shimOpt {
|
||||
// ShimRemote is a ShimOpt for connecting and starting a remote shim
|
||||
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 b.shimConfig(ns, ropts),
|
||||
client.WithStart(shim, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
|
||||
}
|
||||
}
|
||||
|
||||
// ShimLocal is a shimOpt for using an in process shim implementation
|
||||
func ShimLocal(exchange *events.Exchange) shimOpt {
|
||||
// ShimLocal is a ShimOpt for using an in process shim implementation
|
||||
func ShimLocal(exchange *events.Exchange) ShimOpt {
|
||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
||||
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
|
||||
}
|
||||
}
|
||||
|
||||
// ShimConnect is a shimOpt for connecting to an existing remote shim
|
||||
func ShimConnect() shimOpt {
|
||||
// ShimConnect is a ShimOpt for connecting to an existing remote shim
|
||||
func ShimConnect() ShimOpt {
|
||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
||||
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
return client.New(ctx, cfg, opt)
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ func (cs *contentStore) garbageCollect(ctx context.Context) error {
|
||||
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 err := cs.Store.Delete(ctx, info.Digest); err != nil {
|
||||
return err
|
||||
@ -574,9 +574,5 @@ func (cs *contentStore) garbageCollect(ctx context.Context) error {
|
||||
log.G(ctx).WithField("digest", info.Digest).Debug("removed content")
|
||||
}
|
||||
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 returns the errors during initialization.
|
||||
// returns nil if not error was encountered
|
||||
func (p *Plugin) Err() error {
|
||||
return p.err
|
||||
}
|
||||
|
||||
// Instance returns the instance and any initialization error of the plugin
|
||||
func (p *Plugin) Instance() (interface{}, error) {
|
||||
return p.instance, p.err
|
||||
}
|
||||
@ -80,12 +83,14 @@ type PluginSet struct {
|
||||
byTypeAndID map[Type]map[string]*Plugin
|
||||
}
|
||||
|
||||
// NewPluginSet returns an initialized plugin set
|
||||
func NewPluginSet() *PluginSet {
|
||||
return &PluginSet{
|
||||
byTypeAndID: make(map[Type]map[string]*Plugin),
|
||||
}
|
||||
}
|
||||
|
||||
// Add a plugin to the set
|
||||
func (ps *PluginSet) Add(p *Plugin) error {
|
||||
if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok {
|
||||
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)
|
||||
}
|
||||
|
||||
// GetAll plugins in the set
|
||||
func (i *InitContext) GetAll() []*Plugin {
|
||||
return i.plugins.ordered
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/gogo/protobuf/types"
|
||||
)
|
||||
|
||||
// TaskInfo provides task specific information
|
||||
type TaskInfo struct {
|
||||
ID string
|
||||
Runtime string
|
||||
@ -14,6 +15,7 @@ type TaskInfo struct {
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// Process is a runtime object for an executing process inside a container
|
||||
type Process interface {
|
||||
ID() string
|
||||
// State returns the process state
|
||||
@ -30,6 +32,7 @@ type Process interface {
|
||||
Wait(context.Context) (*Exit, error)
|
||||
}
|
||||
|
||||
// Task is the runtime object for an executing container
|
||||
type Task interface {
|
||||
Process
|
||||
|
||||
@ -55,27 +58,37 @@ type Task interface {
|
||||
Metrics(context.Context) (interface{}, error)
|
||||
}
|
||||
|
||||
// ExecOpts provides additional options for additional processes running in a task
|
||||
type ExecOpts struct {
|
||||
Spec *types.Any
|
||||
IO IO
|
||||
}
|
||||
|
||||
// ConsoleSize of a pty or windows terminal
|
||||
type ConsoleSize struct {
|
||||
Width uint32
|
||||
Height uint32
|
||||
}
|
||||
|
||||
// Status is the runtime status of a task and/or process
|
||||
type Status int
|
||||
|
||||
const (
|
||||
// CreatedStatus when a process has been created
|
||||
CreatedStatus Status = iota + 1
|
||||
// RunningStatus when a process is running
|
||||
RunningStatus
|
||||
// StoppedStatus when a process has stopped
|
||||
StoppedStatus
|
||||
// DeletedStatus when a process has been deleted
|
||||
DeletedStatus
|
||||
// PausedStatus when a process is paused
|
||||
PausedStatus
|
||||
// PausingStatus when a process is currently pausing
|
||||
PausingStatus
|
||||
)
|
||||
|
||||
// State information for a process
|
||||
type State struct {
|
||||
// Status is the current status of the container
|
||||
Status Status
|
||||
@ -93,6 +106,7 @@ type State struct {
|
||||
Terminal bool
|
||||
}
|
||||
|
||||
// ProcessInfo holds platform specific process information
|
||||
type ProcessInfo struct {
|
||||
// Pid is the process ID
|
||||
Pid uint32
|
||||
|
@ -9,21 +9,26 @@ import (
|
||||
)
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
// NewTaskList returns a new TaskList
|
||||
func NewTaskList() *TaskList {
|
||||
return &TaskList{
|
||||
tasks: make(map[string]map[string]Task),
|
||||
}
|
||||
}
|
||||
|
||||
// TaskList holds and provides locking around tasks
|
||||
type TaskList struct {
|
||||
mu sync.Mutex
|
||||
tasks map[string]map[string]Task
|
||||
}
|
||||
|
||||
// Get a task
|
||||
func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
@ -42,6 +47,7 @@ func (l *TaskList) Get(ctx context.Context, id string) (Task, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// GetAll tasks under a namespace
|
||||
func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
|
||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
@ -58,6 +64,7 @@ func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) {
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Add a task
|
||||
func (l *TaskList) Add(ctx context.Context, t Task) error {
|
||||
namespace, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
@ -66,6 +73,7 @@ func (l *TaskList) Add(ctx context.Context, t Task) error {
|
||||
return l.AddWithNamespace(namespace, t)
|
||||
}
|
||||
|
||||
// AddWithNamespace adds a task with the provided namespace
|
||||
func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
@ -81,6 +89,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete a task
|
||||
func (l *TaskList) Delete(ctx context.Context, t Task) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
|
@ -36,15 +36,15 @@ type Config struct {
|
||||
// GRPCConfig provides GRPC configuration for the socket
|
||||
type GRPCConfig struct {
|
||||
Address string `toml:"address"`
|
||||
Uid int `toml:"uid"`
|
||||
Gid int `toml:"gid"`
|
||||
UID int `toml:"uid"`
|
||||
GID int `toml:"gid"`
|
||||
}
|
||||
|
||||
// Debug provides debug configuration
|
||||
type Debug struct {
|
||||
Address string `toml:"address"`
|
||||
Uid int `toml:"uid"`
|
||||
Gid int `toml:"gid"`
|
||||
UID int `toml:"uid"`
|
||||
GID int `toml:"gid"`
|
||||
Level string `toml:"level"`
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,12 @@ func init() {
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "healthcheck",
|
||||
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{
|
||||
health.NewServer(),
|
||||
}, nil
|
||||
|
@ -107,8 +107,8 @@ func (b *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, erro
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
||||
func (b *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
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 snapshotter, func() (err error) {
|
||||
merr := mount.UnmountAll(root, unix.MNT_DETACH)
|
||||
if err = cleanupDevice(); err != nil {
|
||||
return errors.Wrap(err, "device cleanup failed")
|
||||
} else {
|
||||
err = merr
|
||||
return snapshotter, func() error {
|
||||
err := mount.UnmountAll(root, unix.MNT_DETACH)
|
||||
if cerr := cleanupDevice(); cerr != nil {
|
||||
err = errors.Wrap(cerr, "device cleanup failed")
|
||||
}
|
||||
return err
|
||||
}, nil
|
||||
|
@ -57,7 +57,7 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
return nil, err
|
||||
}
|
||||
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"))
|
||||
if err != nil {
|
||||
|
@ -582,7 +582,7 @@ func encodeSize(size int64) ([]byte, error) {
|
||||
func encodeID(id uint64) ([]byte, error) {
|
||||
var (
|
||||
buf [binary.MaxVarintLen64]byte
|
||||
idEncoded []byte = buf[:]
|
||||
idEncoded = buf[:]
|
||||
)
|
||||
idEncoded = idEncoded[:binary.PutUvarint(idEncoded, id)]
|
||||
|
||||
|
1
task.go
1
task.go
@ -51,6 +51,7 @@ type Status struct {
|
||||
ExitTime time.Time
|
||||
}
|
||||
|
||||
// ProcessInfo provides platform specific process information
|
||||
type ProcessInfo struct {
|
||||
// Pid is the process ID
|
||||
Pid uint32
|
||||
|
@ -46,10 +46,7 @@ func NewLoopback(size int64) (string, func() error, error) {
|
||||
|
||||
// remove file
|
||||
logrus.Debugf("Removing temporary file %s", file.Name())
|
||||
if err = os.Remove(file.Name()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Remove(file.Name())
|
||||
}
|
||||
|
||||
return deviceName, cleanup, nil
|
||||
|
Loading…
Reference in New Issue
Block a user