Merge pull request #454 from Random-Liu/revert-453

Revert "Add gc.root back in vendored containerd client."
This commit is contained in:
Lantao Liu 2017-12-01 12:19:23 -08:00 committed by GitHub
commit cad87243e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 93 deletions

View File

@ -238,7 +238,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
handler = images.Handlers(append(pullCtx.BaseHandlers, schema1Converter)...) handler = images.Handlers(append(pullCtx.BaseHandlers, schema1Converter)...)
} else { } else {
handler = images.Handlers(append(pullCtx.BaseHandlers, handler = images.Handlers(append(pullCtx.BaseHandlers,
remotes.FetchHandler(store, fetcher, desc), remotes.FetchHandler(store, fetcher),
images.ChildrenHandler(store, platforms.Default()))..., images.ChildrenHandler(store, platforms.Default()))...,
) )
} }
@ -275,11 +275,6 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
imgrec = created imgrec = created
} }
// Remove root tag from manifest now that image refers to it
if _, err := store.Update(ctx, content.Info{Digest: desc.Digest}, "labels.containerd.io/gc.root"); err != nil {
return nil, errors.Wrap(err, "failed to remove manifest root tag")
}
img := &image{ img := &image{
client: c, client: c,
i: imgrec, i: imgrec,

View File

@ -2,13 +2,11 @@ package containerd
import ( import (
"context" "context"
"time"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/gogo/protobuf/types" "github.com/gogo/protobuf/types"
"github.com/opencontainers/image-spec/identity" "github.com/opencontainers/image-spec/identity"
@ -95,11 +93,8 @@ func WithNewSnapshot(id string, i Image) NewContainerOpts {
return err return err
} }
setSnapshotterIfEmpty(c) setSnapshotterIfEmpty(c)
labels := map[string]string{
"containerd.io/gc.root": time.Now().String(),
}
parent := identity.ChainID(diffIDs).String() parent := identity.ChainID(diffIDs).String()
if _, err := client.SnapshotService(c.Snapshotter).Prepare(ctx, id, parent, snapshots.WithLabels(labels)); err != nil { if _, err := client.SnapshotService(c.Snapshotter).Prepare(ctx, id, parent); err != nil {
return err return err
} }
c.SnapshotKey = id c.SnapshotKey = id
@ -128,11 +123,8 @@ func WithNewSnapshotView(id string, i Image) NewContainerOpts {
return err return err
} }
setSnapshotterIfEmpty(c) setSnapshotterIfEmpty(c)
labels := map[string]string{
"containerd.io/gc.root": time.Now().String(),
}
parent := identity.ChainID(diffIDs).String() parent := identity.ChainID(diffIDs).String()
if _, err := client.SnapshotService(c.Snapshotter).View(ctx, id, parent, snapshots.WithLabels(labels)); err != nil { if _, err := client.SnapshotService(c.Snapshotter).View(ctx, id, parent); err != nil {
return err return err
} }
c.SnapshotKey = id c.SnapshotKey = id

View File

@ -10,7 +10,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"time"
"github.com/containerd/containerd/api/types" "github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
@ -19,7 +18,6 @@ import (
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/snapshots"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types" protobuf "github.com/gogo/protobuf/types"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
@ -155,12 +153,9 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool
snapshotter = client.SnapshotService(c.Snapshotter) snapshotter = client.SnapshotService(c.Snapshotter)
parent = identity.ChainID(diffIDs).String() parent = identity.ChainID(diffIDs).String()
usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid) usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid)
opt = snapshots.WithLabels(map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
})
) )
if _, err := snapshotter.Stat(ctx, usernsID); err == nil { if _, err := snapshotter.Stat(ctx, usernsID); err == nil {
if _, err := snapshotter.Prepare(ctx, id, usernsID, opt); err == nil { if _, err := snapshotter.Prepare(ctx, id, usernsID); err == nil {
c.SnapshotKey = id c.SnapshotKey = id
c.Image = i.Name() c.Image = i.Name()
return nil return nil
@ -168,7 +163,7 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool
return err return err
} }
} }
mounts, err := snapshotter.Prepare(ctx, usernsID+"-remap", parent, opt) mounts, err := snapshotter.Prepare(ctx, usernsID+"-remap", parent)
if err != nil { if err != nil {
return err return err
} }
@ -176,13 +171,13 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool
snapshotter.Remove(ctx, usernsID) snapshotter.Remove(ctx, usernsID)
return err return err
} }
if err := snapshotter.Commit(ctx, usernsID, usernsID+"-remap", opt); err != nil { if err := snapshotter.Commit(ctx, usernsID, usernsID+"-remap"); err != nil {
return err return err
} }
if readonly { if readonly {
_, err = snapshotter.View(ctx, id, usernsID, opt) _, err = snapshotter.View(ctx, id, usernsID)
} else { } else {
_, err = snapshotter.Prepare(ctx, id, usernsID, opt) _, err = snapshotter.Prepare(ctx, id, usernsID)
} }
if err != nil { if err != nil {
return err return err

View File

@ -3,7 +3,6 @@ package containerd
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
@ -110,27 +109,14 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
) )
for _, layer := range layers { for _, layer := range layers {
labels := map[string]string{ labels := map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
"containerd.io/uncompressed": layer.Diff.Digest.String(), "containerd.io/uncompressed": layer.Diff.Digest.String(),
} }
lastUnpacked := unpacked
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a, snapshots.WithLabels(labels)) unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a, snapshots.WithLabels(labels))
if err != nil { if err != nil {
return err return err
} }
if lastUnpacked {
info := snapshots.Info{
Name: identity.ChainID(chain).String(),
}
// Remove previously created gc.root label
if _, err := sn.Update(ctx, info, "labels.containerd.io/gc.root"); err != nil {
return err
}
}
chain = append(chain, layer.Diff.Digest) chain = append(chain, layer.Diff.Digest)
} }
@ -151,15 +137,6 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
if _, err := cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName)); err != nil { if _, err := cs.Update(ctx, cinfo, fmt.Sprintf("labels.containerd.io/gc.ref.snapshot.%s", snapshotterName)); err != nil {
return err return err
} }
sinfo := snapshots.Info{
Name: rootfs,
}
// Config now referenced snapshot, release root reference
if _, err := sn.Update(ctx, sinfo, "labels.containerd.io/gc.root"); err != nil {
return err
}
} }
return nil return nil

View File

@ -157,7 +157,6 @@ func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
} }
labels := map[string]string{} labels := map[string]string{}
labels["containerd.io/gc.root"] = time.Now().UTC().Format(time.RFC3339)
labels["containerd.io/gc.ref.content.0"] = manifest.Config.Digest.String() labels["containerd.io/gc.ref.content.0"] = manifest.Config.Digest.String()
for i, ch := range manifest.Layers { for i, ch := range manifest.Layers {
labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i+1)] = ch.Digest.String() labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i+1)] = ch.Digest.String()
@ -173,12 +172,6 @@ func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
return ocispec.Descriptor{}, errors.Wrap(err, "failed to write config") return ocispec.Descriptor{}, errors.Wrap(err, "failed to write config")
} }
for _, ch := range manifest.Layers {
if _, err := c.contentStore.Update(ctx, content.Info{Digest: ch.Digest}, "labels.containerd.io/gc.root"); err != nil {
return ocispec.Descriptor{}, errors.Wrap(err, "failed to remove blob root tag")
}
}
return desc, nil return desc, nil
} }
@ -287,10 +280,8 @@ tryit:
eg.Go(func() error { eg.Go(func() error {
defer pw.Close() defer pw.Close()
opt := content.WithLabels(map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339), return content.Copy(ctx, cw, io.TeeReader(rc, pw), size, desc.Digest)
})
return content.Copy(ctx, cw, io.TeeReader(rc, pw), size, desc.Digest, opt)
}) })
if err := eg.Wait(); err != nil { if err := eg.Wait(); err != nil {

View File

@ -45,7 +45,7 @@ func MakeRefKey(ctx context.Context, desc ocispec.Descriptor) string {
// FetchHandler returns a handler that will fetch all content into the ingester // FetchHandler returns a handler that will fetch all content into the ingester
// discovered in a call to Dispatch. Use with ChildrenHandler to do a full // discovered in a call to Dispatch. Use with ChildrenHandler to do a full
// recursive fetch. // recursive fetch.
func FetchHandler(ingester content.Ingester, fetcher Fetcher, root ocispec.Descriptor) images.HandlerFunc { func FetchHandler(ingester content.Ingester, fetcher Fetcher) images.HandlerFunc {
return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) { return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) {
ctx = log.WithLogger(ctx, log.G(ctx).WithFields(logrus.Fields{ ctx = log.WithLogger(ctx, log.G(ctx).WithFields(logrus.Fields{
"digest": desc.Digest, "digest": desc.Digest,
@ -57,13 +57,13 @@ func FetchHandler(ingester content.Ingester, fetcher Fetcher, root ocispec.Descr
case images.MediaTypeDockerSchema1Manifest: case images.MediaTypeDockerSchema1Manifest:
return nil, fmt.Errorf("%v not supported", desc.MediaType) return nil, fmt.Errorf("%v not supported", desc.MediaType)
default: default:
err := fetch(ctx, ingester, fetcher, desc, desc.Digest == root.Digest) err := fetch(ctx, ingester, fetcher, desc)
return nil, err return nil, err
} }
} }
} }
func fetch(ctx context.Context, ingester content.Ingester, fetcher Fetcher, desc ocispec.Descriptor, root bool) error { func fetch(ctx context.Context, ingester content.Ingester, fetcher Fetcher, desc ocispec.Descriptor) error {
log.G(ctx).Debug("fetch") log.G(ctx).Debug("fetch")
var ( var (
@ -105,13 +105,13 @@ func fetch(ctx context.Context, ingester content.Ingester, fetcher Fetcher, desc
} }
defer rc.Close() defer rc.Close()
r, opts := commitOpts(desc, rc, root) r, opts := commitOpts(desc, rc)
return content.Copy(ctx, cw, r, desc.Size, desc.Digest, opts...) return content.Copy(ctx, cw, r, desc.Size, desc.Digest, opts...)
} }
// commitOpts gets the appropriate content options to alter // commitOpts gets the appropriate content options to alter
// the content info on commit based on media type. // the content info on commit based on media type.
func commitOpts(desc ocispec.Descriptor, r io.Reader, root bool) (io.Reader, []content.Opt) { func commitOpts(desc ocispec.Descriptor, r io.Reader) (io.Reader, []content.Opt) {
var childrenF func(r io.Reader) ([]ocispec.Descriptor, error) var childrenF func(r io.Reader) ([]ocispec.Descriptor, error)
switch desc.MediaType { switch desc.MediaType {
@ -163,13 +163,10 @@ func commitOpts(desc ocispec.Descriptor, r io.Reader, root bool) (io.Reader, []c
return errors.Wrap(err, "unable to get commit labels") return errors.Wrap(err, "unable to get commit labels")
} }
if len(children) > 0 || root { if len(children) > 0 {
if info.Labels == nil { if info.Labels == nil {
info.Labels = map[string]string{} info.Labels = map[string]string{}
} }
if root {
info.Labels["containerd.io/gc.root"] = time.Now().UTC().Format(time.RFC3339)
}
for i, ch := range children { for i, ch := range children {
info.Labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i)] = ch.Digest.String() info.Labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i)] = ch.Digest.String()
} }

View File

@ -18,7 +18,6 @@ import (
"github.com/containerd/containerd/diff" "github.com/containerd/containerd/diff"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/rootfs" "github.com/containerd/containerd/rootfs"
@ -26,7 +25,6 @@ import (
google_protobuf "github.com/gogo/protobuf/types" google_protobuf "github.com/gogo/protobuf/types"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -403,15 +401,6 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
index := v1.Index{ index := v1.Index{
Annotations: make(map[string]string), Annotations: make(map[string]string),
} }
// make sure we clear the gc root labels reguardless of success
var clearRoots []ocispec.Descriptor
defer func() {
for _, r := range append(index.Manifests, clearRoots...) {
if err := clearRootGCLabel(ctx, t.client, r); err != nil {
log.G(ctx).WithError(err).WithField("dgst", r.Digest).Warnf("failed to remove root marker")
}
}
}()
if err := t.checkpointTask(ctx, &index, request); err != nil { if err := t.checkpointTask(ctx, &index, request); err != nil {
return nil, err return nil, err
} }
@ -430,7 +419,6 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
if err != nil { if err != nil {
return nil, err return nil, err
} }
clearRoots = append(clearRoots, desc)
im := images.Image{ im := images.Image{
Name: i.Name, Name: i.Name,
Target: desc, Target: desc,
@ -546,9 +534,6 @@ func (t *task) checkpointTask(ctx context.Context, index *v1.Index, request *tas
func (t *task) checkpointRWSnapshot(ctx context.Context, index *v1.Index, snapshotterName string, id string) error { func (t *task) checkpointRWSnapshot(ctx context.Context, index *v1.Index, snapshotterName string, id string) error {
opts := []diff.Opt{ opts := []diff.Opt{
diff.WithReference(fmt.Sprintf("checkpoint-rw-%s", id)), diff.WithReference(fmt.Sprintf("checkpoint-rw-%s", id)),
diff.WithLabels(map[string]string{
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
}),
} }
rw, err := rootfs.Diff(ctx, id, t.client.SnapshotService(snapshotterName), t.client.DiffService(), opts...) rw, err := rootfs.Diff(ctx, id, t.client.SnapshotService(snapshotterName), t.client.DiffService(), opts...)
if err != nil { if err != nil {
@ -575,9 +560,7 @@ func (t *task) checkpointImage(ctx context.Context, index *v1.Index, image strin
} }
func (t *task) writeIndex(ctx context.Context, index *v1.Index) (d v1.Descriptor, err error) { func (t *task) writeIndex(ctx context.Context, index *v1.Index) (d v1.Descriptor, err error) {
labels := map[string]string{ labels := map[string]string{}
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
}
for i, m := range index.Manifests { for i, m := range index.Manifests {
labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i)] = m.Digest.String() labels[fmt.Sprintf("containerd.io/gc.ref.content.%d", i)] = m.Digest.String()
} }
@ -607,9 +590,3 @@ func writeContent(ctx context.Context, store content.Store, mediaType, ref strin
Size: size, Size: size,
}, nil }, nil
} }
func clearRootGCLabel(ctx context.Context, client *Client, desc ocispec.Descriptor) error {
info := content.Info{Digest: desc.Digest}
_, err := client.ContentStore().Update(ctx, info, "labels.containerd.io/gc.root")
return err
}