Merge pull request #1667 from crosbymichael/more-lint

Fix more lint issues across services
This commit is contained in:
Phil Estes 2017-10-23 11:30:39 +02:00 committed by GitHub
commit 5b6564d89d
24 changed files with 169 additions and 136 deletions

View File

@ -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)
} }

View File

@ -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")
} }

View File

@ -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)
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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

View File

@ -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()

View File

@ -33,23 +33,27 @@ type Config struct {
md toml.MetaData md toml.MetaData
} }
// 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
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"`
} }
// MetricsConfig provides metrics configuration
type MetricsConfig struct { type MetricsConfig struct {
Address string `toml:"address"` Address string `toml:"address"`
} }
// CgroupConfig provides cgroup configuration
type CgroupConfig struct { type CgroupConfig struct {
Path string `toml:"path"` Path string `toml:"path"`
} }

View File

@ -34,21 +34,22 @@ func init() {
}) })
} }
type Service struct { type service struct {
db *metadata.DB db *metadata.DB
publisher events.Publisher publisher events.Publisher
} }
// NewService returns the container GRPC server
func NewService(db *metadata.DB, publisher events.Publisher) api.ContainersServer { func NewService(db *metadata.DB, publisher events.Publisher) api.ContainersServer {
return &Service{db: db, publisher: publisher} return &service{db: db, publisher: publisher}
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterContainersServer(server, s) api.RegisterContainersServer(server, s)
return nil return nil
} }
func (s *Service) Get(ctx context.Context, req *api.GetContainerRequest) (*api.GetContainerResponse, error) { func (s *service) Get(ctx context.Context, req *api.GetContainerRequest) (*api.GetContainerResponse, error) {
var resp api.GetContainerResponse var resp api.GetContainerResponse
return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store containers.Store) error { return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store containers.Store) error {
@ -63,7 +64,7 @@ func (s *Service) Get(ctx context.Context, req *api.GetContainerRequest) (*api.G
})) }))
} }
func (s *Service) List(ctx context.Context, req *api.ListContainersRequest) (*api.ListContainersResponse, error) { func (s *service) List(ctx context.Context, req *api.ListContainersRequest) (*api.ListContainersResponse, error) {
var resp api.ListContainersResponse var resp api.ListContainersResponse
return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store containers.Store) error { return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store containers.Store) error {
@ -77,7 +78,7 @@ func (s *Service) List(ctx context.Context, req *api.ListContainersRequest) (*ap
})) }))
} }
func (s *Service) Create(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) { func (s *service) Create(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
var resp api.CreateContainerResponse var resp api.CreateContainerResponse
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store containers.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store containers.Store) error {
@ -108,7 +109,7 @@ func (s *Service) Create(ctx context.Context, req *api.CreateContainerRequest) (
return &resp, nil return &resp, nil
} }
func (s *Service) Update(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) { func (s *service) Update(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) {
if req.Container.ID == "" { if req.Container.ID == "" {
return nil, status.Errorf(codes.InvalidArgument, "Container.ID required") return nil, status.Errorf(codes.InvalidArgument, "Container.ID required")
} }
@ -148,7 +149,7 @@ func (s *Service) Update(ctx context.Context, req *api.UpdateContainerRequest) (
return &resp, nil return &resp, nil
} }
func (s *Service) Delete(ctx context.Context, req *api.DeleteContainerRequest) (*empty.Empty, error) { func (s *service) Delete(ctx context.Context, req *api.DeleteContainerRequest) (*empty.Empty, error) {
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store containers.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store containers.Store) error {
return store.Delete(ctx, req.ID) return store.Delete(ctx, req.ID)
}); err != nil { }); err != nil {
@ -168,14 +169,14 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteContainerRequest) (
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) withStore(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) func(tx *bolt.Tx) error { func (s *service) withStore(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) func(tx *bolt.Tx) error {
return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewContainerStore(tx)) } return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewContainerStore(tx)) }
} }
func (s *Service) withStoreView(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) error { func (s *service) withStoreView(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) error {
return s.db.View(s.withStore(ctx, fn)) return s.db.View(s.withStore(ctx, fn))
} }
func (s *Service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) error { func (s *service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store containers.Store) error) error {
return s.db.Update(s.withStore(ctx, fn)) return s.db.Update(s.withStore(ctx, fn))
} }

View File

@ -21,7 +21,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
) )
type Service struct { type service struct {
store content.Store store content.Store
publisher events.Publisher publisher events.Publisher
} }
@ -32,7 +32,7 @@ var bufPool = sync.Pool{
}, },
} }
var _ api.ContentServer = &Service{} var _ api.ContentServer = &service{}
func init() { func init() {
plugin.Register(&plugin.Registration{ plugin.Register(&plugin.Registration{
@ -53,19 +53,20 @@ func init() {
}) })
} }
func NewService(cs content.Store, publisher events.Publisher) (*Service, error) { // NewService returns the content GRPC server
return &Service{ func NewService(cs content.Store, publisher events.Publisher) (api.ContentServer, error) {
return &service{
store: cs, store: cs,
publisher: publisher, publisher: publisher,
}, nil }, nil
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterContentServer(server, s) api.RegisterContentServer(server, s)
return nil return nil
} }
func (s *Service) Info(ctx context.Context, req *api.InfoRequest) (*api.InfoResponse, error) { func (s *service) Info(ctx context.Context, req *api.InfoRequest) (*api.InfoResponse, error) {
if err := req.Digest.Validate(); err != nil { if err := req.Digest.Validate(); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%q failed validation", req.Digest) return nil, grpc.Errorf(codes.InvalidArgument, "%q failed validation", req.Digest)
} }
@ -80,7 +81,7 @@ func (s *Service) Info(ctx context.Context, req *api.InfoRequest) (*api.InfoResp
}, nil }, nil
} }
func (s *Service) Update(ctx context.Context, req *api.UpdateRequest) (*api.UpdateResponse, error) { func (s *service) Update(ctx context.Context, req *api.UpdateRequest) (*api.UpdateResponse, error) {
if err := req.Info.Digest.Validate(); err != nil { if err := req.Info.Digest.Validate(); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%q failed validation", req.Info.Digest) return nil, grpc.Errorf(codes.InvalidArgument, "%q failed validation", req.Info.Digest)
} }
@ -95,7 +96,7 @@ func (s *Service) Update(ctx context.Context, req *api.UpdateRequest) (*api.Upda
}, nil }, nil
} }
func (s *Service) List(req *api.ListContentRequest, session api.Content_ListServer) error { func (s *service) List(req *api.ListContentRequest, session api.Content_ListServer) error {
var ( var (
buffer []api.Info buffer []api.Info
sendBlock = func(block []api.Info) error { sendBlock = func(block []api.Info) error {
@ -137,7 +138,7 @@ func (s *Service) List(req *api.ListContentRequest, session api.Content_ListServ
return nil return nil
} }
func (s *Service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*empty.Empty, error) { func (s *service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*empty.Empty, error) {
if err := req.Digest.Validate(); err != nil { if err := req.Digest.Validate(); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, err.Error()) return nil, grpc.Errorf(codes.InvalidArgument, err.Error())
} }
@ -155,7 +156,7 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*e
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) Read(req *api.ReadContentRequest, session api.Content_ReadServer) error { func (s *service) Read(req *api.ReadContentRequest, session api.Content_ReadServer) error {
if err := req.Digest.Validate(); err != nil { if err := req.Digest.Validate(); err != nil {
return grpc.Errorf(codes.InvalidArgument, "%v: %v", req.Digest, err) return grpc.Errorf(codes.InvalidArgument, "%v: %v", req.Digest, err)
} }
@ -223,7 +224,7 @@ func (rw *readResponseWriter) Write(p []byte) (n int, err error) {
return len(p), nil return len(p), nil
} }
func (s *Service) Status(ctx context.Context, req *api.StatusRequest) (*api.StatusResponse, error) { func (s *service) Status(ctx context.Context, req *api.StatusRequest) (*api.StatusResponse, error) {
status, err := s.store.Status(ctx, req.Ref) status, err := s.store.Status(ctx, req.Ref)
if err != nil { if err != nil {
return nil, errdefs.ToGRPCf(err, "could not get status for ref %q", req.Ref) return nil, errdefs.ToGRPCf(err, "could not get status for ref %q", req.Ref)
@ -242,7 +243,7 @@ func (s *Service) Status(ctx context.Context, req *api.StatusRequest) (*api.Stat
return &resp, nil return &resp, nil
} }
func (s *Service) ListStatuses(ctx context.Context, req *api.ListStatusesRequest) (*api.ListStatusesResponse, error) { func (s *service) ListStatuses(ctx context.Context, req *api.ListStatusesRequest) (*api.ListStatusesResponse, error) {
statuses, err := s.store.ListStatuses(ctx, req.Filters...) statuses, err := s.store.ListStatuses(ctx, req.Filters...)
if err != nil { if err != nil {
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
@ -263,7 +264,7 @@ func (s *Service) ListStatuses(ctx context.Context, req *api.ListStatusesRequest
return &resp, nil return &resp, nil
} }
func (s *Service) Write(session api.Content_WriteServer) (err error) { func (s *service) Write(session api.Content_WriteServer) (err error) {
var ( var (
ctx = session.Context() ctx = session.Context()
msg api.WriteContentResponse msg api.WriteContentResponse
@ -283,7 +284,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
// identically across all GRPC methods. // identically across all GRPC methods.
// //
// This is pretty noisy, so we can remove it but leave it for now. // This is pretty noisy, so we can remove it but leave it for now.
log.G(ctx).WithError(err).Error("(*Service).Write failed") log.G(ctx).WithError(err).Error("(*service).Write failed")
} }
return return
@ -319,7 +320,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
ctx = log.WithLogger(ctx, log.G(ctx).WithFields(fields)) ctx = log.WithLogger(ctx, log.G(ctx).WithFields(fields))
log.G(ctx).Debug("(*Service).Write started") log.G(ctx).Debug("(*service).Write started")
// this action locks the writer for the session. // this action locks the writer for the session.
wr, err := s.store.Writer(ctx, ref, total, expected) wr, err := s.store.Writer(ctx, ref, total, expected)
if err != nil { if err != nil {
@ -444,7 +445,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
} }
} }
func (s *Service) Abort(ctx context.Context, req *api.AbortRequest) (*empty.Empty, error) { func (s *service) Abort(ctx context.Context, req *api.AbortRequest) (*empty.Empty, error) {
if err := s.store.Abort(ctx, req.Ref); err != nil { if err := s.store.Abort(ctx, req.Ref); err != nil {
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }

View File

@ -21,20 +21,21 @@ func init() {
}) })
} }
type Service struct { type service struct {
events *events.Exchange events *events.Exchange
} }
// NewService returns the GRPC events server
func NewService(events *events.Exchange) api.EventsServer { func NewService(events *events.Exchange) api.EventsServer {
return &Service{events: events} return &service{events: events}
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterEventsServer(server, s) api.RegisterEventsServer(server, s)
return nil return nil
} }
func (s *Service) Publish(ctx context.Context, r *api.PublishRequest) (*empty.Empty, error) { func (s *service) Publish(ctx context.Context, r *api.PublishRequest) (*empty.Empty, error) {
if err := s.events.Publish(ctx, r.Topic, r.Event); err != nil { if err := s.events.Publish(ctx, r.Topic, r.Event); err != nil {
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }
@ -42,7 +43,7 @@ func (s *Service) Publish(ctx context.Context, r *api.PublishRequest) (*empty.Em
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) Forward(ctx context.Context, r *api.ForwardRequest) (*empty.Empty, error) { func (s *service) Forward(ctx context.Context, r *api.ForwardRequest) (*empty.Empty, error) {
if err := s.events.Forward(ctx, r.Envelope); err != nil { if err := s.events.Forward(ctx, r.Envelope); err != nil {
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }
@ -50,7 +51,7 @@ func (s *Service) Forward(ctx context.Context, r *api.ForwardRequest) (*empty.Em
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) Subscribe(req *api.SubscribeRequest, srv api.Events_SubscribeServer) error { func (s *service) Subscribe(req *api.SubscribeRequest, srv api.Events_SubscribeServer) error {
ctx, cancel := context.WithCancel(srv.Context()) ctx, cancel := context.WithCancel(srv.Context())
defer cancel() defer cancel()

View File

@ -8,7 +8,7 @@ import (
"google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/health/grpc_health_v1"
) )
type Service struct { type service struct {
serve *health.Server serve *health.Server
} }
@ -17,18 +17,18 @@ 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()
}, },
}) })
} }
func NewService() (*Service, error) { func newService() (*service, error) {
return &Service{ return &service{
health.NewServer(), health.NewServer(),
}, nil }, nil
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
grpc_health_v1.RegisterHealthServer(server, s.serve) grpc_health_v1.RegisterHealthServer(server, s.serve)
return nil return nil
} }

View File

@ -34,24 +34,25 @@ func init() {
}) })
} }
type Service struct { type service struct {
db *metadata.DB db *metadata.DB
publisher events.Publisher publisher events.Publisher
} }
// NewService returns the GRPC image server
func NewService(db *metadata.DB, publisher events.Publisher) imagesapi.ImagesServer { func NewService(db *metadata.DB, publisher events.Publisher) imagesapi.ImagesServer {
return &Service{ return &service{
db: db, db: db,
publisher: publisher, publisher: publisher,
} }
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
imagesapi.RegisterImagesServer(server, s) imagesapi.RegisterImagesServer(server, s)
return nil return nil
} }
func (s *Service) Get(ctx context.Context, req *imagesapi.GetImageRequest) (*imagesapi.GetImageResponse, error) { func (s *service) Get(ctx context.Context, req *imagesapi.GetImageRequest) (*imagesapi.GetImageResponse, error) {
var resp imagesapi.GetImageResponse var resp imagesapi.GetImageResponse
return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store images.Store) error { return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store images.Store) error {
@ -65,7 +66,7 @@ func (s *Service) Get(ctx context.Context, req *imagesapi.GetImageRequest) (*ima
})) }))
} }
func (s *Service) List(ctx context.Context, req *imagesapi.ListImagesRequest) (*imagesapi.ListImagesResponse, error) { func (s *service) List(ctx context.Context, req *imagesapi.ListImagesRequest) (*imagesapi.ListImagesResponse, error) {
var resp imagesapi.ListImagesResponse var resp imagesapi.ListImagesResponse
return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store images.Store) error { return &resp, errdefs.ToGRPC(s.withStoreView(ctx, func(ctx context.Context, store images.Store) error {
@ -79,7 +80,7 @@ func (s *Service) List(ctx context.Context, req *imagesapi.ListImagesRequest) (*
})) }))
} }
func (s *Service) Create(ctx context.Context, req *imagesapi.CreateImageRequest) (*imagesapi.CreateImageResponse, error) { func (s *service) Create(ctx context.Context, req *imagesapi.CreateImageRequest) (*imagesapi.CreateImageResponse, error) {
if req.Image.Name == "" { if req.Image.Name == "" {
return nil, status.Errorf(codes.InvalidArgument, "Image.Name required") return nil, status.Errorf(codes.InvalidArgument, "Image.Name required")
} }
@ -111,7 +112,7 @@ func (s *Service) Create(ctx context.Context, req *imagesapi.CreateImageRequest)
} }
func (s *Service) Update(ctx context.Context, req *imagesapi.UpdateImageRequest) (*imagesapi.UpdateImageResponse, error) { func (s *service) Update(ctx context.Context, req *imagesapi.UpdateImageRequest) (*imagesapi.UpdateImageResponse, error) {
if req.Image.Name == "" { if req.Image.Name == "" {
return nil, status.Errorf(codes.InvalidArgument, "Image.Name required") return nil, status.Errorf(codes.InvalidArgument, "Image.Name required")
} }
@ -149,7 +150,7 @@ func (s *Service) Update(ctx context.Context, req *imagesapi.UpdateImageRequest)
return &resp, nil return &resp, nil
} }
func (s *Service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest) (*empty.Empty, error) { func (s *service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest) (*empty.Empty, error) {
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store images.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store images.Store) error {
return errdefs.ToGRPC(store.Delete(ctx, req.Name)) return errdefs.ToGRPC(store.Delete(ctx, req.Name))
}); err != nil { }); err != nil {
@ -169,14 +170,14 @@ func (s *Service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest)
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) withStore(ctx context.Context, fn func(ctx context.Context, store images.Store) error) func(tx *bolt.Tx) error { func (s *service) withStore(ctx context.Context, fn func(ctx context.Context, store images.Store) error) func(tx *bolt.Tx) error {
return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewImageStore(tx)) } return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewImageStore(tx)) }
} }
func (s *Service) withStoreView(ctx context.Context, fn func(ctx context.Context, store images.Store) error) error { func (s *service) withStoreView(ctx context.Context, fn func(ctx context.Context, store images.Store) error) error {
return s.db.View(s.withStore(ctx, fn)) return s.db.View(s.withStore(ctx, fn))
} }
func (s *Service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store images.Store) error) error { func (s *service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store images.Store) error) error {
return s.db.Update(s.withStore(ctx, fn)) return s.db.Update(s.withStore(ctx, fn))
} }

View File

@ -28,22 +28,23 @@ func init() {
}) })
} }
type Service struct { type service struct {
plugins []api.Plugin plugins []api.Plugin
} }
// NewService returns the GRPC introspection server
func NewService(plugins []api.Plugin) api.IntrospectionServer { func NewService(plugins []api.Plugin) api.IntrospectionServer {
return &Service{ return &service{
plugins: plugins, plugins: plugins,
} }
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterIntrospectionServer(server, s) api.RegisterIntrospectionServer(server, s)
return nil return nil
} }
func (s *Service) Plugins(ctx context.Context, req *api.PluginsRequest) (*api.PluginsResponse, error) { func (s *service) Plugins(ctx context.Context, req *api.PluginsRequest) (*api.PluginsResponse, error) {
filter, err := filters.ParseAll(req.Filters...) filter, err := filters.ParseAll(req.Filters...)
if err != nil { if err != nil {
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, err.Error()) return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, err.Error())

View File

@ -34,26 +34,27 @@ func init() {
}) })
} }
type Service struct { type service struct {
db *metadata.DB db *metadata.DB
publisher events.Publisher publisher events.Publisher
} }
var _ api.NamespacesServer = &Service{} var _ api.NamespacesServer = &service{}
// NewService returns the GRPC namespaces server
func NewService(db *metadata.DB, publisher events.Publisher) api.NamespacesServer { func NewService(db *metadata.DB, publisher events.Publisher) api.NamespacesServer {
return &Service{ return &service{
db: db, db: db,
publisher: publisher, publisher: publisher,
} }
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterNamespacesServer(server, s) api.RegisterNamespacesServer(server, s)
return nil return nil
} }
func (s *Service) Get(ctx context.Context, req *api.GetNamespaceRequest) (*api.GetNamespaceResponse, error) { func (s *service) Get(ctx context.Context, req *api.GetNamespaceRequest) (*api.GetNamespaceResponse, error) {
var resp api.GetNamespaceResponse var resp api.GetNamespaceResponse
return &resp, s.withStoreView(ctx, func(ctx context.Context, store namespaces.Store) error { return &resp, s.withStoreView(ctx, func(ctx context.Context, store namespaces.Store) error {
@ -71,7 +72,7 @@ func (s *Service) Get(ctx context.Context, req *api.GetNamespaceRequest) (*api.G
}) })
} }
func (s *Service) List(ctx context.Context, req *api.ListNamespacesRequest) (*api.ListNamespacesResponse, error) { func (s *service) List(ctx context.Context, req *api.ListNamespacesRequest) (*api.ListNamespacesResponse, error) {
var resp api.ListNamespacesResponse var resp api.ListNamespacesResponse
return &resp, s.withStoreView(ctx, func(ctx context.Context, store namespaces.Store) error { return &resp, s.withStoreView(ctx, func(ctx context.Context, store namespaces.Store) error {
@ -98,7 +99,7 @@ func (s *Service) List(ctx context.Context, req *api.ListNamespacesRequest) (*ap
}) })
} }
func (s *Service) Create(ctx context.Context, req *api.CreateNamespaceRequest) (*api.CreateNamespaceResponse, error) { func (s *service) Create(ctx context.Context, req *api.CreateNamespaceRequest) (*api.CreateNamespaceResponse, error) {
var resp api.CreateNamespaceResponse var resp api.CreateNamespaceResponse
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error {
@ -129,7 +130,7 @@ func (s *Service) Create(ctx context.Context, req *api.CreateNamespaceRequest) (
} }
func (s *Service) Update(ctx context.Context, req *api.UpdateNamespaceRequest) (*api.UpdateNamespaceResponse, error) { func (s *service) Update(ctx context.Context, req *api.UpdateNamespaceRequest) (*api.UpdateNamespaceResponse, error) {
var resp api.UpdateNamespaceResponse var resp api.UpdateNamespaceResponse
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error {
if req.UpdateMask != nil && len(req.UpdateMask.Paths) > 0 { if req.UpdateMask != nil && len(req.UpdateMask.Paths) > 0 {
@ -181,7 +182,7 @@ func (s *Service) Update(ctx context.Context, req *api.UpdateNamespaceRequest) (
return &resp, nil return &resp, nil
} }
func (s *Service) Delete(ctx context.Context, req *api.DeleteNamespaceRequest) (*empty.Empty, error) { func (s *service) Delete(ctx context.Context, req *api.DeleteNamespaceRequest) (*empty.Empty, error) {
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error { if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error {
return errdefs.ToGRPC(store.Delete(ctx, req.Name)) return errdefs.ToGRPC(store.Delete(ctx, req.Name))
}); err != nil { }); err != nil {
@ -198,14 +199,14 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteNamespaceRequest) (
return &empty.Empty{}, nil return &empty.Empty{}, nil
} }
func (s *Service) withStore(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) func(tx *bolt.Tx) error { func (s *service) withStore(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) func(tx *bolt.Tx) error {
return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewNamespaceStore(tx)) } return func(tx *bolt.Tx) error { return fn(ctx, metadata.NewNamespaceStore(tx)) }
} }
func (s *Service) withStoreView(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) error { func (s *service) withStoreView(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) error {
return s.db.View(s.withStore(ctx, fn)) return s.db.View(s.withStore(ctx, fn))
} }
func (s *Service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) error { func (s *service) withStoreUpdate(ctx context.Context, fn func(ctx context.Context, store namespaces.Store) error) error {
return s.db.Update(s.withStore(ctx, fn)) return s.db.Update(s.withStore(ctx, fn))
} }

View File

@ -34,7 +34,7 @@ import (
) )
var ( var (
_ = (api.TasksServer)(&Service{}) _ = (api.TasksServer)(&service{})
empty = &google_protobuf.Empty{} empty = &google_protobuf.Empty{}
) )
@ -46,11 +46,11 @@ func init() {
plugin.RuntimePlugin, plugin.RuntimePlugin,
plugin.MetadataPlugin, plugin.MetadataPlugin,
}, },
InitFn: New, InitFn: initFunc,
}) })
} }
func New(ic *plugin.InitContext) (interface{}, error) { func initFunc(ic *plugin.InitContext) (interface{}, error) {
rt, err := ic.GetByType(plugin.RuntimePlugin) rt, err := ic.GetByType(plugin.RuntimePlugin)
if err != nil { if err != nil {
return nil, err return nil, err
@ -75,7 +75,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
if len(runtimes) == 0 { if len(runtimes) == 0 {
return nil, errors.New("no runtimes available to create task service") return nil, errors.New("no runtimes available to create task service")
} }
return &Service{ return &service{
runtimes: runtimes, runtimes: runtimes,
db: m.(*metadata.DB), db: m.(*metadata.DB),
store: cs, store: cs,
@ -83,19 +83,19 @@ func New(ic *plugin.InitContext) (interface{}, error) {
}, nil }, nil
} }
type Service struct { type service struct {
runtimes map[string]runtime.Runtime runtimes map[string]runtime.Runtime
db *metadata.DB db *metadata.DB
store content.Store store content.Store
publisher events.Publisher publisher events.Publisher
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterTasksServer(server, s) api.RegisterTasksServer(server, s)
return nil return nil
} }
func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.CreateTaskResponse, error) { func (s *service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.CreateTaskResponse, error) {
var ( var (
checkpointPath string checkpointPath string
err error err error
@ -160,7 +160,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr
}, nil }, nil
} }
func (s *Service) Start(ctx context.Context, r *api.StartRequest) (*api.StartResponse, error) { func (s *service) Start(ctx context.Context, r *api.StartRequest) (*api.StartResponse, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -183,7 +183,7 @@ func (s *Service) Start(ctx context.Context, r *api.StartRequest) (*api.StartRes
}, nil }, nil
} }
func (s *Service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.DeleteResponse, error) { func (s *service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.DeleteResponse, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -203,7 +203,7 @@ func (s *Service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.De
}, nil }, nil
} }
func (s *Service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*api.DeleteResponse, error) { func (s *service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*api.DeleteResponse, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -253,7 +253,7 @@ func processFromContainerd(ctx context.Context, p runtime.Process) (*task.Proces
}, nil }, nil
} }
func (s *Service) Get(ctx context.Context, r *api.GetRequest) (*api.GetResponse, error) { func (s *service) Get(ctx context.Context, r *api.GetRequest) (*api.GetResponse, error) {
task, err := s.getTask(ctx, r.ContainerID) task, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -273,7 +273,7 @@ func (s *Service) Get(ctx context.Context, r *api.GetRequest) (*api.GetResponse,
}, nil }, nil
} }
func (s *Service) List(ctx context.Context, r *api.ListTasksRequest) (*api.ListTasksResponse, error) { func (s *service) List(ctx context.Context, r *api.ListTasksRequest) (*api.ListTasksResponse, error) {
resp := &api.ListTasksResponse{} resp := &api.ListTasksResponse{}
for _, r := range s.runtimes { for _, r := range s.runtimes {
tasks, err := r.Tasks(ctx) tasks, err := r.Tasks(ctx)
@ -296,7 +296,7 @@ func addTasks(ctx context.Context, r *api.ListTasksResponse, tasks []runtime.Tas
} }
} }
func (s *Service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*google_protobuf.Empty, error) { func (s *service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -308,7 +308,7 @@ func (s *Service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*google_p
return empty, nil return empty, nil
} }
func (s *Service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*google_protobuf.Empty, error) { func (s *service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -320,7 +320,7 @@ func (s *Service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*google
return empty, nil return empty, nil
} }
func (s *Service) Kill(ctx context.Context, r *api.KillRequest) (*google_protobuf.Empty, error) { func (s *service) Kill(ctx context.Context, r *api.KillRequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -337,7 +337,7 @@ func (s *Service) Kill(ctx context.Context, r *api.KillRequest) (*google_protobu
return empty, nil return empty, nil
} }
func (s *Service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.ListPidsResponse, error) { func (s *service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.ListPidsResponse, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -365,7 +365,7 @@ func (s *Service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.Li
}, nil }, nil
} }
func (s *Service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*google_protobuf.Empty, error) { func (s *service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*google_protobuf.Empty, error) {
if r.ExecID == "" { if r.ExecID == "" {
return nil, grpc.Errorf(codes.InvalidArgument, "exec id cannot be empty") return nil, grpc.Errorf(codes.InvalidArgument, "exec id cannot be empty")
} }
@ -387,7 +387,7 @@ func (s *Service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*google_
return empty, nil return empty, nil
} }
func (s *Service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*google_protobuf.Empty, error) { func (s *service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -407,7 +407,7 @@ func (s *Service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*goog
return empty, nil return empty, nil
} }
func (s *Service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_protobuf.Empty, error) { func (s *service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -426,7 +426,7 @@ func (s *Service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_p
return empty, nil return empty, nil
} }
func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) (*api.CheckpointTaskResponse, error) { func (s *service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) (*api.CheckpointTaskResponse, error) {
container, err := s.getContainer(ctx, r.ContainerID) container, err := s.getContainer(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -471,7 +471,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest)
}, nil }, nil
} }
func (s *Service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google_protobuf.Empty, error) { func (s *service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google_protobuf.Empty, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -482,7 +482,7 @@ func (s *Service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google
return empty, nil return empty, nil
} }
func (s *Service) Metrics(ctx context.Context, r *api.MetricsRequest) (*api.MetricsResponse, error) { func (s *service) Metrics(ctx context.Context, r *api.MetricsRequest) (*api.MetricsResponse, error) {
filter, err := filters.ParseAll(r.Filters...) filter, err := filters.ParseAll(r.Filters...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -498,7 +498,7 @@ func (s *Service) Metrics(ctx context.Context, r *api.MetricsRequest) (*api.Metr
return &resp, nil return &resp, nil
} }
func (s *Service) Wait(ctx context.Context, r *api.WaitRequest) (*api.WaitResponse, error) { func (s *service) Wait(ctx context.Context, r *api.WaitRequest) (*api.WaitResponse, error) {
t, err := s.getTask(ctx, r.ContainerID) t, err := s.getTask(ctx, r.ContainerID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -557,7 +557,7 @@ func getTasksMetrics(ctx context.Context, filter filters.Filter, tasks []runtime
} }
} }
func (s *Service) writeContent(ctx context.Context, mediaType, ref string, r io.Reader) (*types.Descriptor, error) { func (s *service) writeContent(ctx context.Context, mediaType, ref string, r io.Reader) (*types.Descriptor, error) {
writer, err := s.store.Writer(ctx, ref, 0, "") writer, err := s.store.Writer(ctx, ref, 0, "")
if err != nil { if err != nil {
return nil, err return nil, err
@ -580,7 +580,7 @@ func (s *Service) writeContent(ctx context.Context, mediaType, ref string, r io.
}, nil }, nil
} }
func (s *Service) getContainer(ctx context.Context, id string) (*containers.Container, error) { func (s *service) getContainer(ctx context.Context, id string) (*containers.Container, error) {
var container containers.Container var container containers.Container
if err := s.db.View(func(tx *bolt.Tx) error { if err := s.db.View(func(tx *bolt.Tx) error {
store := metadata.NewContainerStore(tx) store := metadata.NewContainerStore(tx)
@ -593,7 +593,7 @@ func (s *Service) getContainer(ctx context.Context, id string) (*containers.Cont
return &container, nil return &container, nil
} }
func (s *Service) getTask(ctx context.Context, id string) (runtime.Task, error) { func (s *service) getTask(ctx context.Context, id string) (runtime.Task, error) {
container, err := s.getContainer(ctx, id) container, err := s.getContainer(ctx, id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -601,7 +601,7 @@ func (s *Service) getTask(ctx context.Context, id string) (runtime.Task, error)
return s.getTaskFromContainer(ctx, container) return s.getTaskFromContainer(ctx, container)
} }
func (s *Service) getTaskFromContainer(ctx context.Context, container *containers.Container) (runtime.Task, error) { func (s *service) getTaskFromContainer(ctx context.Context, container *containers.Container) (runtime.Task, error) {
runtime, err := s.getRuntime(container.Runtime.Name) runtime, err := s.getRuntime(container.Runtime.Name)
if err != nil { if err != nil {
return nil, errdefs.ToGRPCf(err, "runtime for task %s", container.Runtime.Name) return nil, errdefs.ToGRPCf(err, "runtime for task %s", container.Runtime.Name)
@ -613,7 +613,7 @@ func (s *Service) getTaskFromContainer(ctx context.Context, container *container
return t, nil return t, nil
} }
func (s *Service) getRuntime(name string) (runtime.Runtime, error) { func (s *service) getRuntime(name string) (runtime.Runtime, error) {
runtime, ok := s.runtimes[name] runtime, ok := s.runtimes[name]
if !ok { if !ok {
return nil, grpc.Errorf(codes.NotFound, "unknown runtime %q", name) return nil, grpc.Errorf(codes.NotFound, "unknown runtime %q", name)

View File

@ -9,29 +9,29 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
var _ api.VersionServer = &Service{} var _ api.VersionServer = &service{}
func init() { func init() {
plugin.Register(&plugin.Registration{ plugin.Register(&plugin.Registration{
Type: plugin.GRPCPlugin, Type: plugin.GRPCPlugin,
ID: "version", ID: "version",
InitFn: New, InitFn: initFunc,
}) })
} }
func New(ic *plugin.InitContext) (interface{}, error) { func initFunc(ic *plugin.InitContext) (interface{}, error) {
return &Service{}, nil return &service{}, nil
} }
type Service struct { type service struct {
} }
func (s *Service) Register(server *grpc.Server) error { func (s *service) Register(server *grpc.Server) error {
api.RegisterVersionServer(server, s) api.RegisterVersionServer(server, s)
return nil return nil
} }
func (s *Service) Version(ctx context.Context, _ *empty.Empty) (*api.VersionResponse, error) { func (s *service) Version(ctx context.Context, _ *empty.Empty) (*api.VersionResponse, error) {
return &api.VersionResponse{ return &api.VersionResponse{
Version: ctrdversion.Version, Version: ctrdversion.Version,
Revision: ctrdversion.Revision, Revision: ctrdversion.Revision,

View File

@ -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
} }

View File

@ -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

View File

@ -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 {

View File

@ -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)]

View File

@ -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

View File

@ -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

View File

@ -1,2 +1,2 @@
// hcsshimtypes holds the windows runtime specific types // Package hcsshimtypes holds the windows runtime specific types
package hcsshimtypes package hcsshimtypes