Skip to content

Commit

Permalink
Comment more packages to pass go lint
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Oct 2, 2017
1 parent 33e974c commit 451421b
Show file tree
Hide file tree
Showing 54 changed files with 255 additions and 121 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor,
m.Lock()
manifestStack = append(manifestStack, desc)
m.Unlock()
return nil, images.StopHandler
return nil, images.ErrStopHandler
default:
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions content/local/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type store struct {
root string
}

// NewServer returns a local content store
// NewStore returns a local content store
func NewStore(root string) (content.Store, error) {
if err := os.MkdirAll(filepath.Join(root, "ingest"), 0777); err != nil && !os.IsExist(err) {
return nil, err
Expand Down Expand Up @@ -383,8 +383,8 @@ func (s *store) Abort(ctx context.Context, ref string) error {
return nil
}

func (cs *store) blobPath(dgst digest.Digest) string {
return filepath.Join(cs.root, "blobs", dgst.Algorithm().String(), dgst.Hex())
func (s *store) blobPath(dgst digest.Digest) string {
return filepath.Join(s.root, "blobs", dgst.Algorithm().String(), dgst.Hex())
}

func (s *store) ingestRoot(ref string) string {
Expand Down
2 changes: 1 addition & 1 deletion design/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ We get back a list of mounts from `Snapshotter.Prepare`, with the `key`
identifying the active snapshot. Mount this to the temporary location with the
following:

if err := MountAll(mounts, tmpDir); err != nil { ... }
if err := mount.All(mounts, tmpDir); err != nil { ... }

Once the mounts are performed, our temporary location is ready to capture
a diff. In practice, this works similar to a filesystem transaction. The
Expand Down
8 changes: 4 additions & 4 deletions differ/differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
plugin.Register(&plugin.Registration{
Type: plugin.DiffPlugin,
ID: "walking",
Requires: []plugin.PluginType{
Requires: []plugin.Type{
plugin.ContentPlugin,
plugin.MetadataPlugin,
},
Expand Down Expand Up @@ -81,7 +81,7 @@ func (s *walkingDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
}
defer os.RemoveAll(dir)

if err := mount.MountAll(mounts, dir); err != nil {
if err := mount.All(mounts, dir); err != nil {
return emptyDesc, errors.Wrap(err, "failed to mount")
}
defer mount.Unmount(dir, 0)
Expand Down Expand Up @@ -149,12 +149,12 @@ func (s *walkingDiff) DiffMounts(ctx context.Context, lower, upper []mount.Mount
}
defer os.RemoveAll(bDir)

if err := mount.MountAll(lower, aDir); err != nil {
if err := mount.All(lower, aDir); err != nil {
return emptyDesc, errors.Wrap(err, "failed to mount")
}
defer mount.Unmount(aDir, 0)

if err := mount.MountAll(upper, bDir); err != nil {
if err := mount.All(upper, bDir); err != nil {
return emptyDesc, errors.Wrap(err, "failed to mount")
}
defer mount.Unmount(bDir, 0)
Expand Down
21 changes: 12 additions & 9 deletions images/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,40 @@ import (
)

var (
// SkipDesc is used to skip processing of a descriptor and
// ErrSkipDesc is used to skip processing of a descriptor and
// its descendants.
SkipDesc = fmt.Errorf("skip descriptor")
ErrSkipDesc = fmt.Errorf("skip descriptor")

// StopHandler is used to signify that the descriptor
// ErrStopHandler is used to signify that the descriptor
// has been handled and should not be handled further.
// This applies only to a single descriptor in a handler
// chain and does not apply to descendant descriptors.
StopHandler = fmt.Errorf("stop handler")
ErrStopHandler = fmt.Errorf("stop handler")
)

// Handler handles image manifests
type Handler interface {
Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)
}

// HandlerFunc function implementing the Handler interface
type HandlerFunc func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error)

// Handle image manifests
func (fn HandlerFunc) Handle(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
return fn(ctx, desc)
}

// Handlers returns a handler that will run the handlers in sequence.
//
// A handler may return `StopHandler` to stop calling additional handlers
// A handler may return `ErrStopHandler` to stop calling additional handlers
func Handlers(handlers ...Handler) HandlerFunc {
return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
var children []ocispec.Descriptor
for _, handler := range handlers {
ch, err := handler.Handle(ctx, desc)
if err != nil {
if errors.Cause(err) == StopHandler {
if errors.Cause(err) == ErrStopHandler {
break
}
return nil, err
Expand All @@ -67,7 +70,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err

children, err := handler.Handle(ctx, desc)
if err != nil {
if errors.Cause(err) == SkipDesc {
if errors.Cause(err) == ErrSkipDesc {
continue // don't traverse the children.
}
return err
Expand All @@ -87,7 +90,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err
// If the handler decode subresources, they will be visited, as well.
//
// Handlers for siblings are run in parallel on the provided descriptors. A
// handler may return `SkipDesc` to signal to the dispatcher to not traverse
// handler may return `ErrSkipDesc` to signal to the dispatcher to not traverse
// any children.
//
// Typically, this function will be used with `FetchHandler`, often composed
Expand All @@ -104,7 +107,7 @@ func Dispatch(ctx context.Context, handler Handler, descs ...ocispec.Descriptor)

children, err := handler.Handle(ctx, desc)
if err != nil {
if errors.Cause(err) == SkipDesc {
if errors.Cause(err) == ErrSkipDesc {
return nil // don't traverse the children.
}
return err
Expand Down
4 changes: 3 additions & 1 deletion images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Image struct {
CreatedAt, UpdatedAt time.Time
}

// Store and interact with images
type Store interface {
Get(ctx context.Context, name string) (Image, error)
List(ctx context.Context, filters ...string) ([]Image, error)
Expand Down Expand Up @@ -69,6 +70,7 @@ func (image *Image) Size(ctx context.Context, provider content.Provider, platfor
}), ChildrenHandler(provider, platform)), image.Target)
}

// Manifest returns the manifest for an image.
func Manifest(ctx context.Context, provider content.Provider, image ocispec.Descriptor, platform string) (ocispec.Manifest, error) {
var (
matcher platforms.Matcher
Expand Down Expand Up @@ -177,7 +179,7 @@ func Platforms(ctx context.Context, provider content.Provider, image ocispec.Des
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
if desc.Platform != nil {
platformSpecs = append(platformSpecs, *desc.Platform)
return nil, SkipDesc
return nil, ErrSkipDesc
}

switch desc.MediaType {
Expand Down
4 changes: 1 addition & 3 deletions labels/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ const (
maxSize = 4096
)

// Validate a label's key and value are under 4096 bytes
func Validate(k, v string) error {
// A label key and value should be under 4096 bytes
if (len(k) + len(v)) > maxSize {
if len(k) > 10 {
k = k[:10]
}

return errors.Wrapf(errdefs.ErrInvalidArgument, "label key and value greater than maximum size (%d bytes), key: %s", maxSize, k)
}

return nil
}
4 changes: 4 additions & 0 deletions linux/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
)

// loadBundle loads an existing bundle from disk
func loadBundle(id, path, workdir string) *bundle {
return &bundle{
id: id,
Expand Down Expand Up @@ -71,19 +72,22 @@ type bundle struct {

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, 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, debug, exitHandler)
}
}

// 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 {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
Expand Down
10 changes: 10 additions & 0 deletions linux/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ import (
"github.com/containerd/containerd/runtime"
)

// Process implements a linux process
type Process struct {
id string
t *Task
}

// ID of the process
func (p *Process) ID() string {
return p.id
}

// Kill sends the provided signal to the underlying process
//
// Unable to kill all processes in the task using this method on a process
func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
_, err := p.t.shim.Kill(ctx, &shim.KillRequest{
Signal: signal,
Expand All @@ -31,6 +36,7 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
return err
}

// State of process
func (p *Process) State(ctx context.Context) (runtime.State, error) {
// use the container status for the status of the process
response, err := p.t.shim.State(ctx, &shim.StateRequest{
Expand Down Expand Up @@ -63,6 +69,7 @@ func (p *Process) State(ctx context.Context) (runtime.State, error) {
}, nil
}

// ResizePty changes the side of the process's PTY to the provided width and height
func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
_, err := p.t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
ID: p.id,
Expand All @@ -75,6 +82,7 @@ func (p *Process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error
return err
}

// CloseIO closes the provided IO pipe for the process
func (p *Process) CloseIO(ctx context.Context) error {
_, err := p.t.shim.CloseIO(ctx, &shim.CloseIORequest{
ID: p.id,
Expand All @@ -86,6 +94,7 @@ func (p *Process) CloseIO(ctx context.Context) error {
return nil
}

// Start the process
func (p *Process) Start(ctx context.Context) error {
_, err := p.t.shim.Start(ctx, &shim.StartRequest{
ID: p.id,
Expand All @@ -96,6 +105,7 @@ func (p *Process) Start(ctx context.Context) error {
return nil
}

// Wait on the process to exit and return the exit status and timestamp
func (p *Process) Wait(ctx context.Context) (*runtime.Exit, error) {
r, err := p.t.shim.Wait(ctx, &shim.WaitRequest{
ID: p.id,
Expand Down
11 changes: 9 additions & 2 deletions linux/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
Type: plugin.RuntimePlugin,
ID: "linux",
Init: New,
Requires: []plugin.PluginType{
Requires: []plugin.Type{
plugin.TaskMonitorPlugin,
plugin.MetadataPlugin,
},
Expand All @@ -65,6 +65,7 @@ func init() {

var _ = (runtime.Runtime)(&Runtime{})

// Config options for the runtime
type Config struct {
// Shim is a path or name of binary implementing the Shim GRPC API
Shim string `toml:"shim"`
Expand All @@ -78,6 +79,7 @@ type Config struct {
ShimDebug bool `toml:"shim_debug"`
}

// New returns a configured runtime
func New(ic *plugin.InitContext) (interface{}, error) {
if err := os.MkdirAll(ic.Root, 0711); err != nil {
return nil, err
Expand Down Expand Up @@ -117,6 +119,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
return r, nil
}

// Runtime for a linux based system
type Runtime struct {
root string
state string
Expand All @@ -130,10 +133,12 @@ type Runtime struct {
config *Config
}

// ID of the runtime
func (r *Runtime) ID() string {
return pluginID
}

// Create a new task
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (_ runtime.Task, err error) {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
Expand Down Expand Up @@ -265,6 +270,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
return t, nil
}

// Delete a task removing all on disk state
func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, error) {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
Expand Down Expand Up @@ -305,6 +311,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
}, nil
}

// Tasks returns all tasks known to the runtime
func (r *Runtime) Tasks(ctx context.Context) ([]runtime.Task, error) {
return r.tasks.GetAll(ctx)
}
Expand All @@ -330,6 +337,7 @@ func (r *Runtime) restoreTasks(ctx context.Context) ([]*Task, error) {
return o, nil
}

// Get a specific task by task id
func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
return r.tasks.Get(ctx, id)
}
Expand Down Expand Up @@ -491,6 +499,5 @@ func (r *Runtime) getRuncOptions(ctx context.Context, id string) (*runcopts.Runc

return ropts, nil
}

return nil, nil
}
4 changes: 4 additions & 0 deletions linux/shim/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/grpc"
)

// ClientOpt is an option for a shim client configuration
type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error)

// WithStart executes a new shim process
Expand Down Expand Up @@ -180,6 +181,7 @@ func WithLocal(publisher events.Publisher) func(context.Context, Config) (shim.S
}
}

// Config contains shim specific configuration
type Config struct {
Path string
Namespace string
Expand All @@ -202,6 +204,7 @@ func New(ctx context.Context, config Config, opt ClientOpt) (*Client, error) {
}, nil
}

// Client is a shim client containing the connection to a shim
type Client struct {
shim.ShimClient

Expand Down Expand Up @@ -233,6 +236,7 @@ func (c *Client) KillShim(ctx context.Context) error {
return c.signalShim(ctx, unix.SIGKILL)
}

// Close the cient connection
func (c *Client) Close() error {
if c.c == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions linux/shim/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pkg/errors"
)

// InitPidFile name of the file that contains the init pid
const InitPidFile = "init.pid"

type initProcess struct {
Expand Down
Loading

0 comments on commit 451421b

Please sign in to comment.