Update cri-containerd to 5bd99af7db

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-02-24 00:09:21 +00:00
parent 5bd99af7db
commit ad04781e3e
13 changed files with 123 additions and 57 deletions

View File

@ -43,7 +43,7 @@ github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
github.com/gotestyourself/gotestyourself 44dbf532bbf5767611f6f2a61bded572e337010a github.com/gotestyourself/gotestyourself 44dbf532bbf5767611f6f2a61bded572e337010a
github.com/google/go-cmp v0.1.0 github.com/google/go-cmp v0.1.0
# cri dependencies # cri dependencies
github.com/containerd/cri-containerd 83573155645882403ef2da86df8ea95e2d031f28 github.com/containerd/cri-containerd c9081b2ec0eefc799f0f1caabbea29d516c72c44
github.com/blang/semver v3.1.0 github.com/blang/semver v3.1.0
github.com/containernetworking/cni v0.6.0 github.com/containernetworking/cni v0.6.0
github.com/containernetworking/plugins v0.6.0 github.com/containernetworking/plugins v0.6.0

View File

@ -39,7 +39,7 @@ The current release of `cri-containerd` has the following dependencies:
* [runc](https://github.com/opencontainers/runc) * [runc](https://github.com/opencontainers/runc)
* [CNI](https://github.com/containernetworking/cni) * [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, 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 we will do our best to rebase/retest `cri-containerd` with these releases on a

View File

@ -39,16 +39,24 @@ func NewWriterGroup() *WriterGroup {
} }
} }
// Add adds a writer into the group, returns an error when writer // Add adds a writer into the group. The writer will be closed
// group is closed. // if the writer group is closed.
func (g *WriterGroup) Add(key string, w io.WriteCloser) error { func (g *WriterGroup) Add(key string, w io.WriteCloser) {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
if g.closed { if g.closed {
return errors.New("wait group closed") w.Close()
return
} }
g.writers[key] = w 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. // Remove removes a writer from the group.
@ -84,8 +92,8 @@ func (g *WriterGroup) Write(p []byte) (int, error) {
return len(p), nil return len(p), nil
} }
// Close closes the writer group. Write or Add will return error // Close closes the writer group. Write will return error after
// after closed. // closed.
func (g *WriterGroup) Close() { func (g *WriterGroup) Close() {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()

View File

@ -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. // TODO(random-liu): Figure out whether we need to support historical output.
if err := cntr.IO.Attach(opts); err != nil { cntr.IO.Attach(opts)
return fmt.Errorf("failed to attach container: %v", err)
}
return nil return nil
} }

View File

@ -17,7 +17,7 @@ limitations under the License.
package server package server
import ( import (
"errors" "fmt"
"golang.org/x/net/context" "golang.org/x/net/context"
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" 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. // 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. // 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) { 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
} }

View File

@ -110,9 +110,7 @@ func (c *criContainerdService) startContainer(ctx context.Context,
} }
} }
}() }()
if err := cio.WithOutput("log", stdoutWC, stderrWC)(cntr.IO); err != nil { cntr.IO.AddOutput("log", stdoutWC, stderrWC)
return nil, fmt.Errorf("failed to add container log: %v", err)
}
cntr.IO.Pipe() cntr.IO.Pipe()
return cntr.IO, nil return cntr.IO, nil
} }

View File

@ -52,23 +52,6 @@ var _ cio.IO = &ContainerIO{}
// ContainerIOOpts sets specific information to newly created ContainerIO. // ContainerIOOpts sets specific information to newly created ContainerIO.
type ContainerIOOpts func(*ContainerIO) error 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. // WithFIFOs specifies existing fifos for the container io.
func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts { func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts {
return func(c *ContainerIO) error { return func(c *ContainerIO) error {
@ -149,7 +132,7 @@ func (c *ContainerIO) Pipe() {
// Attach attaches container stdio. // Attach attaches container stdio.
// TODO(random-liu): Use pools.Copy in docker to reduce memory usage? // 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 var wg sync.WaitGroup
key := util.GenerateID() key := util.GenerateID()
stdinKey := streamKey(c.id, "attach-"+key, Stdin) stdinKey := streamKey(c.id, "attach-"+key, Stdin)
@ -202,21 +185,33 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
if opts.Stdout != nil { if opts.Stdout != nil {
wg.Add(1) wg.Add(1)
wc, close := cioutil.NewWriteCloseInformer(opts.Stdout) wc, close := cioutil.NewWriteCloseInformer(opts.Stdout)
if err := c.stdoutGroup.Add(stdoutKey, wc); err != nil { c.stdoutGroup.Add(stdoutKey, wc)
return err
}
go attachStream(stdoutKey, close) go attachStream(stdoutKey, close)
} }
if !opts.Tty && opts.Stderr != nil { if !opts.Tty && opts.Stderr != nil {
wg.Add(1) wg.Add(1)
wc, close := cioutil.NewWriteCloseInformer(opts.Stderr) wc, close := cioutil.NewWriteCloseInformer(opts.Stderr)
if err := c.stderrGroup.Add(stderrKey, wc); err != nil { c.stderrGroup.Add(stderrKey, wc)
return err
}
go attachStream(stderrKey, close) go attachStream(stderrKey, close)
} }
wg.Wait() 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. // Cancel cancels container io.

View File

@ -161,11 +161,11 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir
} }
containerIO, err = cio.NewContainerIO(id, containerIO, err = cio.NewContainerIO(id,
cio.WithFIFOs(fifos), cio.WithFIFOs(fifos),
cio.WithOutput("log", stdoutWC, stderrWC),
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
containerIO.AddOutput("log", stdoutWC, stderrWC)
containerIO.Pipe() containerIO.Pipe()
return containerIO, nil return containerIO, nil
}) })

View File

@ -262,8 +262,21 @@ func (c *criContainerdService) Run(startGRPC bool) error {
<-eventMonitorCloseCh <-eventMonitorCloseCh
logrus.Info("Event monitor stopped") logrus.Info("Event monitor stopped")
<-streamServerCloseCh // 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") logrus.Info("Stream server stopped")
case <-time.After(streamServerStopTimeout):
logrus.Errorf("Stream server is not stopped in %q", streamServerStopTimeout)
}
if startGRPC { if startGRPC {
// Only wait for grpc server close channel when grpc server is started. // Only wait for grpc server close channel when grpc server is started.
<-grpcServerCloseCh <-grpcServerCloseCh

View File

@ -39,7 +39,7 @@ type Container struct {
// Container IO // Container IO
IO *cio.ContainerIO IO *cio.ContainerIO
// StopCh is used to propagate the stop information of the container. // StopCh is used to propagate the stop information of the container.
store.StopCh *store.StopCh
} }
// Opts sets specific information to newly created Container. // 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) { func NewContainer(metadata Metadata, opts ...Opts) (Container, error) {
c := Container{ c := Container{
Metadata: metadata, Metadata: metadata,
StopCh: store.StopCh(make(chan struct{})), StopCh: store.NewStopCh(),
} }
for _, o := range opts { for _, o := range opts {
if err := o(&c); err != nil { if err := o(&c); err != nil {

View File

@ -37,7 +37,7 @@ type Sandbox struct {
// CNI network namespace client // CNI network namespace client
NetNS *NetNS NetNS *NetNS
// StopCh is used to propagate the stop information of the sandbox. // 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 // NewSandbox creates an internally used sandbox type. This functions reminds
@ -46,7 +46,7 @@ func NewSandbox(metadata Metadata, status Status) Sandbox {
s := Sandbox{ s := Sandbox{
Metadata: metadata, Metadata: metadata,
Status: StoreStatus(status), Status: StoreStatus(status),
StopCh: store.StopCh(make(chan struct{})), StopCh: store.NewStopCh(),
} }
if status.State == StateNotReady { if status.State == StateNotReady {
s.Stop() s.Stop()

View File

@ -16,15 +16,35 @@ limitations under the License.
package store package store
import "sync"
// StopCh is used to propagate the stop information of a container. // 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. // Stop close stopCh of the container.
func (ch StopCh) Stop() { func (s *StopCh) Stop() {
close(ch) 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. // Stopped return the stopCh of the container as a readonly channel.
func (ch StopCh) Stopped() <-chan struct{} { func (s *StopCh) Stopped() <-chan struct{} {
return ch return s.ch
} }

View File

@ -1,18 +1,24 @@
github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
github.com/blang/semver v3.1.0 github.com/blang/semver v3.1.0
github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd
github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895
github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089 github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089
github.com/containerd/containerd ee6ffdd91e8fd9ec2b9684fd385e81a16c40e99c github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e
github.com/containerd/continuity 1a794c0014a7b786879312d1dab309ba96ead8bc github.com/containerd/containerd 129167132c5e0dbd1b031badae201a432d1bd681
github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371
github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6
github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f
github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788 github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788
github.com/containernetworking/cni v0.6.0 github.com/containernetworking/cni v0.6.0
github.com/containernetworking/plugins v0.6.0 github.com/containernetworking/plugins v0.6.0
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6 github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
github.com/cri-o/ocicni 9b451e26eb7c694d564991fbf44f77d0afb9b03c github.com/cri-o/ocicni 9b451e26eb7c694d564991fbf44f77d0afb9b03c
github.com/davecgh/go-spew v1.1.0 github.com/davecgh/go-spew v1.1.0
github.com/dmcgowan/go-tar go1.10
github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621 github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621
github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00 github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098
github.com/docker/go-units v0.3.1 github.com/docker/go-units v0.3.1
github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528 github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528
github.com/emicklei/go-restful ff4f55a206334ef123e4f79bbf348980da81ca46 github.com/emicklei/go-restful ff4f55a206334ef123e4f79bbf348980da81ca46
@ -23,10 +29,12 @@ github.com/gogo/protobuf v0.5
github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed
github.com/golang/protobuf 1643683e1b54a9e88ad26d98f81400c8c9d9f4f9 github.com/golang/protobuf 1643683e1b54a9e88ad26d98f81400c8c9d9f4f9
github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55 github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55
github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
github.com/json-iterator/go 1.0.4 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/go-winio v0.4.5
github.com/Microsoft/hcsshim v0.6.7 github.com/Microsoft/hcsshim v0.6.7
github.com/opencontainers/go-digest 21dfd564fd89c944783d00d069f33e3e7123c448 github.com/opencontainers/go-digest 21dfd564fd89c944783d00d069f33e3e7123c448
@ -37,14 +45,20 @@ github.com/opencontainers/runtime-tools 6073aff4ac61897f75895123f7e24135204a404d
github.com/opencontainers/selinux 4a2974bf1ee960774ffd517717f1f45325af0206 github.com/opencontainers/selinux 4a2974bf1ee960774ffd517717f1f45325af0206
github.com/pkg/errors v0.8.0 github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.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/renstrom/dedent 020d11c3b9c0c7a3c2efcc8e5cf5b9ef7bcea21f
github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0 github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
github.com/sirupsen/logrus v1.0.0 github.com/sirupsen/logrus v1.0.0
github.com/spf13/cobra v0.0.1 github.com/spf13/cobra v0.0.1
github.com/spf13/pflag v1.0.0 github.com/spf13/pflag v1.0.0
github.com/stevvooe/ttrpc d4528379866b0ce7e9d71f3eb96f0582fc374577
github.com/stretchr/testify v1.1.4 github.com/stretchr/testify v1.1.4
github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16 github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
github.com/tchap/go-patricia 5ad6cdb7538b0097d5598c7e57f0a24072adf7dc github.com/tchap/go-patricia 5ad6cdb7538b0097d5598c7e57f0a24072adf7dc
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6 golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
golang.org/x/sys 314a259e304ff91bd6985da2a7149bbf91237993 https://github.com/golang/sys golang.org/x/sys 314a259e304ff91bd6985da2a7149bbf91237993 https://github.com/golang/sys