From ad04781e3eac61ee8e56b0aef014564212080a70 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Sat, 24 Feb 2018 00:09:21 +0000 Subject: [PATCH] Update cri-containerd to 5bd99af7dbfc887d2c62af3949c8d01424c43f78 Signed-off-by: Lantao Liu --- vendor.conf | 2 +- .../containerd/cri-containerd/README.md | 2 +- .../cri-containerd/pkg/ioutil/writer_group.go | 22 ++++++--- .../pkg/server/container_attach.go | 4 +- .../pkg/server/container_log_reopen.go | 26 +++++++++-- .../pkg/server/container_start.go | 4 +- .../pkg/server/io/container_io.go | 45 +++++++++---------- .../cri-containerd/pkg/server/restart.go | 2 +- .../cri-containerd/pkg/server/service.go | 17 ++++++- .../pkg/store/container/container.go | 4 +- .../pkg/store/sandbox/sandbox.go | 4 +- .../cri-containerd/pkg/store/util.go | 30 ++++++++++--- .../containerd/cri-containerd/vendor.conf | 18 +++++++- 13 files changed, 123 insertions(+), 57 deletions(-) diff --git a/vendor.conf b/vendor.conf index aff84f5c9..0639c6399 100644 --- a/vendor.conf +++ b/vendor.conf @@ -43,7 +43,7 @@ github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16 github.com/gotestyourself/gotestyourself 44dbf532bbf5767611f6f2a61bded572e337010a github.com/google/go-cmp v0.1.0 # cri dependencies -github.com/containerd/cri-containerd 83573155645882403ef2da86df8ea95e2d031f28 +github.com/containerd/cri-containerd c9081b2ec0eefc799f0f1caabbea29d516c72c44 github.com/blang/semver v3.1.0 github.com/containernetworking/cni v0.6.0 github.com/containernetworking/plugins v0.6.0 diff --git a/vendor/github.com/containerd/cri-containerd/README.md b/vendor/github.com/containerd/cri-containerd/README.md index fd34b7561..0c0909bab 100644 --- a/vendor/github.com/containerd/cri-containerd/README.md +++ b/vendor/github.com/containerd/cri-containerd/README.md @@ -39,7 +39,7 @@ The current release of `cri-containerd` has the following dependencies: * [runc](https://github.com/opencontainers/runc) * [CNI](https://github.com/containernetworking/cni) -See [versions](./hack/versions) of these dependencies `cri-containerd` is tested with. +See [versions](./vendor.conf) of these dependencies `cri-containerd` is tested with. As containerd and runc move to their respective general availability releases, we will do our best to rebase/retest `cri-containerd` with these releases on a diff --git a/vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go b/vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go index 7c3dde5cb..ea69ce88b 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go @@ -39,16 +39,24 @@ func NewWriterGroup() *WriterGroup { } } -// Add adds a writer into the group, returns an error when writer -// group is closed. -func (g *WriterGroup) Add(key string, w io.WriteCloser) error { +// Add adds a writer into the group. The writer will be closed +// if the writer group is closed. +func (g *WriterGroup) Add(key string, w io.WriteCloser) { g.mu.Lock() defer g.mu.Unlock() if g.closed { - return errors.New("wait group closed") + w.Close() + return } g.writers[key] = w - return nil +} + +// Get gets a writer from the group, returns nil if the writer +// doesn't exist. +func (g *WriterGroup) Get(key string) io.WriteCloser { + g.mu.Lock() + defer g.mu.Unlock() + return g.writers[key] } // Remove removes a writer from the group. @@ -84,8 +92,8 @@ func (g *WriterGroup) Write(p []byte) (int, error) { return len(p), nil } -// Close closes the writer group. Write or Add will return error -// after closed. +// Close closes the writer group. Write will return error after +// closed. func (g *WriterGroup) Close() { g.mu.Lock() defer g.mu.Unlock() diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go b/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go index 116c0cf4e..c823f0953 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go @@ -77,8 +77,6 @@ func (c *criContainerdService) attachContainer(ctx context.Context, id string, s }, } // TODO(random-liu): Figure out whether we need to support historical output. - if err := cntr.IO.Attach(opts); err != nil { - return fmt.Errorf("failed to attach container: %v", err) - } + cntr.IO.Attach(opts) return nil } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go b/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go index 3df4f3efd..b233e65d4 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go @@ -17,7 +17,7 @@ limitations under the License. package server import ( - "errors" + "fmt" "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" @@ -25,7 +25,27 @@ import ( // ReopenContainerLog asks cri-containerd to reopen the stdout/stderr log file for the container. // This is often called after the log file has been rotated. -// TODO(random-liu): Implement this for kubelet log rotation. func (c *criContainerdService) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (*runtime.ReopenContainerLogResponse, error) { - return nil, errors.New("not implemented") + container, err := c.containerStore.Get(r.GetContainerId()) + if err != nil { + return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err) + } + + if container.Status.Get().State() != runtime.ContainerState_CONTAINER_RUNNING { + return nil, fmt.Errorf("container is not running") + } + + // Create new container logger and replace the existing ones. + stdoutWC, stderrWC, err := createContainerLoggers(container.LogPath, container.Config.GetTty()) + if err != nil { + return nil, err + } + oldStdoutWC, oldStderrWC := container.IO.AddOutput("log", stdoutWC, stderrWC) + if oldStdoutWC != nil { + oldStdoutWC.Close() + } + if oldStderrWC != nil { + oldStderrWC.Close() + } + return &runtime.ReopenContainerLogResponse{}, nil } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go b/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go index d16cecf86..32fb2963a 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go @@ -110,9 +110,7 @@ func (c *criContainerdService) startContainer(ctx context.Context, } } }() - if err := cio.WithOutput("log", stdoutWC, stderrWC)(cntr.IO); err != nil { - return nil, fmt.Errorf("failed to add container log: %v", err) - } + cntr.IO.AddOutput("log", stdoutWC, stderrWC) cntr.IO.Pipe() return cntr.IO, nil } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go b/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go index b8d166a38..726071213 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go @@ -52,23 +52,6 @@ var _ cio.IO = &ContainerIO{} // ContainerIOOpts sets specific information to newly created ContainerIO. type ContainerIOOpts func(*ContainerIO) error -// WithOutput adds output stream to the container io. -func WithOutput(name string, stdout, stderr io.WriteCloser) ContainerIOOpts { - return func(c *ContainerIO) error { - if stdout != nil { - if err := c.stdoutGroup.Add(streamKey(c.id, name, Stdout), stdout); err != nil { - return err - } - } - if stderr != nil { - if err := c.stderrGroup.Add(streamKey(c.id, name, Stderr), stderr); err != nil { - return err - } - } - return nil - } -} - // WithFIFOs specifies existing fifos for the container io. func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts { return func(c *ContainerIO) error { @@ -149,7 +132,7 @@ func (c *ContainerIO) Pipe() { // Attach attaches container stdio. // TODO(random-liu): Use pools.Copy in docker to reduce memory usage? -func (c *ContainerIO) Attach(opts AttachOptions) error { +func (c *ContainerIO) Attach(opts AttachOptions) { var wg sync.WaitGroup key := util.GenerateID() stdinKey := streamKey(c.id, "attach-"+key, Stdin) @@ -202,21 +185,33 @@ func (c *ContainerIO) Attach(opts AttachOptions) error { if opts.Stdout != nil { wg.Add(1) wc, close := cioutil.NewWriteCloseInformer(opts.Stdout) - if err := c.stdoutGroup.Add(stdoutKey, wc); err != nil { - return err - } + c.stdoutGroup.Add(stdoutKey, wc) go attachStream(stdoutKey, close) } if !opts.Tty && opts.Stderr != nil { wg.Add(1) wc, close := cioutil.NewWriteCloseInformer(opts.Stderr) - if err := c.stderrGroup.Add(stderrKey, wc); err != nil { - return err - } + c.stderrGroup.Add(stderrKey, wc) go attachStream(stderrKey, close) } wg.Wait() - return nil +} + +// AddOutput adds new write closers to the container stream, and returns existing +// write closers if there are any. +func (c *ContainerIO) AddOutput(name string, stdout, stderr io.WriteCloser) (io.WriteCloser, io.WriteCloser) { + var oldStdout, oldStderr io.WriteCloser + if stdout != nil { + key := streamKey(c.id, name, Stdout) + oldStdout = c.stdoutGroup.Get(key) + c.stdoutGroup.Add(key, stdout) + } + if stderr != nil { + key := streamKey(c.id, name, Stderr) + oldStderr = c.stderrGroup.Get(key) + c.stderrGroup.Add(key, stderr) + } + return oldStdout, oldStderr } // Cancel cancels container io. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go b/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go index 04887034e..158c4b178 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go @@ -161,11 +161,11 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir } containerIO, err = cio.NewContainerIO(id, cio.WithFIFOs(fifos), - cio.WithOutput("log", stdoutWC, stderrWC), ) if err != nil { return nil, err } + containerIO.AddOutput("log", stdoutWC, stderrWC) containerIO.Pipe() return containerIO, nil }) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/service.go b/vendor/github.com/containerd/cri-containerd/pkg/server/service.go index 3c06b69f5..f502709db 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/service.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/server/service.go @@ -262,8 +262,21 @@ func (c *criContainerdService) Run(startGRPC bool) error { <-eventMonitorCloseCh logrus.Info("Event monitor stopped") - <-streamServerCloseCh - logrus.Info("Stream server stopped") + // There is a race condition with http.Server.Serve. + // When `Close` is called at the same time with `Serve`, `Close` + // may finish first, and `Serve` may still block. + // See https://github.com/golang/go/issues/20239. + // Here we set a 2 second timeout for the stream server wait, + // if it timeout, an error log is generated. + // TODO(random-liu): Get rid of this after https://github.com/golang/go/issues/20239 + // is fixed. + const streamServerStopTimeout = 2 * time.Second + select { + case <-streamServerCloseCh: + logrus.Info("Stream server stopped") + case <-time.After(streamServerStopTimeout): + logrus.Errorf("Stream server is not stopped in %q", streamServerStopTimeout) + } if startGRPC { // Only wait for grpc server close channel when grpc server is started. <-grpcServerCloseCh diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go b/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go index cbac43257..76cf41a7a 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go @@ -39,7 +39,7 @@ type Container struct { // Container IO IO *cio.ContainerIO // StopCh is used to propagate the stop information of the container. - store.StopCh + *store.StopCh } // Opts sets specific information to newly created Container. @@ -80,7 +80,7 @@ func WithStatus(status Status, root string) Opts { func NewContainer(metadata Metadata, opts ...Opts) (Container, error) { c := Container{ Metadata: metadata, - StopCh: store.StopCh(make(chan struct{})), + StopCh: store.NewStopCh(), } for _, o := range opts { if err := o(&c); err != nil { diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go b/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go index dfcc7dde0..f9c45ef08 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go @@ -37,7 +37,7 @@ type Sandbox struct { // CNI network namespace client NetNS *NetNS // StopCh is used to propagate the stop information of the sandbox. - store.StopCh + *store.StopCh } // NewSandbox creates an internally used sandbox type. This functions reminds @@ -46,7 +46,7 @@ func NewSandbox(metadata Metadata, status Status) Sandbox { s := Sandbox{ Metadata: metadata, Status: StoreStatus(status), - StopCh: store.StopCh(make(chan struct{})), + StopCh: store.NewStopCh(), } if status.State == StateNotReady { s.Stop() diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/util.go b/vendor/github.com/containerd/cri-containerd/pkg/store/util.go index 8a7b6fcf9..8ea173e0d 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/util.go +++ b/vendor/github.com/containerd/cri-containerd/pkg/store/util.go @@ -16,15 +16,35 @@ limitations under the License. package store +import "sync" + // StopCh is used to propagate the stop information of a container. -type StopCh chan struct{} +type StopCh struct { + mu sync.Mutex + ch chan struct{} + closed bool +} + +// NewStopCh creates a stop channel. The channel is open by default. +func NewStopCh() *StopCh { + return &StopCh{ + ch: make(chan struct{}), + closed: false, + } +} // Stop close stopCh of the container. -func (ch StopCh) Stop() { - close(ch) +func (s *StopCh) Stop() { + s.mu.Lock() + defer s.mu.Unlock() + if s.closed { + return + } + close(s.ch) + s.closed = true } // Stopped return the stopCh of the container as a readonly channel. -func (ch StopCh) Stopped() <-chan struct{} { - return ch +func (s *StopCh) Stopped() <-chan struct{} { + return s.ch } diff --git a/vendor/github.com/containerd/cri-containerd/vendor.conf b/vendor/github.com/containerd/cri-containerd/vendor.conf index db92e52bf..2c5175318 100644 --- a/vendor/github.com/containerd/cri-containerd/vendor.conf +++ b/vendor/github.com/containerd/cri-containerd/vendor.conf @@ -1,18 +1,24 @@ +github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 github.com/blang/semver v3.1.0 +github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089 -github.com/containerd/containerd ee6ffdd91e8fd9ec2b9684fd385e81a16c40e99c -github.com/containerd/continuity 1a794c0014a7b786879312d1dab309ba96ead8bc +github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e +github.com/containerd/containerd 129167132c5e0dbd1b031badae201a432d1bd681 +github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371 github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 +github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788 github.com/containernetworking/cni v0.6.0 github.com/containernetworking/plugins v0.6.0 github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6 github.com/cri-o/ocicni 9b451e26eb7c694d564991fbf44f77d0afb9b03c github.com/davecgh/go-spew v1.1.0 +github.com/dmcgowan/go-tar go1.10 github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621 github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 +github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098 github.com/docker/go-units v0.3.1 github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528 github.com/emicklei/go-restful ff4f55a206334ef123e4f79bbf348980da81ca46 @@ -23,10 +29,12 @@ github.com/gogo/protobuf v0.5 github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed github.com/golang/protobuf 1643683e1b54a9e88ad26d98f81400c8c9d9f4f9 github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c +github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0 github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55 github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 github.com/json-iterator/go 1.0.4 +github.com/matttproud/golang_protobuf_extensions v1.0.0 github.com/Microsoft/go-winio v0.4.5 github.com/Microsoft/hcsshim v0.6.7 github.com/opencontainers/go-digest 21dfd564fd89c944783d00d069f33e3e7123c448 @@ -37,14 +45,20 @@ github.com/opencontainers/runtime-tools 6073aff4ac61897f75895123f7e24135204a404d github.com/opencontainers/selinux 4a2974bf1ee960774ffd517717f1f45325af0206 github.com/pkg/errors v0.8.0 github.com/pmezard/go-difflib v1.0.0 +github.com/prometheus/client_golang f4fb1b73fb099f396a7f0036bf86aa8def4ed823 +github.com/prometheus/client_model 99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c +github.com/prometheus/common 89604d197083d4781071d3c65855d24ecfb0a563 +github.com/prometheus/procfs cb4147076ac75738c9a7d279075a253c0cc5acbd github.com/renstrom/dedent 020d11c3b9c0c7a3c2efcc8e5cf5b9ef7bcea21f github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0 github.com/sirupsen/logrus v1.0.0 github.com/spf13/cobra v0.0.1 github.com/spf13/pflag v1.0.0 +github.com/stevvooe/ttrpc d4528379866b0ce7e9d71f3eb96f0582fc374577 github.com/stretchr/testify v1.1.4 github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16 github.com/tchap/go-patricia 5ad6cdb7538b0097d5598c7e57f0a24072adf7dc +github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6 golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c golang.org/x/sys 314a259e304ff91bd6985da2a7149bbf91237993 https://github.com/golang/sys