X Tutup
Skip to content

Commit 451421b

Browse files
committed
Comment more packages to pass go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 33e974c commit 451421b

File tree

54 files changed

+255
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+255
-121
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor,
300300
m.Lock()
301301
manifestStack = append(manifestStack, desc)
302302
m.Unlock()
303-
return nil, images.StopHandler
303+
return nil, images.ErrStopHandler
304304
default:
305305
return nil, nil
306306
}

content/local/store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type store struct {
3636
root string
3737
}
3838

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

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

390390
func (s *store) ingestRoot(ref string) string {

design/snapshots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ We get back a list of mounts from `Snapshotter.Prepare`, with the `key`
137137
identifying the active snapshot. Mount this to the temporary location with the
138138
following:
139139

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

142142
Once the mounts are performed, our temporary location is ready to capture
143143
a diff. In practice, this works similar to a filesystem transaction. The

differ/differ.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func init() {
2525
plugin.Register(&plugin.Registration{
2626
Type: plugin.DiffPlugin,
2727
ID: "walking",
28-
Requires: []plugin.PluginType{
28+
Requires: []plugin.Type{
2929
plugin.ContentPlugin,
3030
plugin.MetadataPlugin,
3131
},
@@ -81,7 +81,7 @@ func (s *walkingDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
8181
}
8282
defer os.RemoveAll(dir)
8383

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

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

157-
if err := mount.MountAll(upper, bDir); err != nil {
157+
if err := mount.All(upper, bDir); err != nil {
158158
return emptyDesc, errors.Wrap(err, "failed to mount")
159159
}
160160
defer mount.Unmount(bDir, 0)

images/handlers.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ import (
1414
)
1515

1616
var (
17-
// SkipDesc is used to skip processing of a descriptor and
17+
// ErrSkipDesc is used to skip processing of a descriptor and
1818
// its descendants.
19-
SkipDesc = fmt.Errorf("skip descriptor")
19+
ErrSkipDesc = fmt.Errorf("skip descriptor")
2020

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

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

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

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

3841
// Handlers returns a handler that will run the handlers in sequence.
3942
//
40-
// A handler may return `StopHandler` to stop calling additional handlers
43+
// A handler may return `ErrStopHandler` to stop calling additional handlers
4144
func Handlers(handlers ...Handler) HandlerFunc {
4245
return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
4346
var children []ocispec.Descriptor
4447
for _, handler := range handlers {
4548
ch, err := handler.Handle(ctx, desc)
4649
if err != nil {
47-
if errors.Cause(err) == StopHandler {
50+
if errors.Cause(err) == ErrStopHandler {
4851
break
4952
}
5053
return nil, err
@@ -67,7 +70,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err
6770

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

105108
children, err := handler.Handle(ctx, desc)
106109
if err != nil {
107-
if errors.Cause(err) == SkipDesc {
110+
if errors.Cause(err) == ErrSkipDesc {
108111
return nil // don't traverse the children.
109112
}
110113
return err

images/image.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Image struct {
2121
CreatedAt, UpdatedAt time.Time
2222
}
2323

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

73+
// Manifest returns the manifest for an image.
7274
func Manifest(ctx context.Context, provider content.Provider, image ocispec.Descriptor, platform string) (ocispec.Manifest, error) {
7375
var (
7476
matcher platforms.Matcher
@@ -177,7 +179,7 @@ func Platforms(ctx context.Context, provider content.Provider, image ocispec.Des
177179
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
178180
if desc.Platform != nil {
179181
platformSpecs = append(platformSpecs, *desc.Platform)
180-
return nil, SkipDesc
182+
return nil, ErrSkipDesc
181183
}
182184

183185
switch desc.MediaType {

labels/validate.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ const (
99
maxSize = 4096
1010
)
1111

12+
// Validate a label's key and value are under 4096 bytes
1213
func Validate(k, v string) error {
13-
// A label key and value should be under 4096 bytes
1414
if (len(k) + len(v)) > maxSize {
1515
if len(k) > 10 {
1616
k = k[:10]
1717
}
18-
1918
return errors.Wrapf(errdefs.ErrInvalidArgument, "label key and value greater than maximum size (%d bytes), key: %s", maxSize, k)
2019
}
21-
2220
return nil
2321
}

linux/bundle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/pkg/errors"
1616
)
1717

18+
// loadBundle loads an existing bundle from disk
1819
func loadBundle(id, path, workdir string) *bundle {
1920
return &bundle{
2021
id: id,
@@ -71,19 +72,22 @@ type bundle struct {
7172

7273
type shimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
7374

75+
// ShimRemote is a shimOpt for connecting and starting a remote shim
7476
func ShimRemote(shim, daemonAddress, cgroup string, debug bool, exitHandler func()) shimOpt {
7577
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
7678
return b.shimConfig(ns, ropts),
7779
client.WithStart(shim, b.shimAddress(ns), daemonAddress, cgroup, debug, exitHandler)
7880
}
7981
}
8082

83+
// ShimLocal is a shimOpt for using an in process shim implementation
8184
func ShimLocal(exchange *events.Exchange) shimOpt {
8285
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
8386
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
8487
}
8588
}
8689

90+
// ShimConnect is a shimOpt for connecting to an existing remote shim
8791
func ShimConnect() shimOpt {
8892
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
8993
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))

linux/process.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ import (
1111
"github.com/containerd/containerd/runtime"
1212
)
1313

14+
// Process implements a linux process
1415
type Process struct {
1516
id string
1617
t *Task
1718
}
1819

20+
// ID of the process
1921
func (p *Process) ID() string {
2022
return p.id
2123
}
2224

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

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

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

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

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

108+
// Wait on the process to exit and return the exit status and timestamp
99109
func (p *Process) Wait(ctx context.Context) (*runtime.Exit, error) {
100110
r, err := p.t.shim.Wait(ctx, &shim.WaitRequest{
101111
ID: p.id,

linux/runtime.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func init() {
5252
Type: plugin.RuntimePlugin,
5353
ID: "linux",
5454
Init: New,
55-
Requires: []plugin.PluginType{
55+
Requires: []plugin.Type{
5656
plugin.TaskMonitorPlugin,
5757
plugin.MetadataPlugin,
5858
},
@@ -65,6 +65,7 @@ func init() {
6565

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

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

82+
// New returns a configured runtime
8183
func New(ic *plugin.InitContext) (interface{}, error) {
8284
if err := os.MkdirAll(ic.Root, 0711); err != nil {
8385
return nil, err
@@ -117,6 +119,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
117119
return r, nil
118120
}
119121

122+
// Runtime for a linux based system
120123
type Runtime struct {
121124
root string
122125
state string
@@ -130,10 +133,12 @@ type Runtime struct {
130133
config *Config
131134
}
132135

136+
// ID of the runtime
133137
func (r *Runtime) ID() string {
134138
return pluginID
135139
}
136140

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

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

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

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

492500
return ropts, nil
493501
}
494-
495502
return nil, nil
496503
}

0 commit comments

Comments
 (0)
X Tutup