Cleanup image operations.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-08-30 07:34:00 +00:00
parent 39854b292a
commit ac4f238f48
13 changed files with 96 additions and 85 deletions

View File

@@ -192,6 +192,11 @@ For sync communication we have a community slack with a #containerd channel that
**Slack:** https://dockr.ly/community
### Reporting security issues
__If you are reporting a security issue, please follow the responsible
disclosure guidelines and reach out discreetly at containerd-security@googlegroups.com__.
## Copyright and license
Copyright ©2016-2017 Docker, Inc. All rights reserved, except as follows. Code

View File

@@ -1,18 +0,0 @@
// +build linux
package containerd
import (
"context"
"github.com/containerd/containerd/containers"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
// WithApparmor sets the provided apparmor profile to the spec
func WithApparmorProfile(profile string) SpecOpts {
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {
s.Process.ApparmorProfile = profile
return nil
}
}

View File

@@ -5,6 +5,8 @@ import (
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/typeurl"
"github.com/gogo/protobuf/types"
"github.com/opencontainers/image-spec/identity"
"github.com/pkg/errors"
)
@@ -14,10 +16,21 @@ type NewContainerOpts func(ctx context.Context, client *Client, c *containers.Co
// WithRuntime allows a user to specify the runtime name and additional options that should
// be used to create tasks for the container
func WithRuntime(name string) NewContainerOpts {
func WithRuntime(name string, options interface{}) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
var (
any *types.Any
err error
)
if options != nil {
any, err = typeurl.MarshalAny(options)
if err != nil {
return err
}
}
c.Runtime = containers.RuntimeInfo{
Name: name,
Name: name,
Options: any,
}
return nil
}

View File

@@ -185,11 +185,11 @@ func validateTopic(topic string) error {
}
if topic[0] != '/' {
return errors.Wrapf(errdefs.ErrInvalidArgument, "must start with '/'", topic)
return errors.Wrapf(errdefs.ErrInvalidArgument, "must start with '/'")
}
if len(topic) == 1 {
return errors.Wrapf(errdefs.ErrInvalidArgument, "must have at least one component", topic)
return errors.Wrapf(errdefs.ErrInvalidArgument, "must have at least one component")
}
components := strings.Split(topic[1:], "/")

View File

@@ -20,10 +20,12 @@ type Image interface {
Target() ocispec.Descriptor
// Unpack unpacks the image's content into a snapshot
Unpack(context.Context, string) error
// RootFS returns the image digests
// RootFS returns the unpacked diffids that make up images rootfs.
RootFS(ctx context.Context) ([]digest.Digest, error)
// Size returns the image size
// Size returns the total size of the image's packed resources.
Size(ctx context.Context) (int64, error)
// Config descriptor for the image.
Config(ctx context.Context) (ocispec.Descriptor, error)
}
var _ = (Image)(&image{})
@@ -52,6 +54,11 @@ func (i *image) Size(ctx context.Context) (int64, error) {
return i.i.Size(ctx, provider)
}
func (i *image) Config(ctx context.Context) (ocispec.Descriptor, error) {
provider := i.client.ContentStore()
return i.i.Config(ctx, provider)
}
func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
layers, err := i.getLayers(ctx)
if err != nil {

View File

@@ -7,7 +7,9 @@ const (
TaskExitEventTopic = "/tasks/exit"
TaskDeleteEventTopic = "/tasks/delete"
TaskExecAddedEventTopic = "/tasks/exec-added"
TaskExecStartedEventTopic = "/tasks/exec-started"
TaskPausedEventTopic = "/tasks/paused"
TaskResumedEventTopic = "/tasks/resumed"
TaskCheckpointedEventTopic = "/tasks/checkpointed"
TaskUnknownTopic = "/tasks/?"
)

View File

@@ -2,10 +2,10 @@ package runtime
import (
"context"
"errors"
"sync"
"github.com/containerd/containerd/namespaces"
"github.com/pkg/errors"
)
var (
@@ -75,7 +75,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
l.tasks[namespace] = make(map[string]Task)
}
if _, ok := l.tasks[namespace][id]; ok {
return ErrTaskAlreadyExists
return errors.Wrap(ErrTaskAlreadyExists, id)
}
l.tasks[namespace][id] = t
return nil

View File

@@ -34,8 +34,9 @@ golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
github.com/BurntSushi/toml v0.2.0-21-g9906417
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
github.com/Microsoft/go-winio v0.4.4
github.com/Microsoft/hcsshim v0.6.3
github.com/Microsoft/opengcs v0.3.2
github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd
github.com/Microsoft/hcsshim v0.6.1
github.com/Azure/go-ansiterm 19f72df4d05d31cbe1c56bfc8045c96babff6c7e
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4