diff --git a/archive/tar.go b/archive/tar.go index 47111b027f5a..02fb0940be9c 100644 --- a/archive/tar.go +++ b/archive/tar.go @@ -522,9 +522,5 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header return err } - if err := chtimes(path, boundTime(latestTime(hdr.AccessTime, hdr.ModTime)), boundTime(hdr.ModTime)); err != nil { - return err - } - - return nil + return chtimes(path, boundTime(latestTime(hdr.AccessTime, hdr.ModTime)), boundTime(hdr.ModTime)) } diff --git a/archive/tar_test.go b/archive/tar_test.go index 67dc8a02a7d2..6c3ae699b33e 100644 --- a/archive/tar_test.go +++ b/archive/tar_test.go @@ -167,7 +167,7 @@ func TestSymlinks(t *testing.T) { } func TestBreakouts(t *testing.T) { - tc := TarContext{}.WithUidGid(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()) + tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()) expected := "unbroken" unbrokenCheck := func(root string) error { b, err := ioutil.ReadFile(filepath.Join(root, "etc", "unbroken")) @@ -480,7 +480,7 @@ func TestDiffApply(t *testing.T) { } func TestApplyTar(t *testing.T) { - tc := TarContext{}.WithUidGid(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()) + tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()) directoriesExist := func(dirs ...string) func(string) error { return func(root string) error { for _, d := range dirs { @@ -767,8 +767,8 @@ func TarFromWriterTo(wt WriterToTar) io.ReadCloser { // TarContext is used to create tar records type TarContext struct { - Uid int - Gid int + UID int + GID int // ModTime sets the modtimes for all files, if nil the current time // is used for each file when it was written @@ -784,8 +784,8 @@ func (tc TarContext) newHeader(mode os.FileMode, name, link string, size int64) size: size, modt: tc.ModTime, hdr: &tar.Header{ - Uid: tc.Uid, - Gid: tc.Gid, + Uid: tc.UID, + Gid: tc.GID, Xattrs: tc.Xattrs, }, } @@ -837,10 +837,10 @@ func (ti tarInfo) Sys() interface{} { return ti.hdr } -func (tc TarContext) WithUidGid(uid, gid int) TarContext { +func (tc TarContext) WithUIDGID(uid, gid int) TarContext { ntc := tc - ntc.Uid = uid - ntc.Gid = gid + ntc.UID = uid + ntc.GID = gid return ntc } diff --git a/cmd/containerd-shim/shim_linux.go b/cmd/containerd-shim/shim_linux.go index 7d6229621b83..0b5c9a38462f 100644 --- a/cmd/containerd-shim/shim_linux.go +++ b/cmd/containerd-shim/shim_linux.go @@ -42,6 +42,7 @@ type unixSocketCredentials struct { serverName string } +// NewUnixSocketCredentials returns TransportCredentials for a local unix socket func NewUnixSocketCredentials(uid, gid int) credentials.TransportCredentials { return &unixSocketCredentials{uid, gid, "locahost"} } diff --git a/cmd/ctr/namespaces.go b/cmd/ctr/namespaces.go index 23923771f19d..7b096641afe4 100644 --- a/cmd/ctr/namespaces.go +++ b/cmd/ctr/namespaces.go @@ -44,12 +44,7 @@ var namespacesCreateCommand = cli.Command{ if err != nil { return err } - - if err := namespaces.Create(ctx, namespace, labels); err != nil { - return err - } - - return nil + return namespaces.Create(ctx, namespace, labels) }, } diff --git a/cmd/ctr/ps.go b/cmd/ctr/ps.go index c0a3f354a4c2..e5a668f9e256 100644 --- a/cmd/ctr/ps.go +++ b/cmd/ctr/ps.go @@ -47,9 +47,6 @@ var taskPsCommand = cli.Command{ return err } } - if err := w.Flush(); err != nil { - return err - } - return nil + return w.Flush() }, } diff --git a/containers/containers.go b/containers/containers.go index 1ea593bdfe67..df4ad83c9ebf 100644 --- a/containers/containers.go +++ b/containers/containers.go @@ -62,11 +62,13 @@ type Container struct { Extensions map[string]types.Any } +// RuntimeInfo holds runtime specific information type RuntimeInfo struct { Name string Options *types.Any } +// Store interacts with the underlying container storage type Store interface { Get(ctx context.Context, id string) (Container, error) diff --git a/content/content.go b/content/content.go index 6dce8b2e7493..6770b3464d34 100644 --- a/content/content.go +++ b/content/content.go @@ -8,20 +8,25 @@ import ( "github.com/opencontainers/go-digest" ) +// ReaderAt extends the standard io.ReaderAt interface with reporting of Size and io.Closer type ReaderAt interface { io.ReaderAt io.Closer Size() int64 } +// Provider provides a reader interface for specific content type Provider interface { ReaderAt(ctx context.Context, dgst digest.Digest) (ReaderAt, error) } +// Ingester writes content type Ingester interface { Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (Writer, error) } +// Info holds content specific information +// // TODO(stevvooe): Consider a very different name for this struct. Info is way // to general. It also reads very weird in certain context, like pluralization. type Info struct { @@ -32,6 +37,7 @@ type Info struct { Labels map[string]string } +// Status of a content operation type Status struct { Ref string Offset int64 @@ -81,6 +87,7 @@ type IngestManager interface { Abort(ctx context.Context, ref string) error } +// Writer handles the write of content into a content store type Writer interface { // Close is expected to be called after Commit() when commission is needed. io.WriteCloser @@ -111,6 +118,7 @@ type Store interface { // Opt is used to alter the mutable properties of content type Opt func(*Info) error +// WithLabels allows labels to be set on content func WithLabels(labels map[string]string) Opt { return func(info *Info) error { info.Labels = labels diff --git a/content/helpers.go b/content/helpers.go index b6d21ccbd57a..1c1087057c94 100644 --- a/content/helpers.go +++ b/content/helpers.go @@ -19,6 +19,7 @@ var ( } ) +// NewReader returns a io.Reader from a ReaderAt func NewReader(ra ReaderAt) io.Reader { rd := io.NewSectionReader(ra, 0, ra.Size()) return rd diff --git a/content/local/store.go b/content/local/store.go index f977e5ba90c1..a3483fa7704f 100644 --- a/content/local/store.go +++ b/content/local/store.go @@ -36,6 +36,7 @@ type store struct { root string } +// NewServer 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 @@ -97,8 +98,8 @@ func (s *store) ReaderAt(ctx context.Context, dgst digest.Digest) (content.Reade // // While this is safe to do concurrently, safe exist-removal logic must hold // some global lock on the store. -func (cs *store) Delete(ctx context.Context, dgst digest.Digest) error { - if err := os.RemoveAll(cs.blobPath(dgst)); err != nil { +func (s *store) Delete(ctx context.Context, dgst digest.Digest) error { + if err := os.RemoveAll(s.blobPath(dgst)); err != nil { if !os.IsNotExist(err) { return err } @@ -109,14 +110,14 @@ func (cs *store) Delete(ctx context.Context, dgst digest.Digest) error { return nil } -func (cs *store) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) { +func (s *store) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) { // TODO: Support persisting and updating mutable content data return content.Info{}, errors.Wrapf(errdefs.ErrFailedPrecondition, "update not supported on immutable content store") } -func (cs *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error { +func (s *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error { // TODO: Support filters - root := filepath.Join(cs.root, "blobs") + root := filepath.Join(s.root, "blobs") var alg digest.Algorithm return filepath.Walk(root, func(path string, fi os.FileInfo, err error) error { if err != nil { @@ -153,7 +154,7 @@ func (cs *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...strin // store or extra paths not expected previously. } - return fn(cs.info(dgst, fi)) + return fn(s.info(dgst, fi)) }) } diff --git a/errdefs/errors.go b/errdefs/errors.go index 44ec72e7b9e8..b4d6ea860b04 100644 --- a/errdefs/errors.go +++ b/errdefs/errors.go @@ -29,6 +29,7 @@ var ( ErrNotImplemented = errors.New("not implemented") // represents not supported and unimplemented ) +// IsInvalidArgument returns true if the error is due to an invalid argument func IsInvalidArgument(err error) bool { return errors.Cause(err) == ErrInvalidArgument } @@ -45,15 +46,17 @@ func IsAlreadyExists(err error) bool { } // IsFailedPrecondition returns true if an operation could not proceed to the -// lack of a particular condition. +// lack of a particular condition func IsFailedPrecondition(err error) bool { return errors.Cause(err) == ErrFailedPrecondition } +// IsUnavailable returns true if the error is due to a resource being unavailable func IsUnavailable(err error) bool { return errors.Cause(err) == ErrUnavailable } +// IsNotImplemented returns true if the error is due to not being implemented func IsNotImplemented(err error) bool { return errors.Cause(err) == ErrNotImplemented } diff --git a/errdefs/grpc.go b/errdefs/grpc.go index 76fb3eb3fc37..29394534826c 100644 --- a/errdefs/grpc.go +++ b/errdefs/grpc.go @@ -53,6 +53,7 @@ func ToGRPCf(err error, format string, args ...interface{}) error { return ToGRPC(errors.Wrapf(err, format, args...)) } +// FromGRPC returns the underlying error from a grpc service based on the grpc error code func FromGRPC(err error) error { if err == nil { return nil diff --git a/events/events.go b/events/events.go index 1ae0fc88074c..efe2f598b92b 100644 --- a/events/events.go +++ b/events/events.go @@ -6,6 +6,7 @@ import ( events "github.com/containerd/containerd/api/services/events/v1" ) +// Event is a generic interface for any type of event type Event interface{} // Publisher posts the event. @@ -13,6 +14,7 @@ type Publisher interface { Publish(ctx context.Context, topic string, event Event) error } +// Forwarder forwards an event to the underlying event bus type Forwarder interface { Forward(ctx context.Context, envelope *events.Envelope) error } @@ -23,6 +25,7 @@ func (fn publisherFunc) Publish(ctx context.Context, topic string, event Event) return fn(ctx, topic, event) } +// Subscriber allows callers to subscribe to events type Subscriber interface { Subscribe(ctx context.Context, filters ...string) (ch <-chan *events.Envelope, errs <-chan error) } diff --git a/events/exchange.go b/events/exchange.go index 0c8e60f0e70a..eeeeea36222b 100644 --- a/events/exchange.go +++ b/events/exchange.go @@ -18,10 +18,12 @@ import ( "github.com/sirupsen/logrus" ) +// Exchange broadcasts events type Exchange struct { broadcaster *goevents.Broadcaster } +// NewExchange returns a new event Exchange func NewExchange() *Exchange { return &Exchange{ broadcaster: goevents.NewBroadcaster(), diff --git a/filters/adaptor.go b/filters/adaptor.go index 27465afd89bb..5a5ac7ec1340 100644 --- a/filters/adaptor.go +++ b/filters/adaptor.go @@ -8,8 +8,10 @@ type Adaptor interface { Field(fieldpath []string) (value string, present bool) } +// AdapterFunc allows implementation specific matching of fieldpaths type AdapterFunc func(fieldpath []string) (string, bool) +// Field returns the field name and true if it exists func (fn AdapterFunc) Field(fieldpath []string) (string, bool) { return fn(fieldpath) } diff --git a/filters/filter.go b/filters/filter.go index 2c9c3d702292..621755762d5b 100644 --- a/filters/filter.go +++ b/filters/filter.go @@ -58,22 +58,28 @@ import ( "github.com/containerd/containerd/log" ) +// Filter matches specific resources based the provided filter type Filter interface { Match(adaptor Adaptor) bool } +// FilterFunc is a function that handles matching with an adaptor type FilterFunc func(Adaptor) bool +// Match matches the FilterFunc returning true if the object matches the filter func (fn FilterFunc) Match(adaptor Adaptor) bool { return fn(adaptor) } +// Always is a filter that always returns true for any type of object var Always FilterFunc = func(adaptor Adaptor) bool { return true } +// Any allows multiple filters to be matched aginst the object type Any []Filter +// Match returns true if any of the provided filters are true func (m Any) Match(adaptor Adaptor) bool { for _, m := range m { if m.Match(adaptor) { @@ -84,8 +90,10 @@ func (m Any) Match(adaptor Adaptor) bool { return false } +// All allows multiple filters to be matched aginst the object type All []Filter +// Match only returns true if all filters match the object func (m All) Match(adaptor Adaptor) bool { for _, m := range m { if !m.Match(adaptor) { diff --git a/filters/filter_test.go b/filters/filter_test.go index f2e32cce840e..e166ed916148 100644 --- a/filters/filter_test.go +++ b/filters/filter_test.go @@ -243,10 +243,9 @@ func TestFilters(t *testing.T) { } return - } else { - if err != nil { - t.Fatal(err) - } + } + if err != nil { + t.Fatal(err) } if filter == nil { diff --git a/filters/scanner.go b/filters/scanner.go index 9c3fe2b756d2..5a55e0abf9d3 100644 --- a/filters/scanner.go +++ b/filters/scanner.go @@ -67,9 +67,8 @@ func (s *scanner) next() rune { if r == utf8.RuneError { if w > 0 { return tokenIllegal - } else { - return tokenEOF } + return tokenEOF } if r == 0 { diff --git a/fs/du.go b/fs/du.go index 8dfdaebdae8b..61f439d3970f 100644 --- a/fs/du.go +++ b/fs/du.go @@ -1,5 +1,6 @@ package fs +// Usage of disk information type Usage struct { Inodes int64 Size int64 diff --git a/fs/fstest/file.go b/fs/fstest/file.go index 02b4ebd0fe34..48544c9785c5 100644 --- a/fs/fstest/file.go +++ b/fs/fstest/file.go @@ -26,12 +26,7 @@ func CreateFile(name string, content []byte, perm os.FileMode) Applier { if err := ioutil.WriteFile(fullPath, content, perm); err != nil { return err } - - if err := os.Chmod(fullPath, perm); err != nil { - return err - } - - return nil + return os.Chmod(fullPath, perm) }) } diff --git a/fs/fstest/file_unix.go b/fs/fstest/file_unix.go index ee303215aeb8..2df4a1b6dafe 100644 --- a/fs/fstest/file_unix.go +++ b/fs/fstest/file_unix.go @@ -4,6 +4,7 @@ package fstest import "github.com/containerd/continuity/sysx" +// SetXAttr sets the xatter for the file func SetXAttr(name, key, value string) Applier { return applyFn(func(root string) error { return sysx.LSetxattr(name, key, []byte(value), 0) diff --git a/fs/fstest/testsuite.go b/fs/fstest/testsuite.go index 372d76f08f19..f0faa3448e38 100644 --- a/fs/fstest/testsuite.go +++ b/fs/fstest/testsuite.go @@ -7,11 +7,13 @@ import ( "testing" ) +// TestApplier applies the test context type TestApplier interface { TestContext(context.Context) (context.Context, func(), error) Apply(context.Context, Applier) (string, func(), error) } +// FSSuite runs the path test suite func FSSuite(t *testing.T, a TestApplier) { t.Run("Basic", makeTest(t, a, basicTest)) t.Run("Deletion", makeTest(t, a, deletionTest)) diff --git a/fs/hardlink.go b/fs/hardlink.go index 4d5156f400a6..38da93813ce8 100644 --- a/fs/hardlink.go +++ b/fs/hardlink.go @@ -2,7 +2,7 @@ package fs import "os" -// GetLinkID returns an identifier representing the node a hardlink is pointing +// GetLinkInfo returns an identifier representing the node a hardlink is pointing // to. If the file is not hard linked then 0 will be returned. func GetLinkInfo(fi os.FileInfo) (uint64, bool) { return getLinkInfo(fi)