From 0d8298aa43bad3f840bd79975aec5819e59389b2 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Mon, 4 Dec 2017 18:22:51 +0000 Subject: [PATCH 1/2] Update containerd Signed-off-by: Lantao Liu --- hack/versions | 3 ++- vendor.conf | 3 +-- .../containerd/container_opts_unix.go | 10 ++++--- .../containerd/mount/mount_linux.go | 27 ++++++++++++++++--- .../containerd/oci/spec_opts_unix.go | 27 +++++++++++++------ 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/hack/versions b/hack/versions index 8e21465de..f893a9d81 100644 --- a/hack/versions +++ b/hack/versions @@ -1,5 +1,6 @@ RUNC_VERSION=74a17296470088de3805e138d3d87c62e613dfc4 CNI_VERSION=v0.6.0 -CONTAINERD_VERSION=53c892d796a565127899d397e43bd52edf3148b0 +CONTAINERD_VERSION=cc969fb42f427a68a8cc6870ef47f17304b83962 +CONTAINERD_REPO= CRITOOL_VERSION=4cd2b047a26a2ef01bbd02ee55f7d70d8825ebb5 KUBERNETES_VERSION=164317879bcd810b97e5ebf1c8df041770f2ff1b diff --git a/vendor.conf b/vendor.conf index 67b0cb7f3..b1d0ce7d7 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,8 +1,7 @@ github.com/blang/semver v3.1.0 -github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 github.com/containerd/cgroups 29da22c6171a4316169f9205ab6c49f59b5b852f -github.com/containerd/containerd 53c892d796a565127899d397e43bd52edf3148b0 +github.com/containerd/containerd cc969fb42f427a68a8cc6870ef47f17304b83962 github.com/containerd/continuity cf279e6ac893682272b4479d4c67fd3abf878b4e github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788 diff --git a/vendor/github.com/containerd/containerd/container_opts_unix.go b/vendor/github.com/containerd/containerd/container_opts_unix.go index bb431e51f..b678033b7 100644 --- a/vendor/github.com/containerd/containerd/container_opts_unix.go +++ b/vendor/github.com/containerd/containerd/container_opts_unix.go @@ -24,7 +24,6 @@ import ( "github.com/opencontainers/image-spec/identity" "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "golang.org/x/sys/unix" ) // WithCheckpoint allows a container to be created from the checkpointed information @@ -193,14 +192,17 @@ func remapRootFS(mounts []mount.Mount, uid, gid uint32) error { if err != nil { return err } - defer os.RemoveAll(root) + defer os.Remove(root) for _, m := range mounts { if err := m.Mount(root); err != nil { return err } } - defer unix.Unmount(root, 0) - return filepath.Walk(root, incrementFS(root, uid, gid)) + err = filepath.Walk(root, incrementFS(root, uid, gid)) + if uerr := mount.Unmount(root, 0); err == nil { + err = uerr + } + return err } func incrementFS(root string, uidInc, gidInc uint32) filepath.WalkFunc { diff --git a/vendor/github.com/containerd/containerd/mount/mount_linux.go b/vendor/github.com/containerd/containerd/mount/mount_linux.go index 474792d8e..de2e8bb7d 100644 --- a/vendor/github.com/containerd/containerd/mount/mount_linux.go +++ b/vendor/github.com/containerd/containerd/mount/mount_linux.go @@ -2,7 +2,9 @@ package mount import ( "strings" + "time" + "github.com/pkg/errors" "golang.org/x/sys/unix" ) @@ -42,8 +44,27 @@ func (m *Mount) Mount(target string) error { } // Unmount the provided mount path with the flags -func Unmount(mount string, flags int) error { - return unix.Unmount(mount, flags) +func Unmount(target string, flags int) error { + if err := unmount(target, flags); err != nil && err != unix.EINVAL { + return err + } + return nil +} + +func unmount(target string, flags int) error { + for i := 0; i < 50; i++ { + if err := unix.Unmount(target, flags); err != nil { + switch err { + case unix.EBUSY: + time.Sleep(50 * time.Millisecond) + continue + default: + return err + } + } + return nil + } + return errors.Wrapf(unix.EBUSY, "failed to unmount target %s", target) } // UnmountAll repeatedly unmounts the given mount point until there @@ -51,7 +72,7 @@ func Unmount(mount string, flags int) error { // useful for undoing a stack of mounts on the same mount point. func UnmountAll(mount string, flags int) error { for { - if err := Unmount(mount, flags); err != nil { + if err := unmount(mount, flags); err != nil { // EINVAL is returned if the target is not a // mount point, indicating that we are // done. It can also indicate a few other diff --git a/vendor/github.com/containerd/containerd/oci/spec_opts_unix.go b/vendor/github.com/containerd/containerd/oci/spec_opts_unix.go index 3a07f377e..865aff29a 100644 --- a/vendor/github.com/containerd/containerd/oci/spec_opts_unix.go +++ b/vendor/github.com/containerd/containerd/oci/spec_opts_unix.go @@ -12,12 +12,11 @@ import ( "strconv" "strings" - "golang.org/x/sys/unix" - "github.com/containerd/containerd/containers" "github.com/containerd/containerd/content" "github.com/containerd/containerd/fs" "github.com/containerd/containerd/images" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/namespaces" "github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/runc/libcontainer/user" @@ -260,7 +259,7 @@ func WithUIDGID(uid, gid uint32) SpecOpts { // or uid is not found in /etc/passwd, it sets gid to be the same with // uid, and not returns error. func WithUserID(uid uint32) SpecOpts { - return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error { + return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) (err error) { if c.Snapshotter == "" { return errors.Errorf("no snapshotter set for container") } @@ -276,13 +275,19 @@ func WithUserID(uid uint32) SpecOpts { if err != nil { return err } - defer os.RemoveAll(root) + defer os.Remove(root) for _, m := range mounts { if err := m.Mount(root); err != nil { return err } } - defer unix.Unmount(root, 0) + defer func() { + if uerr := mount.Unmount(root, 0); uerr != nil { + if err == nil { + err = uerr + } + } + }() ppath, err := fs.RootPath(root, "/etc/passwd") if err != nil { return err @@ -317,7 +322,7 @@ func WithUserID(uid uint32) SpecOpts { // does not exist, or the username is not found in /etc/passwd, // it returns error. func WithUsername(username string) SpecOpts { - return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error { + return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) (err error) { if c.Snapshotter == "" { return errors.Errorf("no snapshotter set for container") } @@ -333,13 +338,19 @@ func WithUsername(username string) SpecOpts { if err != nil { return err } - defer os.RemoveAll(root) + defer os.Remove(root) for _, m := range mounts { if err := m.Mount(root); err != nil { return err } } - defer unix.Unmount(root, 0) + defer func() { + if uerr := mount.Unmount(root, 0); uerr != nil { + if err == nil { + err = uerr + } + } + }() ppath, err := fs.RootPath(root, "/etc/passwd") if err != nil { return err From 12a71882db771db5de195173745b770bc5401de4 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Mon, 4 Dec 2017 18:23:13 +0000 Subject: [PATCH 2/2] Add support to install from alternative repo Signed-off-by: Lantao Liu --- hack/install-deps.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hack/install-deps.sh b/hack/install-deps.sh index 8b7df187f..76b53a069 100755 --- a/hack/install-deps.sh +++ b/hack/install-deps.sh @@ -72,12 +72,17 @@ GOPATH=${GOPATH%%:*} # checkout_repo checks out specified repository # and switch to specified version. # Varset: -# 1) Repo name; +# 1) Pkg name; # 2) Version. +# 3) Repo name (optional); checkout_repo() { - repo=$1 + pkg=$1 version=$2 - path="${GOPATH}/src/${repo}" + repo=${3:-""} + if [ -z "${repo}" ]; then + repo=${pkg} + fi + path="${GOPATH}/src/${pkg}" if [ ! -d ${path} ]; then mkdir -p ${path} git clone https://${repo} ${path} @@ -130,7 +135,7 @@ EOF' fi # Install containerd -checkout_repo ${CONTAINERD_PKG} ${CONTAINERD_VERSION} +checkout_repo ${CONTAINERD_PKG} ${CONTAINERD_VERSION} ${CONTAINERD_REPO} cd ${GOPATH}/src/${CONTAINERD_PKG} make ${sudo} make install -e DESTDIR=${CONTAINERD_DIR}