Merge pull request #1667 from crosbymichael/more-lint
Fix more lint issues across services
This commit is contained in:
commit
5b6564d89d
@ -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 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()
|
||||
|
@ -33,23 +33,27 @@ type Config struct {
|
||||
md toml.MetaData
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// MetricsConfig provides metrics configuration
|
||||
type MetricsConfig struct {
|
||||
Address string `toml:"address"`
|
||||
}
|
||||
|
||||
// CgroupConfig provides cgroup configuration
|
||||
type CgroupConfig struct {
|
||||
Path string `toml:"path"`
|
||||
}
|
||||
|
@ -34,21 +34,22 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
db *metadata.DB
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
// NewService returns the container GRPC server
|
||||
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)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 == "" {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return store.Delete(ctx, req.ID)
|
||||
}); err != nil {
|
||||
@ -168,14 +169,14 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteContainerRequest) (
|
||||
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)) }
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
store content.Store
|
||||
publisher events.Publisher
|
||||
}
|
||||
@ -32,7 +32,7 @@ var bufPool = sync.Pool{
|
||||
},
|
||||
}
|
||||
|
||||
var _ api.ContentServer = &Service{}
|
||||
var _ api.ContentServer = &service{}
|
||||
|
||||
func init() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
@ -53,19 +53,20 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func NewService(cs content.Store, publisher events.Publisher) (*Service, error) {
|
||||
return &Service{
|
||||
// NewService returns the content GRPC server
|
||||
func NewService(cs content.Store, publisher events.Publisher) (api.ContentServer, error) {
|
||||
return &service{
|
||||
store: cs,
|
||||
publisher: publisher,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
api.RegisterContentServer(server, s)
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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 (
|
||||
buffer []api.Info
|
||||
sendBlock = func(block []api.Info) error {
|
||||
@ -137,7 +138,7 @@ func (s *Service) List(req *api.ListContentRequest, session api.Content_ListServ
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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...)
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
@ -263,7 +264,7 @@ func (s *Service) ListStatuses(ctx context.Context, req *api.ListStatusesRequest
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) Write(session api.Content_WriteServer) (err error) {
|
||||
func (s *service) Write(session api.Content_WriteServer) (err error) {
|
||||
var (
|
||||
ctx = session.Context()
|
||||
msg api.WriteContentResponse
|
||||
@ -283,7 +284,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
|
||||
// identically across all GRPC methods.
|
||||
//
|
||||
// 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
|
||||
@ -319,7 +320,7 @@ func (s *Service) Write(session api.Content_WriteServer) (err error) {
|
||||
|
||||
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.
|
||||
wr, err := s.store.Writer(ctx, ref, total, expected)
|
||||
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 {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
|
@ -21,20 +21,21 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
events *events.Exchange
|
||||
}
|
||||
|
||||
// NewService returns the GRPC events server
|
||||
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)
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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())
|
||||
defer cancel()
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
serve *health.Server
|
||||
}
|
||||
|
||||
@ -17,18 +17,18 @@ func init() {
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "healthcheck",
|
||||
InitFn: func(*plugin.InitContext) (interface{}, error) {
|
||||
return NewService()
|
||||
return newService()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func NewService() (*Service, error) {
|
||||
return &Service{
|
||||
func newService() (*service, error) {
|
||||
return &service{
|
||||
health.NewServer(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
grpc_health_v1.RegisterHealthServer(server, s.serve)
|
||||
return nil
|
||||
}
|
||||
|
@ -34,24 +34,25 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
db *metadata.DB
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
// NewService returns the GRPC image server
|
||||
func NewService(db *metadata.DB, publisher events.Publisher) imagesapi.ImagesServer {
|
||||
return &Service{
|
||||
return &service{
|
||||
db: db,
|
||||
publisher: publisher,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
imagesapi.RegisterImagesServer(server, s)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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 == "" {
|
||||
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 == "" {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return errdefs.ToGRPC(store.Delete(ctx, req.Name))
|
||||
}); err != nil {
|
||||
@ -169,14 +170,14 @@ func (s *Service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest)
|
||||
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)) }
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
@ -28,22 +28,23 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
plugins []api.Plugin
|
||||
}
|
||||
|
||||
// NewService returns the GRPC introspection server
|
||||
func NewService(plugins []api.Plugin) api.IntrospectionServer {
|
||||
return &Service{
|
||||
return &service{
|
||||
plugins: plugins,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
api.RegisterIntrospectionServer(server, s)
|
||||
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...)
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, err.Error())
|
||||
|
@ -34,26 +34,27 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
db *metadata.DB
|
||||
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 {
|
||||
return &Service{
|
||||
return &service{
|
||||
db: db,
|
||||
publisher: publisher,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
api.RegisterNamespacesServer(server, s)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
if err := s.withStoreUpdate(ctx, func(ctx context.Context, store namespaces.Store) error {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return errdefs.ToGRPC(store.Delete(ctx, req.Name))
|
||||
}); err != nil {
|
||||
@ -198,14 +199,14 @@ func (s *Service) Delete(ctx context.Context, req *api.DeleteNamespaceRequest) (
|
||||
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)) }
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ = (api.TasksServer)(&Service{})
|
||||
_ = (api.TasksServer)(&service{})
|
||||
empty = &google_protobuf.Empty{}
|
||||
)
|
||||
|
||||
@ -46,11 +46,11 @@ func init() {
|
||||
plugin.RuntimePlugin,
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -75,7 +75,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
if len(runtimes) == 0 {
|
||||
return nil, errors.New("no runtimes available to create task service")
|
||||
}
|
||||
return &Service{
|
||||
return &service{
|
||||
runtimes: runtimes,
|
||||
db: m.(*metadata.DB),
|
||||
store: cs,
|
||||
@ -83,19 +83,19 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
type service struct {
|
||||
runtimes map[string]runtime.Runtime
|
||||
db *metadata.DB
|
||||
store content.Store
|
||||
publisher events.Publisher
|
||||
}
|
||||
|
||||
func (s *Service) Register(server *grpc.Server) error {
|
||||
func (s *service) Register(server *grpc.Server) error {
|
||||
api.RegisterTasksServer(server, s)
|
||||
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 (
|
||||
checkpointPath string
|
||||
err error
|
||||
@ -160,7 +160,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -183,7 +183,7 @@ func (s *Service) Start(ctx context.Context, r *api.StartRequest) (*api.StartRes
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -203,7 +203,7 @@ func (s *Service) Delete(ctx context.Context, r *api.DeleteTaskRequest) (*api.De
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -253,7 +253,7 @@ func processFromContainerd(ctx context.Context, p runtime.Process) (*task.Proces
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -273,7 +273,7 @@ func (s *Service) Get(ctx context.Context, r *api.GetRequest) (*api.GetResponse,
|
||||
}, 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{}
|
||||
for _, r := range s.runtimes {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -308,7 +308,7 @@ func (s *Service) Pause(ctx context.Context, r *api.PauseTaskRequest) (*google_p
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -320,7 +320,7 @@ func (s *Service) Resume(ctx context.Context, r *api.ResumeTaskRequest) (*google
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -337,7 +337,7 @@ func (s *Service) Kill(ctx context.Context, r *api.KillRequest) (*google_protobu
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -365,7 +365,7 @@ func (s *Service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.Li
|
||||
}, 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 == "" {
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -407,7 +407,7 @@ func (s *Service) ResizePty(ctx context.Context, r *api.ResizePtyRequest) (*goog
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -426,7 +426,7 @@ func (s *Service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_p
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -471,7 +471,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest)
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -482,7 +482,7 @@ func (s *Service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google
|
||||
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...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -498,7 +498,7 @@ func (s *Service) Metrics(ctx context.Context, r *api.MetricsRequest) (*api.Metr
|
||||
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)
|
||||
if err != nil {
|
||||
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, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -580,7 +580,7 @@ func (s *Service) writeContent(ctx context.Context, mediaType, ref string, r io.
|
||||
}, 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
|
||||
if err := s.db.View(func(tx *bolt.Tx) error {
|
||||
store := metadata.NewContainerStore(tx)
|
||||
@ -593,7 +593,7 @@ func (s *Service) getContainer(ctx context.Context, id string) (*containers.Cont
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -601,7 +601,7 @@ func (s *Service) getTask(ctx context.Context, id string) (runtime.Task, error)
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
func (s *Service) getRuntime(name string) (runtime.Runtime, error) {
|
||||
func (s *service) getRuntime(name string) (runtime.Runtime, error) {
|
||||
runtime, ok := s.runtimes[name]
|
||||
if !ok {
|
||||
return nil, grpc.Errorf(codes.NotFound, "unknown runtime %q", name)
|
||||
|
@ -9,29 +9,29 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ api.VersionServer = &Service{}
|
||||
var _ api.VersionServer = &service{}
|
||||
|
||||
func init() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.GRPCPlugin,
|
||||
ID: "version",
|
||||
InitFn: New,
|
||||
InitFn: initFunc,
|
||||
})
|
||||
}
|
||||
|
||||
func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
return &Service{}, nil
|
||||
func initFunc(ic *plugin.InitContext) (interface{}, error) {
|
||||
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)
|
||||
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{
|
||||
Version: ctrdversion.Version,
|
||||
Revision: ctrdversion.Revision,
|
||||
|
@ -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
|
||||
|
@ -1,2 +1,2 @@
|
||||
// hcsshimtypes holds the windows runtime specific types
|
||||
// Package hcsshimtypes holds the windows runtime specific types
|
||||
package hcsshimtypes
|
||||
|
Loading…
Reference in New Issue
Block a user