From 9bd1dc78cb20988a906537d54943a18812e5d63d Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 20 Oct 2017 11:18:37 -0400 Subject: [PATCH 1/2] Unexport grpc service types Since these are registered and the interface is what matters, these Service types do not need to be exported. Signed-off-by: Michael Crosby --- server/config.go | 4 +++ services/containers/service.go | 23 +++++++------ services/content/service.go | 33 +++++++++--------- services/events/service.go | 13 +++---- services/healthcheck/service.go | 9 ++--- services/images/service.go | 23 +++++++------ services/introspection/service.go | 9 ++--- services/namespaces/service.go | 25 +++++++------- services/tasks/service.go | 56 +++++++++++++++---------------- services/version/service.go | 14 ++++---- windows/hcsshimtypes/doc.go | 2 +- 11 files changed, 111 insertions(+), 100 deletions(-) diff --git a/server/config.go b/server/config.go index 764f6bdf2..d6c2ca644 100644 --- a/server/config.go +++ b/server/config.go @@ -33,12 +33,14 @@ 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"` } +// Debug provides debug configuration type Debug struct { Address string `toml:"address"` Uid int `toml:"uid"` @@ -46,10 +48,12 @@ type Debug struct { 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"` } diff --git a/services/containers/service.go b/services/containers/service.go index c5322f874..81af3f169 100644 --- a/services/containers/service.go +++ b/services/containers/service.go @@ -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)) } diff --git a/services/content/service.go b/services/content/service.go index 8289e1e64..3784579d5 100644 --- a/services/content/service.go +++ b/services/content/service.go @@ -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) } diff --git a/services/events/service.go b/services/events/service.go index ae2d3913f..c6f080b8c 100644 --- a/services/events/service.go +++ b/services/events/service.go @@ -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() diff --git a/services/healthcheck/service.go b/services/healthcheck/service.go index bb7d33e5f..85ffdab67 100644 --- a/services/healthcheck/service.go +++ b/services/healthcheck/service.go @@ -8,7 +8,7 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" ) -type Service struct { +type service struct { serve *health.Server } @@ -22,13 +22,14 @@ func init() { }) } -func NewService() (*Service, error) { - return &Service{ +// NewService returns the GRPC health server +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 } diff --git a/services/images/service.go b/services/images/service.go index fa8a00aae..3843df554 100644 --- a/services/images/service.go +++ b/services/images/service.go @@ -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)) } diff --git a/services/introspection/service.go b/services/introspection/service.go index 34c2307aa..001db8e53 100644 --- a/services/introspection/service.go +++ b/services/introspection/service.go @@ -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()) diff --git a/services/namespaces/service.go b/services/namespaces/service.go index c0f6eb733..b795ab52f 100644 --- a/services/namespaces/service.go +++ b/services/namespaces/service.go @@ -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)) } diff --git a/services/tasks/service.go b/services/tasks/service.go index 75904a98c..2c58c9d72 100644 --- a/services/tasks/service.go +++ b/services/tasks/service.go @@ -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) diff --git a/services/version/service.go b/services/version/service.go index b0e1ee6da..5a7454f24 100644 --- a/services/version/service.go +++ b/services/version/service.go @@ -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, diff --git a/windows/hcsshimtypes/doc.go b/windows/hcsshimtypes/doc.go index 1712b1aed..4b1b4b341 100644 --- a/windows/hcsshimtypes/doc.go +++ b/windows/hcsshimtypes/doc.go @@ -1,2 +1,2 @@ -// hcsshimtypes holds the windows runtime specific types +// Package hcsshimtypes holds the windows runtime specific types package hcsshimtypes From 5fd0415985f9f55c0cec2632b25cdf25b4670526 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 20 Oct 2017 11:46:19 -0400 Subject: [PATCH 2/2] Add comments and fix common lint issues Signed-off-by: Michael Crosby --- client.go | 1 + cmd/containerd/main.go | 4 ++-- linux/bundle.go | 17 +++++++++-------- metadata/content.go | 8 ++------ plugin/context.go | 6 ++++++ runtime/task.go | 14 ++++++++++++++ runtime/task_list.go | 11 ++++++++++- server/config.go | 8 ++++---- services/healthcheck/service.go | 5 ++--- snapshot/btrfs/btrfs.go | 4 ++-- snapshot/btrfs/btrfs_test.go | 10 ++++------ snapshot/overlay/overlay.go | 2 +- snapshot/storage/bolt.go | 2 +- task.go | 1 + testutil/loopback_linux.go | 5 +---- 15 files changed, 60 insertions(+), 38 deletions(-) diff --git a/client.go b/client.go index 6f0eb28a2..2e253a08d 100644 --- a/client.go +++ b/client.go @@ -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) } diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index eed4356b2..a6ca3d078 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -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") } diff --git a/linux/bundle.go b/linux/bundle.go index 3dbfef98d..29ab6ba5f 100644 --- a/linux/bundle.go +++ b/linux/bundle.go @@ -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) } diff --git a/metadata/content.go b/metadata/content.go index 05064fdec..293539aa1 100644 --- a/metadata/content.go +++ b/metadata/content.go @@ -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 + }) } diff --git a/plugin/context.go b/plugin/context.go index 7fff5c6c6..849b1cb0f 100644 --- a/plugin/context.go +++ b/plugin/context.go @@ -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 } diff --git a/runtime/task.go b/runtime/task.go index 019d4c8cf..4c02455dc 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -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 diff --git a/runtime/task_list.go b/runtime/task_list.go index 12062cef5..7c522655f 100644 --- a/runtime/task_list.go +++ b/runtime/task_list.go @@ -9,21 +9,26 @@ import ( ) var ( - ErrTaskNotExists = errors.New("task does not exist") + // ErrTaskNotExists is returned when a task does not exist + ErrTaskNotExists = errors.New("task does not exist") + // ErrTaskAlreadyExists is returned when a task already exists ErrTaskAlreadyExists = errors.New("task already exists") ) +// NewTaskList returns a new TaskList func NewTaskList() *TaskList { return &TaskList{ tasks: make(map[string]map[string]Task), } } +// TaskList holds and provides locking around tasks type TaskList struct { mu sync.Mutex tasks map[string]map[string]Task } +// Get a task func (l *TaskList) Get(ctx context.Context, id string) (Task, error) { l.mu.Lock() defer l.mu.Unlock() @@ -42,6 +47,7 @@ func (l *TaskList) Get(ctx context.Context, id string) (Task, error) { return t, nil } +// GetAll tasks under a namespace func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) { namespace, err := namespaces.NamespaceRequired(ctx) if err != nil { @@ -58,6 +64,7 @@ func (l *TaskList) GetAll(ctx context.Context) ([]Task, error) { return o, nil } +// Add a task func (l *TaskList) Add(ctx context.Context, t Task) error { namespace, err := namespaces.NamespaceRequired(ctx) if err != nil { @@ -66,6 +73,7 @@ func (l *TaskList) Add(ctx context.Context, t Task) error { return l.AddWithNamespace(namespace, t) } +// AddWithNamespace adds a task with the provided namespace func (l *TaskList) AddWithNamespace(namespace string, t Task) error { l.mu.Lock() defer l.mu.Unlock() @@ -81,6 +89,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error { return nil } +// Delete a task func (l *TaskList) Delete(ctx context.Context, t Task) { l.mu.Lock() defer l.mu.Unlock() diff --git a/server/config.go b/server/config.go index d6c2ca644..26af539ac 100644 --- a/server/config.go +++ b/server/config.go @@ -36,15 +36,15 @@ type Config struct { // GRPCConfig provides GRPC configuration for the socket type GRPCConfig struct { Address string `toml:"address"` - Uid int `toml:"uid"` - Gid int `toml:"gid"` + UID int `toml:"uid"` + GID int `toml:"gid"` } // Debug provides debug configuration type Debug struct { Address string `toml:"address"` - Uid int `toml:"uid"` - Gid int `toml:"gid"` + UID int `toml:"uid"` + GID int `toml:"gid"` Level string `toml:"level"` } diff --git a/services/healthcheck/service.go b/services/healthcheck/service.go index 85ffdab67..86c77e190 100644 --- a/services/healthcheck/service.go +++ b/services/healthcheck/service.go @@ -17,13 +17,12 @@ func init() { Type: plugin.GRPCPlugin, ID: "healthcheck", InitFn: func(*plugin.InitContext) (interface{}, error) { - return NewService() + return newService() }, }) } -// NewService returns the GRPC health server -func NewService() (*service, error) { +func newService() (*service, error) { return &service{ health.NewServer(), }, nil diff --git a/snapshot/btrfs/btrfs.go b/snapshot/btrfs/btrfs.go index 8bbe3fc80..32d66957e 100644 --- a/snapshot/btrfs/btrfs.go +++ b/snapshot/btrfs/btrfs.go @@ -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 } diff --git a/snapshot/btrfs/btrfs_test.go b/snapshot/btrfs/btrfs_test.go index 54ff402c5..63c9b02af 100644 --- a/snapshot/btrfs/btrfs_test.go +++ b/snapshot/btrfs/btrfs_test.go @@ -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 diff --git a/snapshot/overlay/overlay.go b/snapshot/overlay/overlay.go index c186c6ca7..8f0e0d09e 100644 --- a/snapshot/overlay/overlay.go +++ b/snapshot/overlay/overlay.go @@ -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 { diff --git a/snapshot/storage/bolt.go b/snapshot/storage/bolt.go index 3ca3b879c..63dc1743d 100644 --- a/snapshot/storage/bolt.go +++ b/snapshot/storage/bolt.go @@ -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)] diff --git a/task.go b/task.go index 6b9af1d41..b5f8450b3 100644 --- a/task.go +++ b/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 diff --git a/testutil/loopback_linux.go b/testutil/loopback_linux.go index 1639c20de..635a6c31a 100644 --- a/testutil/loopback_linux.go +++ b/testutil/loopback_linux.go @@ -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