Update containerd to fix mount.Lookup.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-02-01 18:27:15 +00:00
parent 8094fe69d4
commit a28672b088
15 changed files with 89 additions and 104 deletions

View File

@ -1,6 +1,6 @@
RUNC_VERSION=9f9c96235cc97674e935002fc3d78361b696a69e
CNI_VERSION=v0.6.0
CONTAINERD_VERSION=ec15fe95aa8fd3abeb05d036e1579129c0ba7b1c
CONTAINERD_VERSION=6570c97942e5438bb6bfa202aa5467a0a9a83b55
CONTAINERD_REPO=
CRITOOL_VERSION=v1.0.0-alpha.0
KUBERNETES_VERSION=v1.9.0

View File

@ -1,7 +1,7 @@
github.com/blang/semver v3.1.0
github.com/BurntSushi/toml v0.2.0-21-g9906417
github.com/containerd/cgroups 29da22c6171a4316169f9205ab6c49f59b5b852f
github.com/containerd/containerd ec15fe95aa8fd3abeb05d036e1579129c0ba7b1c
github.com/containerd/containerd 6570c97942e5438bb6bfa202aa5467a0a9a83b55
github.com/containerd/continuity cf279e6ac893682272b4479d4c67fd3abf878b4e
github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6
github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788

View File

@ -7,8 +7,6 @@ import (
"net/http"
"runtime"
"strconv"
"strings"
"sync"
"time"
containersapi "github.com/containerd/containerd/api/services/containers/v1"
@ -301,51 +299,7 @@ func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor,
return err
}
var m sync.Mutex
manifestStack := []ocispec.Descriptor{}
filterHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch desc.MediaType {
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest,
images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
m.Lock()
manifestStack = append(manifestStack, desc)
m.Unlock()
return nil, images.ErrStopHandler
default:
return nil, nil
}
})
cs := c.ContentStore()
pushHandler := remotes.PushHandler(cs, pusher)
handlers := append(pushCtx.BaseHandlers,
images.ChildrenHandler(cs, platforms.Default()),
filterHandler,
pushHandler,
)
if err := images.Dispatch(ctx, images.Handlers(handlers...), desc); err != nil {
return err
}
// Iterate in reverse order as seen, parent always uploaded after child
for i := len(manifestStack) - 1; i >= 0; i-- {
_, err := pushHandler(ctx, manifestStack[i])
if err != nil {
// TODO(estesp): until we have a more complete method for index push, we need to report
// missing dependencies in an index/manifest list by sensing the "400 Bad Request"
// as a marker for this problem
if (manifestStack[i].MediaType == ocispec.MediaTypeImageIndex ||
manifestStack[i].MediaType == images.MediaTypeDockerSchema2ManifestList) &&
errors.Cause(err) != nil && strings.Contains(errors.Cause(err).Error(), "400 Bad Request") {
return errors.Wrap(err, "manifest list/index references to blobs and/or manifests are missing in your target registry")
}
return err
}
}
return nil
return remotes.PushContent(ctx, pusher, desc, c.ContentStore(), pushCtx.BaseHandlers...)
}
// GetImage returns an existing image

View File

@ -2,6 +2,7 @@ package containerd
import (
"context"
"encoding/json"
"os"
"path/filepath"
"strings"
@ -13,7 +14,6 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/typeurl"
prototypes "github.com/gogo/protobuf/types"
jsoniter "github.com/json-iterator/go"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
@ -115,7 +115,6 @@ func (c *container) Spec(ctx context.Context) (*specs.Spec, error) {
if err != nil {
return nil, err
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
var s specs.Spec
if err := json.Unmarshal(r.Spec.Value, &s); err != nil {
return nil, err

View File

@ -4,6 +4,7 @@ package containerd
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -19,7 +20,6 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity"
"github.com/opencontainers/image-spec/specs-go/v1"
@ -121,7 +121,6 @@ func decodeIndex(ctx context.Context, store content.Store, id digest.Digest) (*v
if err != nil {
return nil, err
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(p, &index); err != nil {
return nil, err
}

View File

@ -3,6 +3,7 @@ package content
import (
"context"
"io"
"io/ioutil"
"sync"
"github.com/containerd/containerd/errdefs"
@ -76,14 +77,7 @@ func Copy(ctx context.Context, cw Writer, r io.Reader, size int64, expected dige
if ws.Offset > 0 {
r, err = seekReader(r, ws.Offset, size)
if err != nil {
if !isUnseekable(err) {
return errors.Wrapf(err, "unable to resume write to %v", ws.Ref)
}
// reader is unseekable, try to move the writer back to the start.
if err := cw.Truncate(0); err != nil {
return errors.Wrapf(err, "content writer truncate failed")
}
return errors.Wrapf(err, "unable to resume write to %v", ws.Ref)
}
}
@ -103,14 +97,9 @@ func Copy(ctx context.Context, cw Writer, r io.Reader, size int64, expected dige
return nil
}
var errUnseekable = errors.New("seek not supported")
func isUnseekable(err error) bool {
return errors.Cause(err) == errUnseekable
}
// seekReader attempts to seek the reader to the given offset, either by
// resolving `io.Seeker` or by detecting `io.ReaderAt`.
// resolving `io.Seeker`, by detecting `io.ReaderAt`, or discarding
// up to the given offset.
func seekReader(r io.Reader, offset, size int64) (io.Reader, error) {
// attempt to resolve r as a seeker and setup the offset.
seeker, ok := r.(io.Seeker)
@ -134,5 +123,17 @@ func seekReader(r io.Reader, offset, size int64) (io.Reader, error) {
return sr, nil
}
return r, errors.Wrapf(errUnseekable, "seek to offset %v failed", offset)
// well then, let's just discard up to the offset
buf := bufPool.Get().(*[]byte)
defer bufPool.Put(buf)
n, err := io.CopyBuffer(ioutil.Discard, io.LimitReader(r, offset), *buf)
if err != nil {
return nil, errors.Wrap(err, "failed to discard to offset")
}
if n != offset {
return nil, errors.Errorf("unable to discard to offset")
}
return r, nil
}

View File

@ -4,12 +4,12 @@ package seccomp
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/oci"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/runtime-spec/specs-go"
)
@ -23,7 +23,6 @@ func WithProfile(profile string) oci.SpecOpts {
if err != nil {
return fmt.Errorf("Cannot load seccomp profile %q: %v", profile, err)
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(f, s.Linux.Seccomp); err != nil {
return fmt.Errorf("Decoding seccomp profile failed %q: %v", profile, err)
}

View File

@ -2,6 +2,7 @@ package images
import (
"context"
"encoding/json"
"strings"
"time"
@ -9,7 +10,6 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
@ -123,7 +123,6 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc
return ocispec.Manifest{}, err
}
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := Walk(ctx, HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch desc.MediaType {
@ -217,7 +216,6 @@ func Config(ctx context.Context, provider content.Provider, image ocispec.Descri
// Platforms returns one or more platforms supported by the image.
func Platforms(ctx context.Context, provider content.Provider, image ocispec.Descriptor) ([]ocispec.Platform, error) {
var platformSpecs []ocispec.Platform
json := jsoniter.ConfigCompatibleWithStandardLibrary
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)
@ -288,7 +286,6 @@ func Check(ctx context.Context, provider content.Provider, image ocispec.Descrip
// Children returns the immediate children of content described by the descriptor.
func Children(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, platform string) ([]ocispec.Descriptor, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var descs []ocispec.Descriptor
switch desc.MediaType {
case MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
@ -357,7 +354,6 @@ func RootFS(ctx context.Context, provider content.Provider, configDesc ocispec.D
return nil, err
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
var config ocispec.Image
if err := json.Unmarshal(p, &config); err != nil {
return nil, err

View File

@ -3,22 +3,16 @@
package mount
import (
"fmt"
"path/filepath"
"sort"
"strings"
"syscall"
"github.com/pkg/errors"
)
// Lookup returns the mount info corresponds to the path.
func Lookup(dir string) (Info, error) {
var dirStat syscall.Stat_t
dir = filepath.Clean(dir)
if err := syscall.Stat(dir, &dirStat); err != nil {
return Info{}, errors.Wrapf(err, "failed to access %q", dir)
}
mounts, err := Self()
if err != nil {
@ -26,21 +20,18 @@ func Lookup(dir string) (Info, error) {
}
// Sort descending order by Info.Mountpoint
sort.Slice(mounts, func(i, j int) bool {
sort.SliceStable(mounts, func(i, j int) bool {
return mounts[j].Mountpoint < mounts[i].Mountpoint
})
for _, m := range mounts {
// Note that m.{Major, Minor} are generally unreliable for our purpose here
// https://www.spinics.net/lists/linux-btrfs/msg58908.html
var st syscall.Stat_t
if err := syscall.Stat(m.Mountpoint, &st); err != nil {
// may fail; ignore err
continue
}
if st.Dev == dirStat.Dev && strings.HasPrefix(dir, m.Mountpoint) {
// Note that device number is not checked here, because for overlayfs files
// may have different device number with the mountpoint.
if strings.HasPrefix(dir, m.Mountpoint) {
return m, nil
}
}
return Info{}, fmt.Errorf("failed to find the mount info for %q", dir)
return Info{}, errors.Errorf("failed to find the mount info for %q", dir)
}

View File

@ -1,11 +1,11 @@
package mount
import (
"encoding/json"
"path/filepath"
"strings"
"github.com/Microsoft/hcsshim"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
@ -49,7 +49,6 @@ const ParentLayerPathsFlag = "parentLayerPaths="
// GetParentPaths of the mount
func (m *Mount) GetParentPaths() ([]string, error) {
var parentLayerPaths []string
json := jsoniter.ConfigCompatibleWithStandardLibrary
for _, option := range m.Options {
if strings.HasPrefix(option, ParentLayerPathsFlag) {
err := json.Unmarshal([]byte(option[len(ParentLayerPathsFlag):]), &parentLayerPaths)

View File

@ -4,6 +4,7 @@ package oci
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -16,7 +17,6 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/runc/libcontainer/user"
specs "github.com/opencontainers/runtime-spec/specs-go"
@ -66,7 +66,6 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts {
// WithImageConfig configures the spec to from the configuration of an Image
func WithImageConfig(image Image) SpecOpts {
return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
ic, err := image.Config(ctx)
if err != nil {
return err

View File

@ -4,12 +4,12 @@ package oci
import (
"context"
"encoding/json"
"fmt"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -24,7 +24,6 @@ func WithImageConfig(image Image) SpecOpts {
var (
ociimage v1.Image
config v1.ImageConfig
json = jsoniter.ConfigCompatibleWithStandardLibrary
)
switch ic.MediaType {
case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config:

View File

@ -5,6 +5,7 @@ import (
"compress/gzip"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
@ -20,7 +21,6 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/remotes"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@ -110,7 +110,6 @@ func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
return ocispec.Descriptor{}, errors.Wrap(err, "schema 1 conversion failed")
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
var img ocispec.Image
if err := json.Unmarshal([]byte(c.pulledManifest.History[0].V1Compatibility), &img); err != nil {
return ocispec.Descriptor{}, errors.Wrap(err, "failed to unmarshal image from schema 1 history")
@ -195,7 +194,6 @@ func (c *Converter) fetchManifest(ctx context.Context, desc ocispec.Descriptor)
return err
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
var m manifest
if err := json.Unmarshal(b, &m); err != nil {
return err
@ -318,7 +316,6 @@ func (c *Converter) schema1ManifestHistory() ([]ocispec.History, []digest.Digest
return nil, nil, errors.New("no history")
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
history := make([]ocispec.History, len(m.History))
diffIDs := []digest.Digest{}
for i := range m.History {
@ -376,7 +373,6 @@ type v1History struct {
// empty layer. A return value of true indicates the layer is empty,
// however false does not indicate non-empty.
func isEmptyLayer(compatHistory []byte) (bool, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var h v1History
if err := json.Unmarshal(compatHistory, &h); err != nil {
return false, err
@ -426,7 +422,6 @@ func joseBase64UrlDecode(s string) ([]byte, error) {
}
func stripSignature(b []byte) ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var sig signature
if err := json.Unmarshal(b, &sig); err != nil {
return nil, err

View File

@ -6,12 +6,15 @@ import (
"fmt"
"io"
"math/rand"
"strings"
"sync"
"time"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -180,7 +183,7 @@ func commitOpts(desc ocispec.Descriptor, r io.Reader) (io.Reader, []content.Opt)
// PushHandler returns a handler that will push all content from the provider
// using a writer from the pusher.
func PushHandler(provider content.Provider, pusher Pusher) images.HandlerFunc {
func PushHandler(pusher Pusher, provider content.Provider) images.HandlerFunc {
return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
ctx = log.WithLogger(ctx, log.G(ctx).WithFields(logrus.Fields{
"digest": desc.Digest,
@ -215,3 +218,55 @@ func push(ctx context.Context, provider content.Provider, pusher Pusher, desc oc
rd := io.NewSectionReader(ra, 0, desc.Size)
return content.Copy(ctx, cw, rd, desc.Size, desc.Digest)
}
// PushContent pushes content specified by the descriptor from the provider.
//
// Base handlers can be provided which will be called before any push specific
// handlers.
func PushContent(ctx context.Context, pusher Pusher, desc ocispec.Descriptor, provider content.Provider, baseHandlers ...images.Handler) error {
var m sync.Mutex
manifestStack := []ocispec.Descriptor{}
filterHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch desc.MediaType {
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest,
images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
m.Lock()
manifestStack = append(manifestStack, desc)
m.Unlock()
return nil, images.ErrStopHandler
default:
return nil, nil
}
})
pushHandler := PushHandler(pusher, provider)
handlers := append(baseHandlers,
images.ChildrenHandler(provider, platforms.Default()),
filterHandler,
pushHandler,
)
if err := images.Dispatch(ctx, images.Handlers(handlers...), desc); err != nil {
return err
}
// Iterate in reverse order as seen, parent always uploaded after child
for i := len(manifestStack) - 1; i >= 0; i-- {
_, err := pushHandler(ctx, manifestStack[i])
if err != nil {
// TODO(estesp): until we have a more complete method for index push, we need to report
// missing dependencies in an index/manifest list by sensing the "400 Bad Request"
// as a marker for this problem
if (manifestStack[i].MediaType == ocispec.MediaTypeImageIndex ||
manifestStack[i].MediaType == images.MediaTypeDockerSchema2ManifestList) &&
errors.Cause(err) != nil && strings.Contains(errors.Cause(err).Error(), "400 Bad Request") {
return errors.Wrap(err, "manifest list/index references to blobs and/or manifests are missing in your target registry")
}
return err
}
}
return nil
}

View File

@ -42,4 +42,3 @@ golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4
github.com/dmcgowan/go-tar go1.10
github.com/stevvooe/ttrpc d2710463e497617f16f26d1e715a3308609e7982
github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
github.com/json-iterator/go 1.0.4