Merge pull request #547 from Random-Liu/glog-to-logrus

glog to logrus
This commit is contained in:
Lantao Liu 2018-01-17 19:26:31 -08:00 committed by GitHub
commit ca3b73899a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 336 additions and 249 deletions

View File

@ -107,7 +107,7 @@ sudo containerd
``` ```
2. Start `cri-containerd` as root in a second terminal: 2. Start `cri-containerd` as root in a second terminal:
```bash ```bash
sudo cri-containerd -v 2 --alsologtostderr sudo cri-containerd
``` ```
3. From the Kubernetes project directory startup a local cluster using `cri-containerd`: 3. From the Kubernetes project directory startup a local cluster using `cri-containerd`:
```bash ```bash

View File

@ -82,7 +82,7 @@ write_files:
# cri-containerd on master uses the cni binary and config in the # cri-containerd on master uses the cni binary and config in the
# release tarball. # release tarball.
ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \ ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \
--logtostderr --v=4 \ --log-level=debug \
--network-bin-dir=/home/cri-containerd/opt/cni/bin \ --network-bin-dir=/home/cri-containerd/opt/cni/bin \
--network-conf-dir=/home/cri-containerd/etc/cni/net.d --network-conf-dir=/home/cri-containerd/etc/cni/net.d

View File

@ -85,7 +85,7 @@ write_files:
# Point to /home/kubernetes/bin where calico setup cni binary in kube-up.sh. # Point to /home/kubernetes/bin where calico setup cni binary in kube-up.sh.
# Point to /etc/cni/net.d where calico put cni config in kube-up.sh. # Point to /etc/cni/net.d where calico put cni config in kube-up.sh.
ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \ ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \
--logtostderr --v=4 \ --log-level=debug \
--network-bin-dir=/home/kubernetes/bin \ --network-bin-dir=/home/kubernetes/bin \
--network-conf-dir=/etc/cni/net.d --network-conf-dir=/etc/cni/net.d

View File

@ -27,12 +27,13 @@ import (
"runtime" "runtime"
"syscall" "syscall"
"github.com/golang/glog"
"github.com/opencontainers/selinux/go-selinux" "github.com/opencontainers/selinux/go-selinux"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/util/interrupt" "k8s.io/kubernetes/pkg/util/interrupt"
"github.com/containerd/cri-containerd/cmd/cri-containerd/options" "github.com/containerd/cri-containerd/cmd/cri-containerd/options"
"github.com/containerd/cri-containerd/pkg/log"
"github.com/containerd/cri-containerd/pkg/server" "github.com/containerd/cri-containerd/pkg/server"
"github.com/containerd/cri-containerd/pkg/version" "github.com/containerd/cri-containerd/pkg/version"
) )
@ -53,11 +54,6 @@ var cmd = &cobra.Command{
Long: desc, Long: desc,
} }
// Add golang flags as persistent flags.
func init() {
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
}
func defaultConfigCommand() *cobra.Command { func defaultConfigCommand() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "default-config", Use: "default-config",
@ -93,15 +89,19 @@ func main() {
} }
validateConfig(o) validateConfig(o)
glog.V(0).Infof("Run cri-containerd %+v", o) if err := setLogLevel(o.LogLevel); err != nil {
return fmt.Errorf("failed to set log level: %v", err)
}
logrus.Infof("Run cri-containerd %+v", o)
// Start profiling server if enable. // Start profiling server if enable.
if o.EnableProfiling { if o.EnableProfiling {
glog.V(2).Info("Start profiling server") logrus.Info("Start profiling server")
go startProfilingServer(o.ProfilingAddress, o.ProfilingPort) go startProfilingServer(o.ProfilingAddress, o.ProfilingPort)
} }
glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.SocketPath) logrus.Infof("Run cri-containerd grpc server on socket %q", o.SocketPath)
s, err := server.NewCRIContainerdService(o.Config) s, err := server.NewCRIContainerdService(o.Config)
if err != nil { if err != nil {
return fmt.Errorf("failed to create CRI containerd service: %v", err) return fmt.Errorf("failed to create CRI containerd service: %v", err)
@ -125,7 +125,7 @@ func main() {
func validateConfig(o *options.CRIContainerdOptions) { func validateConfig(o *options.CRIContainerdOptions) {
if o.EnableSelinux { if o.EnableSelinux {
if !selinux.GetEnabled() { if !selinux.GetEnabled() {
glog.Warning("Selinux is not supported") logrus.Warn("Selinux is not supported")
} }
} else { } else {
selinux.SetDisabled() selinux.SetDisabled()
@ -152,7 +152,7 @@ func dumpStacks() {
} }
buf = make([]byte, 2*len(buf)) buf = make([]byte, 2*len(buf))
} }
glog.V(0).Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
} }
// startProfilingServer start http server to profiling via web interface // startProfilingServer start http server to profiling via web interface
@ -164,6 +164,39 @@ func startProfilingServer(host string, port string) {
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace) mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
if err := http.ListenAndServe(endpoint, mux); err != nil { if err := http.ListenAndServe(endpoint, mux); err != nil {
glog.Errorf("Failed to start profiling server: %v", err) logrus.WithError(err).Error("Failed to start profiling server")
} }
} }
func setLogLevel(l string) error {
lvl, err := log.ParseLevel(l)
if err != nil {
return err
}
if err := setGLogLevel(lvl); err != nil {
return err
}
logrus.SetLevel(lvl)
return nil
}
// TODO(random-liu): Set glog level in plugin mode.
func setGLogLevel(l logrus.Level) error {
if err := flag.Set("logtostderr", "true"); err != nil {
return err
}
switch l {
case log.TraceLevel:
return flag.Set("v", "5")
case logrus.DebugLevel:
return flag.Set("v", "4")
case logrus.InfoLevel:
return flag.Set("v", "2")
// glog doesn't support following filters. Defaults to v=0.
case logrus.WarnLevel:
case logrus.ErrorLevel:
case logrus.FatalLevel:
case logrus.PanicLevel:
}
return nil
}

View File

@ -99,13 +99,15 @@ type Config struct {
// SkipImageFSUUID skips retrieving imagefs uuid. // SkipImageFSUUID skips retrieving imagefs uuid.
// TODO(random-liu): Remove this after we find a generic way to get imagefs uuid. // TODO(random-liu): Remove this after we find a generic way to get imagefs uuid.
SkipImageFSUUID bool `toml:"skip_imagefs_uuid" json:"skipImageFSUUID,omitempty"` SkipImageFSUUID bool `toml:"skip_imagefs_uuid" json:"skipImageFSUUID,omitempty"`
// LogLevel is the logrus log level.
LogLevel string `toml:"log_level" json:"logLevel,omitempty"`
} }
// CRIContainerdOptions contains cri-containerd command line and toml options. // CRIContainerdOptions contains cri-containerd command line and toml options.
type CRIContainerdOptions struct { type CRIContainerdOptions struct {
// Config contains cri-containerd toml config // Config contains cri-containerd toml config
Config Config
// Path to the TOML config file. // ConfigFilePath is the path to the TOML config file.
ConfigFilePath string `toml:"-"` ConfigFilePath string `toml:"-"`
} }
@ -117,6 +119,8 @@ func NewCRIContainerdOptions() *CRIContainerdOptions {
// AddFlags adds cri-containerd command line options to pflag. // AddFlags adds cri-containerd command line options to pflag.
func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) { func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
defaults := DefaultConfig() defaults := DefaultConfig()
fs.StringVar(&c.LogLevel, "log-level",
"info", "Set the logging level [trace, debug, info, warn, error, fatal, panic].")
fs.StringVar(&c.ConfigFilePath, configFilePathArgName, fs.StringVar(&c.ConfigFilePath, configFilePathArgName,
defaultConfigFilePath, "Path to the config file.") defaultConfigFilePath, "Path to the config file.")
fs.StringVar(&c.SocketPath, "socket-path", fs.StringVar(&c.SocketPath, "socket-path",

View File

@ -11,7 +11,7 @@ LimitNOFILE=1048576
# in the kernel. We recommend using cgroups to do container-local accounting. # in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity LimitNPROC=infinity
LimitCORE=infinity LimitCORE=infinity
ExecStart=/usr/local/bin/cri-containerd --logtostderr ExecStart=/usr/local/bin/cri-containerd
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

13
cri.go
View File

@ -17,8 +17,8 @@ limitations under the License.
package cri package cri
import ( import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/golang/glog"
"github.com/containerd/cri-containerd/cmd/cri-containerd/options" "github.com/containerd/cri-containerd/cmd/cri-containerd/options"
"github.com/containerd/cri-containerd/pkg/server" "github.com/containerd/cri-containerd/pkg/server"
@ -43,27 +43,28 @@ func init() {
}) })
} }
func initCRIService(_ *plugin.InitContext) (interface{}, error) { func initCRIService(ic *plugin.InitContext) (interface{}, error) {
ctx := ic.Context
// TODO(random-liu): Support Config through Registration.Config. // TODO(random-liu): Support Config through Registration.Config.
// TODO(random-liu): Validate the configuration. // TODO(random-liu): Validate the configuration.
// TODO(random-liu): Leverage other fields in InitContext, such as Root. // TODO(random-liu): Leverage other fields in InitContext, such as Root.
// TODO(random-liu): Register GRPC service onto containerd GRPC server. // TODO(random-liu): Register GRPC service onto containerd GRPC server.
// TODO(random-liu): Separate cri plugin config from cri-containerd server config, // TODO(random-liu): Separate cri plugin config from cri-containerd server config,
// because many options only make sense to cri-containerd server. // because many options only make sense to cri-containerd server.
// TODO(random-liu): Change all glog to logrus.
// TODO(random-liu): Handle graceful stop. // TODO(random-liu): Handle graceful stop.
// TODO(random-liu): Make grpc interceptor pluggable, and add and use cri context.
c := options.DefaultConfig() c := options.DefaultConfig()
glog.V(0).Infof("Start cri plugin with config %+v", c) log.G(ctx).Infof("Start cri plugin with config %+v", c)
// Use a goroutine to start cri service. The reason is that currently // Use a goroutine to start cri service. The reason is that currently
// cri service requires containerd to be running. // cri service requires containerd to be running.
// TODO(random-liu): Resolve the circular dependency. // TODO(random-liu): Resolve the circular dependency.
go func() { go func() {
s, err := server.NewCRIContainerdService(c) s, err := server.NewCRIContainerdService(c)
if err != nil { if err != nil {
glog.Exitf("Failed to create CRI service: %v", err) log.G(ctx).WithError(err).Fatal("Failed to create CRI service")
} }
if err := s.Run(); err != nil { if err := s.Run(); err != nil {
glog.Exitf("Failed to run CRI grpc server: %v", err) log.G(ctx).WithError(err).Fatal("Failed to run CRI grpc server")
} }
}() }()
return nil, nil return nil, nil

View File

@ -51,7 +51,7 @@ test_setup() {
# Start cri-containerd # Start cri-containerd
if ${STANDALONE_CRI_CONTAINERD}; then if ${STANDALONE_CRI_CONTAINERD}; then
keepalive "sudo ${ROOT}/_output/cri-containerd --alsologtostderr --v 4 ${CRI_CONTAINERD_FLAGS}" \ keepalive "sudo ${ROOT}/_output/cri-containerd --log-level=debug ${CRI_CONTAINERD_FLAGS}" \
${RESTART_WAIT_PERIOD} &> ${report_dir}/cri-containerd.log & ${RESTART_WAIT_PERIOD} &> ${report_dir}/cri-containerd.log &
cri_containerd_pid=$! cri_containerd_pid=$!
fi fi

View File

@ -23,7 +23,7 @@ import (
"time" "time"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/kubelet/apis/cri" "k8s.io/kubernetes/pkg/kubelet/apis/cri"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/remote" "k8s.io/kubernetes/pkg/kubelet/remote"
@ -53,7 +53,7 @@ var (
func init() { func init() {
if err := ConnectDaemons(); err != nil { if err := ConnectDaemons(); err != nil {
glog.Exitf("Failed to connect daemons: %v", err) logrus.WithError(err).Fatalf("Failed to connect daemons")
} }
} }

View File

@ -27,8 +27,8 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/fs" "github.com/containerd/containerd/fs"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/golang/glog"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
) )
// WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the // WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the
@ -81,7 +81,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
} }
defer func() { defer func() {
if uerr := mount.Unmount(root, 0); uerr != nil { if uerr := mount.Unmount(root, 0); uerr != nil {
glog.Errorf("Failed to unmount snapshot %q: %v", c.SnapshotKey, uerr) logrus.WithError(uerr).Errorf("Failed to unmount snapshot %q", c.SnapshotKey)
if err == nil { if err == nil {
err = uerr err = uerr
} }

46
pkg/log/log.go Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright 2018 The Containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package log
import "github.com/sirupsen/logrus"
// TODO(random-liu): Add trace support in containerd.
// TraceLevel is the log level for trace.
const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1))
// ParseLevel takes a string level and returns the Logrus log level constant.
func ParseLevel(lvl string) (logrus.Level, error) {
if lvl == "trace" {
return TraceLevel, nil
}
return logrus.ParseLevel(lvl)
}
// Trace logs a message at level Trace on the standard logger.
func Trace(args ...interface{}) {
if logrus.GetLevel() >= TraceLevel {
logrus.Debug(args...)
}
}
// Tracef logs a message at level Trace on the standard logger.
func Tracef(format string, args ...interface{}) {
if logrus.GetLevel() >= TraceLevel {
logrus.Debugf(format, args...)
}
}

View File

@ -21,7 +21,7 @@ import (
"io" "io"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -62,7 +62,7 @@ func (c *criContainerdService) attachContainer(ctx context.Context, id string, s
} }
handleResizing(resize, func(size remotecommand.TerminalSize) { handleResizing(resize, func(size remotecommand.TerminalSize) {
if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil { if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
glog.Errorf("Failed to resize task %q console: %v", id, err) logrus.WithError(err).Errorf("Failed to resize task %q console", id)
} }
}) })

View File

@ -33,13 +33,13 @@ import (
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/golang/glog"
imagespec "github.com/opencontainers/image-spec/specs-go/v1" imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/runc/libcontainer/devices" "github.com/opencontainers/runc/libcontainer/devices"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/runtime-tools/validate" "github.com/opencontainers/runtime-tools/validate"
"github.com/opencontainers/selinux/go-selinux/label" "github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"github.com/syndtr/gocapability/capability" "github.com/syndtr/gocapability/capability"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -92,7 +92,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
// the same container. // the same container.
id := util.GenerateID() id := util.GenerateID()
name := makeContainerName(config.GetMetadata(), sandboxConfig.GetMetadata()) name := makeContainerName(config.GetMetadata(), sandboxConfig.GetMetadata())
glog.V(4).Infof("Generated id %q for container %q", id, name) logrus.Debugf("Generated id %q for container %q", id, name)
if err = c.containerNameIndex.Reserve(name, id); err != nil { if err = c.containerNameIndex.Reserve(name, id); err != nil {
return nil, fmt.Errorf("failed to reserve container name %q: %v", name, err) return nil, fmt.Errorf("failed to reserve container name %q: %v", name, err)
} }
@ -132,8 +132,8 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
if retErr != nil { if retErr != nil {
// Cleanup the container root directory. // Cleanup the container root directory.
if err = c.os.RemoveAll(containerRootDir); err != nil { if err = c.os.RemoveAll(containerRootDir); err != nil {
glog.Errorf("Failed to remove container root directory %q: %v", logrus.WithError(err).Errorf("Failed to remove container root directory %q",
containerRootDir, err) containerRootDir)
} }
} }
}() }()
@ -149,7 +149,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err) return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err)
} }
glog.V(4).Infof("Container %q spec: %#+v", id, spew.NewFormatter(spec)) logrus.Debugf("Container %q spec: %#+v", id, spew.NewFormatter(spec))
// Set snapshotter before any other options. // Set snapshotter before any other options.
opts := []containerd.NewContainerOpts{ opts := []containerd.NewContainerOpts{
@ -184,7 +184,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err := containerIO.Close(); err != nil { if err := containerIO.Close(); err != nil {
glog.Errorf("Failed to close container io %q : %v", id, err) logrus.WithError(err).Errorf("Failed to close container io %q", id)
} }
} }
}() }()
@ -241,7 +241,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err := cntr.Delete(ctx, containerd.WithSnapshotCleanup); err != nil { if err := cntr.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
glog.Errorf("Failed to delete containerd container %q: %v", id, err) logrus.WithError(err).Errorf("Failed to delete containerd container %q", id)
} }
} }
}() }()
@ -260,7 +260,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
if retErr != nil { if retErr != nil {
// Cleanup container checkpoint on error. // Cleanup container checkpoint on error.
if err := container.Delete(); err != nil { if err := container.Delete(); err != nil {
glog.Errorf("Failed to cleanup container checkpoint for %q: %v", id, err) logrus.WithError(err).Errorf("Failed to cleanup container checkpoint for %q", id)
} }
} }
}() }()
@ -603,7 +603,7 @@ func (c *criContainerdService) addOCIBindMounts(g *generate.Generator, mounts []
g.SetLinuxRootPropagation("rslave") // nolint: errcheck g.SetLinuxRootPropagation("rslave") // nolint: errcheck
} }
default: default:
glog.Warningf("Unknown propagation mode for hostPath %q", mount.HostPath) logrus.Warnf("Unknown propagation mode for hostPath %q", mount.HostPath)
options = append(options, "rprivate") options = append(options, "rprivate")
} }

View File

@ -25,7 +25,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
containerdio "github.com/containerd/containerd/cio" containerdio "github.com/containerd/containerd/cio"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
@ -114,7 +114,7 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o
opts.stderr = cio.NewDiscardLogger() opts.stderr = cio.NewDiscardLogger()
} }
execID := util.GenerateID() execID := util.GenerateID()
glog.V(4).Infof("Generated exec id %q for container %q", execID, id) logrus.Debugf("Generated exec id %q for container %q", execID, id)
rootDir := getContainerRootDir(c.config.RootDir, id) rootDir := getContainerRootDir(c.config.RootDir, id)
var execIO *cio.ExecIO var execIO *cio.ExecIO
process, err := task.Exec(ctx, execID, pspec, process, err := task.Exec(ctx, execID, pspec,
@ -129,7 +129,7 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o
} }
defer func() { defer func() {
if _, err := process.Delete(ctx); err != nil { if _, err := process.Delete(ctx); err != nil {
glog.Errorf("Failed to delete exec process %q for container %q: %v", execID, id, err) logrus.WithError(err).Errorf("Failed to delete exec process %q for container %q", execID, id)
} }
}() }()
@ -143,7 +143,7 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o
handleResizing(opts.resize, func(size remotecommand.TerminalSize) { handleResizing(opts.resize, func(size remotecommand.TerminalSize) {
if err := process.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil { if err := process.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil {
glog.Errorf("Failed to resize process %q console for container %q: %v", execID, id, err) logrus.WithError(err).Errorf("Failed to resize process %q console for container %q", execID, id)
} }
}) })
@ -174,19 +174,19 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o
} }
// Wait for the process to be killed. // Wait for the process to be killed.
exitRes := <-exitCh exitRes := <-exitCh
glog.V(2).Infof("Timeout received while waiting for exec process kill %q code %d and error %v", logrus.Infof("Timeout received while waiting for exec process kill %q code %d and error %v",
execID, exitRes.ExitCode(), exitRes.Error()) execID, exitRes.ExitCode(), exitRes.Error())
<-attachDone <-attachDone
glog.V(4).Infof("Stream pipe for exec process %q done", execID) logrus.Debugf("Stream pipe for exec process %q done", execID)
return nil, fmt.Errorf("timeout %v exceeded", opts.timeout) return nil, fmt.Errorf("timeout %v exceeded", opts.timeout)
case exitRes := <-exitCh: case exitRes := <-exitCh:
code, _, err := exitRes.Result() code, _, err := exitRes.Result()
glog.V(2).Infof("Exec process %q exits with exit code %d and error %v", execID, code, err) logrus.Infof("Exec process %q exits with exit code %d and error %v", execID, code, err)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed while waiting for exec %q: %v", execID, err) return nil, fmt.Errorf("failed while waiting for exec %q: %v", execID, err)
} }
<-attachDone <-attachDone
glog.V(4).Infof("Stream pipe for exec process %q done", execID) logrus.Debugf("Stream pipe for exec process %q done", execID)
return &code, nil return &code, nil
} }
} }

View File

@ -22,10 +22,11 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"github.com/containerd/cri-containerd/pkg/log"
"github.com/containerd/cri-containerd/pkg/store" "github.com/containerd/cri-containerd/pkg/store"
containerstore "github.com/containerd/cri-containerd/pkg/store/container" containerstore "github.com/containerd/cri-containerd/pkg/store/container"
) )
@ -39,7 +40,7 @@ func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.R
return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err) return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err)
} }
// Do not return error if container metadata doesn't exist. // Do not return error if container metadata doesn't exist.
glog.V(5).Infof("RemoveContainer called for container %q that does not exist", r.GetContainerId()) log.Tracef("RemoveContainer called for container %q that does not exist", r.GetContainerId())
return &runtime.RemoveContainerResponse{}, nil return &runtime.RemoveContainerResponse{}, nil
} }
id := container.ID id := container.ID
@ -53,7 +54,7 @@ func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.R
if retErr != nil { if retErr != nil {
// Reset removing if remove failed. // Reset removing if remove failed.
if err := resetContainerRemoving(container); err != nil { if err := resetContainerRemoving(container); err != nil {
glog.Errorf("failed to reset removing state for container %q: %v", id, err) logrus.WithError(err).Errorf("failed to reset removing state for container %q", id)
} }
} }
}() }()
@ -68,7 +69,7 @@ func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.R
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("failed to delete containerd container %q: %v", id, err) return nil, fmt.Errorf("failed to delete containerd container %q: %v", id, err)
} }
glog.V(5).Infof("Remove called for containerd container %q that does not exist", id, err) log.Tracef("Remove called for containerd container %q that does not exist", id)
} }
// Delete container checkpoint. // Delete container checkpoint.

View File

@ -23,7 +23,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
containerdio "github.com/containerd/containerd/cio" containerdio "github.com/containerd/containerd/cio"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -133,7 +133,7 @@ func (c *criContainerdService) startContainer(ctx context.Context,
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil { if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil {
glog.Errorf("Failed to delete containerd task %q: %v", id, err) logrus.WithError(err).Errorf("Failed to delete containerd task %q", id)
} }
} }
}() }()

View File

@ -20,8 +20,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/golang/glog"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -131,7 +131,7 @@ func toCRIContainerInfo(ctx context.Context, container containerstore.Container,
if err == nil { if err == nil {
ci.RuntimeSpec = spec ci.RuntimeSpec = spec
} else { } else {
glog.Errorf("Failed to get container %q spec: %v", container.ID, err) logrus.WithError(err).Errorf("Failed to get container %q spec", container.ID)
} }
ctrInfo, err := container.Container.Info(ctx) ctrInfo, err := container.Container.Info(ctx)
@ -139,7 +139,7 @@ func toCRIContainerInfo(ctx context.Context, container containerstore.Container,
ci.SnapshotKey = ctrInfo.SnapshotKey ci.SnapshotKey = ctrInfo.SnapshotKey
ci.Snapshotter = ctrInfo.Snapshotter ci.Snapshotter = ctrInfo.Snapshotter
} else { } else {
glog.Errorf("Failed to get container %q info: %v", container.ID, err) logrus.WithError(err).Errorf("Failed to get container %q info", container.ID)
} }
infoBytes, err := json.Marshal(ci) infoBytes, err := json.Marshal(ci)

View File

@ -23,7 +23,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -65,7 +65,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
// stop only takes real action after the container is started. // stop only takes real action after the container is started.
state := container.Status.Get().State() state := container.Status.Get().State()
if state != runtime.ContainerState_CONTAINER_RUNNING { if state != runtime.ContainerState_CONTAINER_RUNNING {
glog.V(2).Infof("Container to stop %q is not running, current state %q", logrus.Infof("Container to stop %q is not running, current state %q",
id, criContainerStateToString(state)) id, criContainerStateToString(state))
return nil return nil
} }
@ -87,7 +87,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
image.ImageSpec.Config.StopSignal, err) image.ImageSpec.Config.StopSignal, err)
} }
} }
glog.V(2).Infof("Stop container %q with signal %v", id, stopSignal) logrus.Infof("Stop container %q with signal %v", id, stopSignal)
task, err := container.Container.Task(ctx, nil) task, err := container.Container.Task(ctx, nil)
if err != nil { if err != nil {
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
@ -108,7 +108,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
if err == nil { if err == nil {
return nil return nil
} }
glog.Errorf("Stop container %q timed out: %v", id, err) logrus.WithError(err).Errorf("Stop container %q timed out", id)
} }
task, err := container.Container.Task(ctx, nil) task, err := container.Container.Task(ctx, nil)
@ -119,7 +119,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
return nil return nil
} }
// Event handler will Delete the container from containerd after it handles the Exited event. // Event handler will Delete the container from containerd after it handles the Exited event.
glog.V(2).Infof("Kill container %q", id) logrus.Infof("Kill container %q", id)
if task != nil { if task != nil {
if err = task.Kill(ctx, unix.SIGKILL, containerd.WithKillAll); err != nil { if err = task.Kill(ctx, unix.SIGKILL, containerd.WithKillAll); err != nil {
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
@ -151,7 +151,7 @@ func (c *criContainerdService) waitContainerStop(ctx context.Context, id string,
} }
// Do not return error here because container was removed means // Do not return error here because container was removed means
// it is already stopped. // it is already stopped.
glog.Warningf("Container %q was removed during stopping", id) logrus.Warnf("Container %q was removed during stopping", id)
return nil return nil
} }
// TODO(random-liu): Use channel with event handler instead of polling. // TODO(random-liu): Use channel with event handler instead of polling.

View File

@ -24,8 +24,8 @@ import (
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/golang/glog"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -80,7 +80,7 @@ func (c *criContainerdService) updateContainerResources(ctx context.Context,
if retErr != nil { if retErr != nil {
// Reset spec on error. // Reset spec on error.
if err := updateContainerSpec(ctx, cntr.Container, oldSpec); err != nil { if err := updateContainerSpec(ctx, cntr.Container, oldSpec); err != nil {
glog.Errorf("Failed to update spec %+v for container %q: %v", oldSpec, id, err) logrus.WithError(err).Errorf("Failed to update spec %+v for container %q", oldSpec, id)
} }
} }
}() }()

View File

@ -22,7 +22,7 @@ import (
containerdio "github.com/containerd/containerd/cio" containerdio "github.com/containerd/containerd/cio"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
containerstore "github.com/containerd/cri-containerd/pkg/store/container" containerstore "github.com/containerd/cri-containerd/pkg/store/container"
@ -59,10 +59,10 @@ func (em *eventMonitor) start() <-chan struct{} {
for { for {
select { select {
case e := <-em.ch: case e := <-em.ch:
glog.V(4).Infof("Received container event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic) logrus.Debugf("Received container event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic)
em.handleEvent(e) em.handleEvent(e)
case err := <-em.errCh: case err := <-em.errCh:
glog.Errorf("Failed to handle event stream: %v", err) logrus.WithError(err).Error("Failed to handle event stream")
close(em.closeCh) close(em.closeCh)
return return
} }
@ -81,7 +81,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) {
c := em.c c := em.c
any, err := typeurl.UnmarshalAny(evt.Event) any, err := typeurl.UnmarshalAny(evt.Event)
if err != nil { if err != nil {
glog.Errorf("Failed to convert event envelope %+v: %v", evt, err) logrus.WithError(err).Errorf("Failed to convert event envelope %+v", evt)
return return
} }
switch any.(type) { switch any.(type) {
@ -91,13 +91,13 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) {
// TODO(random-liu): [P2] Handle containerd-shim exit. // TODO(random-liu): [P2] Handle containerd-shim exit.
case *eventtypes.TaskExit: case *eventtypes.TaskExit:
e := any.(*eventtypes.TaskExit) e := any.(*eventtypes.TaskExit)
glog.V(2).Infof("TaskExit event %+v", e) logrus.Infof("TaskExit event %+v", e)
cntr, err := c.containerStore.Get(e.ContainerID) cntr, err := c.containerStore.Get(e.ContainerID)
if err != nil { if err != nil {
if _, err := c.sandboxStore.Get(e.ContainerID); err == nil { if _, err := c.sandboxStore.Get(e.ContainerID); err == nil {
return return
} }
glog.Errorf("Failed to get container %q: %v", e.ContainerID, err) logrus.WithError(err).Errorf("Failed to get container %q", e.ContainerID)
return return
} }
if e.Pid != cntr.Status.Get().Pid { if e.Pid != cntr.Status.Get().Pid {
@ -112,7 +112,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) {
) )
if err != nil { if err != nil {
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
glog.Errorf("failed to stop container, task not found for container %q: %v", e.ContainerID, err) logrus.WithError(err).Errorf("failed to stop container, task not found for container %q", e.ContainerID)
return return
} }
} else { } else {
@ -120,7 +120,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) {
if _, err = task.Delete(context.Background()); err != nil { if _, err = task.Delete(context.Background()); err != nil {
// TODO(random-liu): [P0] Enqueue the event and retry. // TODO(random-liu): [P0] Enqueue the event and retry.
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
glog.Errorf("failed to stop container %q: %v", e.ContainerID, err) logrus.WithError(err).Errorf("failed to stop container %q", e.ContainerID)
return return
} }
// Move on to make sure container status is updated. // Move on to make sure container status is updated.
@ -138,26 +138,26 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) {
return status, nil return status, nil
}) })
if err != nil { if err != nil {
glog.Errorf("Failed to update container %q state: %v", e.ContainerID, err) logrus.WithError(err).Errorf("Failed to update container %q state", e.ContainerID)
// TODO(random-liu): [P0] Enqueue the event and retry. // TODO(random-liu): [P0] Enqueue the event and retry.
return return
} }
case *eventtypes.TaskOOM: case *eventtypes.TaskOOM:
e := any.(*eventtypes.TaskOOM) e := any.(*eventtypes.TaskOOM)
glog.V(2).Infof("TaskOOM event %+v", e) logrus.Infof("TaskOOM event %+v", e)
cntr, err := c.containerStore.Get(e.ContainerID) cntr, err := c.containerStore.Get(e.ContainerID)
if err != nil { if err != nil {
if _, err := c.sandboxStore.Get(e.ContainerID); err == nil { if _, err := c.sandboxStore.Get(e.ContainerID); err == nil {
return return
} }
glog.Errorf("Failed to get container %q: %v", e.ContainerID, err) logrus.WithError(err).Errorf("Failed to get container %q", e.ContainerID)
} }
err = cntr.Status.UpdateSync(func(status containerstore.Status) (containerstore.Status, error) { err = cntr.Status.UpdateSync(func(status containerstore.Status) (containerstore.Status, error) {
status.Reason = oomExitReason status.Reason = oomExitReason
return status, nil return status, nil
}) })
if err != nil { if err != nil {
glog.Errorf("Failed to update container %q oom: %v", e.ContainerID, err) logrus.WithError(err).Errorf("Failed to update container %q oom", e.ContainerID)
return return
} }
} }

View File

@ -22,7 +22,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/golang/glog" "github.com/sirupsen/logrus"
api "github.com/containerd/cri-containerd/pkg/api/v1" api "github.com/containerd/cri-containerd/pkg/api/v1"
"github.com/containerd/cri-containerd/pkg/containerd/importer" "github.com/containerd/cri-containerd/pkg/containerd/importer"
@ -49,7 +49,7 @@ func (c *criContainerdService) LoadImage(ctx context.Context, r *api.LoadImageRe
return nil, fmt.Errorf("failed to get image %q: %v", repoTag, err) return nil, fmt.Errorf("failed to get image %q: %v", repoTag, err)
} }
if err := image.Unpack(ctx, c.config.ContainerdConfig.Snapshotter); err != nil { if err := image.Unpack(ctx, c.config.ContainerdConfig.Snapshotter); err != nil {
glog.Warningf("Failed to unpack image %q: %v", repoTag, err) logrus.WithError(err).Warnf("Failed to unpack image %q", repoTag)
// Do not fail image importing. Unpack will be retried when container creation. // Do not fail image importing. Unpack will be retried when container creation.
} }
info, err := getImageInfo(ctx, image) info, err := getImageInfo(ctx, image)
@ -74,7 +74,7 @@ func (c *criContainerdService) LoadImage(ctx context.Context, r *api.LoadImageRe
if err := c.imageStore.Add(img); err != nil { if err := c.imageStore.Add(img); err != nil {
return nil, fmt.Errorf("failed to add image %q into store: %v", id, err) return nil, fmt.Errorf("failed to add image %q into store: %v", id, err)
} }
glog.V(4).Infof("Imported image with id %q, repo tag %q", id, repoTag) logrus.Debugf("Imported image with id %q, repo tag %q", id, repoTag)
} }
return &api.LoadImageResponse{Images: repoTags}, nil return &api.LoadImageResponse{Images: repoTags}, nil
} }

View File

@ -26,8 +26,8 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
containerdimages "github.com/containerd/containerd/images" containerdimages "github.com/containerd/containerd/images"
"github.com/containerd/containerd/remotes/docker" "github.com/containerd/containerd/remotes/docker"
"github.com/golang/glog"
imagespec "github.com/opencontainers/image-spec/specs-go/v1" imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -86,7 +86,7 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
// TODO(random-liu): [P0] Avoid concurrent pulling/removing on the same image reference. // TODO(random-liu): [P0] Avoid concurrent pulling/removing on the same image reference.
ref := namedRef.String() ref := namedRef.String()
if ref != imageRef { if ref != imageRef {
glog.V(4).Infof("PullImage using normalized image ref: %q", ref) logrus.Debugf("PullImage using normalized image ref: %q", ref)
} }
resolver := docker.NewResolver(docker.ResolverOptions{ resolver := docker.NewResolver(docker.ResolverOptions{
@ -111,9 +111,9 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
} }
// Do best effort unpack. // Do best effort unpack.
glog.V(4).Infof("Unpack image %q", imageRef) logrus.Debugf("Unpack image %q", imageRef)
if err := image.Unpack(ctx, c.config.ContainerdConfig.Snapshotter); err != nil { if err := image.Unpack(ctx, c.config.ContainerdConfig.Snapshotter); err != nil {
glog.Warningf("Failed to unpack image %q: %v", imageRef, err) logrus.WithError(err).Warnf("Failed to unpack image %q", imageRef)
// Do not fail image pulling. Unpack will be retried before container creation. // Do not fail image pulling. Unpack will be retried before container creation.
} }
@ -134,7 +134,7 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
} }
} }
glog.V(4).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID, logrus.Debugf("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
repoTag, repoDigest) repoTag, repoDigest)
img := imagestore.Image{ img := imagestore.Image{
ID: imageID, ID: imageID,

View File

@ -21,7 +21,7 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
) )
@ -64,13 +64,13 @@ func (c *criContainerdService) RemoveImage(ctx context.Context, r *runtime.Remov
// but different ids generated from compressed contents - manifest digest. // but different ids generated from compressed contents - manifest digest.
// So we decide to leave it. // So we decide to leave it.
// After all, the user can override the repoTag by pulling image again. // After all, the user can override the repoTag by pulling image again.
glog.Errorf("Can't remove image,failed to get config for Image tag %q,id %q: %v", tag, image.ID, err) logrus.WithError(err).Errorf("Can't remove image,failed to get config for Image tag %q,id %q", tag, image.ID)
image.RepoTags = append(image.RepoTags[:i], image.RepoTags[i+1:]...) image.RepoTags = append(image.RepoTags[:i], image.RepoTags[i+1:]...)
continue continue
} }
cID := desc.Digest.String() cID := desc.Digest.String()
if cID != image.ID { if cID != image.ID {
glog.V(4).Infof("Image tag %q for %q is outdated, it's currently used by %q", tag, image.ID, cID) logrus.Debugf("Image tag %q for %q is outdated, it's currently used by %q", tag, image.ID, cID)
image.RepoTags = append(image.RepoTags[:i], image.RepoTags[i+1:]...) image.RepoTags = append(image.RepoTags[:i], image.RepoTags[i+1:]...)
continue continue
} }

View File

@ -20,7 +20,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -95,7 +95,7 @@ func (c *criContainerdService) toCRIImageInfo(ctx context.Context, image *images
if err == nil { if err == nil {
info["info"] = string(m) info["info"] = string(m)
} else { } else {
glog.Errorf("failed to marshal info %v: %v", imi, err) logrus.WithError(err).Errorf("failed to marshal info %v", imi)
info["info"] = err.Error() info["info"] = err.Error()
} }

View File

@ -17,11 +17,12 @@ limitations under the License.
package server package server
import ( import (
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
api "github.com/containerd/cri-containerd/pkg/api/v1" api "github.com/containerd/cri-containerd/pkg/api/v1"
"github.com/containerd/cri-containerd/pkg/log"
) )
// instrumentedService wraps service and logs each operation. // instrumentedService wraps service and logs each operation.
@ -34,86 +35,86 @@ func newInstrumentedService(c *criContainerdService) CRIContainerdService {
} }
func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (res *runtime.RunPodSandboxResponse, err error) { func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (res *runtime.RunPodSandboxResponse, err error) {
glog.V(2).Infof("RunPodSandbox with config %+v", r.GetConfig()) logrus.Infof("RunPodSandbox with config %+v", r.GetConfig())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("RunPodSandbox for %+v failed, error: %v", r.GetConfig().GetMetadata(), err) logrus.WithError(err).Errorf("RunPodSandbox for %+v failed, error", r.GetConfig().GetMetadata())
} else { } else {
glog.V(2).Infof("RunPodSandbox for %+v returns sandbox id %q", r.GetConfig().GetMetadata(), res.GetPodSandboxId()) logrus.Infof("RunPodSandbox for %+v returns sandbox id %q", r.GetConfig().GetMetadata(), res.GetPodSandboxId())
} }
}() }()
return in.criContainerdService.RunPodSandbox(ctx, r) return in.criContainerdService.RunPodSandbox(ctx, r)
} }
func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (res *runtime.ListPodSandboxResponse, err error) { func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (res *runtime.ListPodSandboxResponse, err error) {
glog.V(5).Infof("ListPodSandbox with filter %+v", r.GetFilter()) log.Tracef("ListPodSandbox with filter %+v", r.GetFilter())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ListPodSandbox failed, error: %v", err) logrus.WithError(err).Error("ListPodSandbox failed")
} else { } else {
glog.V(5).Infof("ListPodSandbox returns sandboxes %+v", res.GetItems()) log.Tracef("ListPodSandbox returns sandboxes %+v", res.GetItems())
} }
}() }()
return in.criContainerdService.ListPodSandbox(ctx, r) return in.criContainerdService.ListPodSandbox(ctx, r)
} }
func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (res *runtime.PodSandboxStatusResponse, err error) { func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (res *runtime.PodSandboxStatusResponse, err error) {
glog.V(5).Infof("PodSandboxStatus for %q", r.GetPodSandboxId()) log.Tracef("PodSandboxStatus for %q", r.GetPodSandboxId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("PodSandboxStatus for %q failed, error: %v", r.GetPodSandboxId(), err) logrus.WithError(err).Errorf("PodSandboxStatus for %q failed", r.GetPodSandboxId())
} else { } else {
glog.V(5).Infof("PodSandboxStatus for %q returns status %+v", r.GetPodSandboxId(), res.GetStatus()) log.Tracef("PodSandboxStatus for %q returns status %+v", r.GetPodSandboxId(), res.GetStatus())
} }
}() }()
return in.criContainerdService.PodSandboxStatus(ctx, r) return in.criContainerdService.PodSandboxStatus(ctx, r)
} }
func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (_ *runtime.StopPodSandboxResponse, err error) { func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (_ *runtime.StopPodSandboxResponse, err error) {
glog.V(2).Infof("StopPodSandbox for %q", r.GetPodSandboxId()) logrus.Infof("StopPodSandbox for %q", r.GetPodSandboxId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("StopPodSandbox for %q failed, error: %v", r.GetPodSandboxId(), err) logrus.WithError(err).Errorf("StopPodSandbox for %q failed", r.GetPodSandboxId())
} else { } else {
glog.V(2).Infof("StopPodSandbox for %q returns successfully", r.GetPodSandboxId()) logrus.Infof("StopPodSandbox for %q returns successfully", r.GetPodSandboxId())
} }
}() }()
return in.criContainerdService.StopPodSandbox(ctx, r) return in.criContainerdService.StopPodSandbox(ctx, r)
} }
func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (_ *runtime.RemovePodSandboxResponse, err error) { func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (_ *runtime.RemovePodSandboxResponse, err error) {
glog.V(2).Infof("RemovePodSandbox for %q", r.GetPodSandboxId()) logrus.Infof("RemovePodSandbox for %q", r.GetPodSandboxId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("RemovePodSandbox for %q failed, error: %v", r.GetPodSandboxId(), err) logrus.WithError(err).Errorf("RemovePodSandbox for %q failed", r.GetPodSandboxId())
} else { } else {
glog.V(2).Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId()) logrus.Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId())
} }
}() }()
return in.criContainerdService.RemovePodSandbox(ctx, r) return in.criContainerdService.RemovePodSandbox(ctx, r)
} }
func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (res *runtime.PortForwardResponse, err error) { func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (res *runtime.PortForwardResponse, err error) {
glog.V(2).Infof("Portforward for %q port %v", r.GetPodSandboxId(), r.GetPort()) logrus.Infof("Portforward for %q port %v", r.GetPodSandboxId(), r.GetPort())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("Portforward for %q failed, error: %v", r.GetPodSandboxId(), err) logrus.WithError(err).Errorf("Portforward for %q failed", r.GetPodSandboxId())
} else { } else {
glog.V(2).Infof("Portforward for %q returns URL %q", r.GetPodSandboxId(), res.GetUrl()) logrus.Infof("Portforward for %q returns URL %q", r.GetPodSandboxId(), res.GetUrl())
} }
}() }()
return in.criContainerdService.PortForward(ctx, r) return in.criContainerdService.PortForward(ctx, r)
} }
func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (res *runtime.CreateContainerResponse, err error) { func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (res *runtime.CreateContainerResponse, err error) {
glog.V(2).Infof("CreateContainer within sandbox %q with container config %+v and sandbox config %+v", logrus.Infof("CreateContainer within sandbox %q with container config %+v and sandbox config %+v",
r.GetPodSandboxId(), r.GetConfig(), r.GetSandboxConfig()) r.GetPodSandboxId(), r.GetConfig(), r.GetSandboxConfig())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("CreateContainer within sandbox %q for %+v failed, error: %v", logrus.WithError(err).Errorf("CreateContainer within sandbox %q for %+v failed",
r.GetPodSandboxId(), r.GetConfig().GetMetadata(), err) r.GetPodSandboxId(), r.GetConfig().GetMetadata())
} else { } else {
glog.V(2).Infof("CreateContainer within sandbox %q for %+v returns container id %q", logrus.Infof("CreateContainer within sandbox %q for %+v returns container id %q",
r.GetPodSandboxId(), r.GetConfig().GetMetadata(), res.GetContainerId()) r.GetPodSandboxId(), r.GetConfig().GetMetadata(), res.GetContainerId())
} }
}() }()
@ -121,24 +122,24 @@ func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.C
} }
func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (_ *runtime.StartContainerResponse, err error) { func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (_ *runtime.StartContainerResponse, err error) {
glog.V(2).Infof("StartContainer for %q", r.GetContainerId()) logrus.Infof("StartContainer for %q", r.GetContainerId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("StartContainer for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("StartContainer for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("StartContainer for %q returns successfully", r.GetContainerId()) logrus.Infof("StartContainer for %q returns successfully", r.GetContainerId())
} }
}() }()
return in.criContainerdService.StartContainer(ctx, r) return in.criContainerdService.StartContainer(ctx, r)
} }
func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (res *runtime.ListContainersResponse, err error) { func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (res *runtime.ListContainersResponse, err error) {
glog.V(5).Infof("ListContainers with filter %+v", r.GetFilter()) log.Tracef("ListContainers with filter %+v", r.GetFilter())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ListContainers with filter %+v failed, error: %v", r.GetFilter(), err) logrus.WithError(err).Errorf("ListContainers with filter %+v failed", r.GetFilter())
} else { } else {
glog.V(5).Infof("ListContainers with filter %+v returns containers %+v", log.Tracef("ListContainers with filter %+v returns containers %+v",
r.GetFilter(), res.GetContainers()) r.GetFilter(), res.GetContainers())
} }
}() }()
@ -146,49 +147,49 @@ func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.Li
} }
func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (res *runtime.ContainerStatusResponse, err error) { func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (res *runtime.ContainerStatusResponse, err error) {
glog.V(5).Infof("ContainerStatus for %q", r.GetContainerId()) log.Tracef("ContainerStatus for %q", r.GetContainerId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ContainerStatus for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("ContainerStatus for %q failed", r.GetContainerId())
} else { } else {
glog.V(5).Infof("ContainerStatus for %q returns status %+v", r.GetContainerId(), res.GetStatus()) log.Tracef("ContainerStatus for %q returns status %+v", r.GetContainerId(), res.GetStatus())
} }
}() }()
return in.criContainerdService.ContainerStatus(ctx, r) return in.criContainerdService.ContainerStatus(ctx, r)
} }
func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (res *runtime.StopContainerResponse, err error) { func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (res *runtime.StopContainerResponse, err error) {
glog.V(2).Infof("StopContainer for %q with timeout %d (s)", r.GetContainerId(), r.GetTimeout()) logrus.Infof("StopContainer for %q with timeout %d (s)", r.GetContainerId(), r.GetTimeout())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("StopContainer for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("StopContainer for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("StopContainer for %q returns successfully", r.GetContainerId()) logrus.Infof("StopContainer for %q returns successfully", r.GetContainerId())
} }
}() }()
return in.criContainerdService.StopContainer(ctx, r) return in.criContainerdService.StopContainer(ctx, r)
} }
func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (res *runtime.RemoveContainerResponse, err error) { func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (res *runtime.RemoveContainerResponse, err error) {
glog.V(2).Infof("RemoveContainer for %q", r.GetContainerId()) logrus.Infof("RemoveContainer for %q", r.GetContainerId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("RemoveContainer for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("RemoveContainer for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("RemoveContainer for %q returns successfully", r.GetContainerId()) logrus.Infof("RemoveContainer for %q returns successfully", r.GetContainerId())
} }
}() }()
return in.criContainerdService.RemoveContainer(ctx, r) return in.criContainerdService.RemoveContainer(ctx, r)
} }
func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (res *runtime.ExecSyncResponse, err error) { func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (res *runtime.ExecSyncResponse, err error) {
glog.V(2).Infof("ExecSync for %q with command %+v and timeout %d (s)", r.GetContainerId(), r.GetCmd(), r.GetTimeout()) logrus.Infof("ExecSync for %q with command %+v and timeout %d (s)", r.GetContainerId(), r.GetCmd(), r.GetTimeout())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ExecSync for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("ExecSync for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("ExecSync for %q returns with exit code %d", r.GetContainerId(), res.GetExitCode()) logrus.Infof("ExecSync for %q returns with exit code %d", r.GetContainerId(), res.GetExitCode())
glog.V(4).Infof("ExecSync for %q outputs - stdout: %q, stderr: %q", r.GetContainerId(), logrus.Debugf("ExecSync for %q outputs - stdout: %q, stderr: %q", r.GetContainerId(),
res.GetStdout(), res.GetStderr()) res.GetStdout(), res.GetStderr())
} }
}() }()
@ -196,49 +197,49 @@ func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSync
} }
func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest) (res *runtime.ExecResponse, err error) { func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest) (res *runtime.ExecResponse, err error) {
glog.V(2).Infof("Exec for %q with command %+v, tty %v and stdin %v", logrus.Infof("Exec for %q with command %+v, tty %v and stdin %v",
r.GetContainerId(), r.GetCmd(), r.GetTty(), r.GetStdin()) r.GetContainerId(), r.GetCmd(), r.GetTty(), r.GetStdin())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("Exec for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("Exec for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("Exec for %q returns URL %q", r.GetContainerId(), res.GetUrl()) logrus.Infof("Exec for %q returns URL %q", r.GetContainerId(), res.GetUrl())
} }
}() }()
return in.criContainerdService.Exec(ctx, r) return in.criContainerdService.Exec(ctx, r)
} }
func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequest) (res *runtime.AttachResponse, err error) { func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequest) (res *runtime.AttachResponse, err error) {
glog.V(2).Infof("Attach for %q with tty %v and stdin %v", r.GetContainerId(), r.GetTty(), r.GetStdin()) logrus.Infof("Attach for %q with tty %v and stdin %v", r.GetContainerId(), r.GetTty(), r.GetStdin())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("Attach for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("Attach for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("Attach for %q returns URL %q", r.GetContainerId(), res.Url) logrus.Infof("Attach for %q returns URL %q", r.GetContainerId(), res.Url)
} }
}() }()
return in.criContainerdService.Attach(ctx, r) return in.criContainerdService.Attach(ctx, r)
} }
func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (res *runtime.UpdateContainerResourcesResponse, err error) { func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (res *runtime.UpdateContainerResourcesResponse, err error) {
glog.V(2).Infof("UpdateContainerResources for %q with %+v", r.GetContainerId(), r.GetLinux()) logrus.Infof("UpdateContainerResources for %q with %+v", r.GetContainerId(), r.GetLinux())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("UpdateContainerResources for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("UpdateContainerResources for %q failed", r.GetContainerId())
} else { } else {
glog.V(2).Infof("UpdateContainerResources for %q returns successfully", r.GetContainerId()) logrus.Infof("UpdateContainerResources for %q returns successfully", r.GetContainerId())
} }
}() }()
return in.criContainerdService.UpdateContainerResources(ctx, r) return in.criContainerdService.UpdateContainerResources(ctx, r)
} }
func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (res *runtime.PullImageResponse, err error) { func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (res *runtime.PullImageResponse, err error) {
glog.V(2).Infof("PullImage %q with auth config %+v", r.GetImage().GetImage(), r.GetAuth()) logrus.Infof("PullImage %q with auth config %+v", r.GetImage().GetImage(), r.GetAuth())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("PullImage %q failed, error: %v", r.GetImage().GetImage(), err) logrus.WithError(err).Errorf("PullImage %q failed", r.GetImage().GetImage())
} else { } else {
glog.V(2).Infof("PullImage %q returns image reference %q", logrus.Infof("PullImage %q returns image reference %q",
r.GetImage().GetImage(), res.GetImageRef()) r.GetImage().GetImage(), res.GetImageRef())
} }
}() }()
@ -246,12 +247,12 @@ func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullIma
} }
func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (res *runtime.ListImagesResponse, err error) { func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (res *runtime.ListImagesResponse, err error) {
glog.V(5).Infof("ListImages with filter %+v", r.GetFilter()) log.Tracef("ListImages with filter %+v", r.GetFilter())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ListImages with filter %+v failed, error: %v", r.GetFilter(), err) logrus.WithError(err).Errorf("ListImages with filter %+v failed", r.GetFilter())
} else { } else {
glog.V(5).Infof("ListImages with filter %+v returns image list %+v", log.Tracef("ListImages with filter %+v returns image list %+v",
r.GetFilter(), res.GetImages()) r.GetFilter(), res.GetImages())
} }
}() }()
@ -259,12 +260,12 @@ func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListIm
} }
func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (res *runtime.ImageStatusResponse, err error) { func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (res *runtime.ImageStatusResponse, err error) {
glog.V(5).Infof("ImageStatus for %q", r.GetImage().GetImage()) log.Tracef("ImageStatus for %q", r.GetImage().GetImage())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ImageStatus for %q failed, error: %v", r.GetImage().GetImage(), err) logrus.WithError(err).Errorf("ImageStatus for %q failed", r.GetImage().GetImage())
} else { } else {
glog.V(5).Infof("ImageStatus for %q returns image status %+v", log.Tracef("ImageStatus for %q returns image status %+v",
r.GetImage().GetImage(), res.GetImage()) r.GetImage().GetImage(), res.GetImage())
} }
}() }()
@ -272,60 +273,60 @@ func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.Image
} }
func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (_ *runtime.RemoveImageResponse, err error) { func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (_ *runtime.RemoveImageResponse, err error) {
glog.V(2).Infof("RemoveImage %q", r.GetImage().GetImage()) logrus.Infof("RemoveImage %q", r.GetImage().GetImage())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("RemoveImage %q failed, error: %v", r.GetImage().GetImage(), err) logrus.WithError(err).Errorf("RemoveImage %q failed", r.GetImage().GetImage())
} else { } else {
glog.V(2).Infof("RemoveImage %q returns successfully", r.GetImage().GetImage()) logrus.Infof("RemoveImage %q returns successfully", r.GetImage().GetImage())
} }
}() }()
return in.criContainerdService.RemoveImage(ctx, r) return in.criContainerdService.RemoveImage(ctx, r)
} }
func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (res *runtime.ImageFsInfoResponse, err error) { func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (res *runtime.ImageFsInfoResponse, err error) {
glog.V(4).Infof("ImageFsInfo") logrus.Debugf("ImageFsInfo")
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ImageFsInfo failed, error: %v", err) logrus.WithError(err).Error("ImageFsInfo failed")
} else { } else {
glog.V(4).Infof("ImageFsInfo returns filesystem info %+v", res.ImageFilesystems) logrus.Debugf("ImageFsInfo returns filesystem info %+v", res.ImageFilesystems)
} }
}() }()
return in.criContainerdService.ImageFsInfo(ctx, r) return in.criContainerdService.ImageFsInfo(ctx, r)
} }
func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.ContainerStatsRequest) (res *runtime.ContainerStatsResponse, err error) { func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.ContainerStatsRequest) (res *runtime.ContainerStatsResponse, err error) {
glog.V(4).Infof("ContainerStats for %q", r.GetContainerId()) logrus.Debugf("ContainerStats for %q", r.GetContainerId())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ContainerStats for %q failed, error: %v", r.GetContainerId(), err) logrus.WithError(err).Errorf("ContainerStats for %q failed", r.GetContainerId())
} else { } else {
glog.V(4).Infof("ContainerStats for %q returns stats %+v", r.GetContainerId(), res.GetStats()) logrus.Debugf("ContainerStats for %q returns stats %+v", r.GetContainerId(), res.GetStats())
} }
}() }()
return in.criContainerdService.ContainerStats(ctx, r) return in.criContainerdService.ContainerStats(ctx, r)
} }
func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (res *runtime.ListContainerStatsResponse, err error) { func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (res *runtime.ListContainerStatsResponse, err error) {
glog.V(5).Infof("ListContainerStats with filter %+v", r.GetFilter()) log.Tracef("ListContainerStats with filter %+v", r.GetFilter())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("ListContainerStats failed, error: %v", err) logrus.WithError(err).Error("ListContainerStats failed")
} else { } else {
glog.V(5).Infof("ListContainerStats returns stats %+v", res.GetStats()) log.Tracef("ListContainerStats returns stats %+v", res.GetStats())
} }
}() }()
return in.criContainerdService.ListContainerStats(ctx, r) return in.criContainerdService.ListContainerStats(ctx, r)
} }
func (in *instrumentedService) LoadImage(ctx context.Context, r *api.LoadImageRequest) (res *api.LoadImageResponse, err error) { func (in *instrumentedService) LoadImage(ctx context.Context, r *api.LoadImageRequest) (res *api.LoadImageResponse, err error) {
glog.V(4).Infof("LoadImage from file %q", r.GetFilePath()) logrus.Debugf("LoadImage from file %q", r.GetFilePath())
defer func() { defer func() {
if err != nil { if err != nil {
glog.Errorf("LoadImage failed, error: %v", err) logrus.WithError(err).Error("LoadImage failed")
} else { } else {
glog.V(4).Infof("LoadImage returns images %+v", res.GetImages()) logrus.Debugf("LoadImage returns images %+v", res.GetImages())
} }
}() }()
return in.criContainerdService.LoadImage(ctx, r) return in.criContainerdService.LoadImage(ctx, r)

View File

@ -23,7 +23,7 @@ import (
"sync" "sync"
"github.com/containerd/containerd/cio" "github.com/containerd/containerd/cio"
"github.com/golang/glog" "github.com/sirupsen/logrus"
cioutil "github.com/containerd/cri-containerd/pkg/ioutil" cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
"github.com/containerd/cri-containerd/pkg/util" "github.com/containerd/cri-containerd/pkg/util"
@ -125,24 +125,24 @@ func (c *ContainerIO) Pipe() {
wg.Add(1) wg.Add(1)
go func() { go func() {
if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil { if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil {
glog.Errorf("Failed to pipe stdout of container %q: %v", c.id, err) logrus.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id)
} }
c.stdout.Close() c.stdout.Close()
c.stdoutGroup.Close() c.stdoutGroup.Close()
wg.Done() wg.Done()
glog.V(2).Infof("Finish piping stdout of container %q", c.id) logrus.Infof("Finish piping stdout of container %q", c.id)
}() }()
if !c.fifos.Terminal { if !c.fifos.Terminal {
wg.Add(1) wg.Add(1)
go func() { go func() {
if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil { if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil {
glog.Errorf("Failed to pipe stderr of container %q: %v", c.id, err) logrus.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id)
} }
c.stderr.Close() c.stderr.Close()
c.stderrGroup.Close() c.stderrGroup.Close()
wg.Done() wg.Done()
glog.V(2).Infof("Finish piping stderr of container %q", c.id) logrus.Infof("Finish piping stderr of container %q", c.id)
}() }()
} }
} }
@ -165,9 +165,9 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
wg.Add(1) wg.Add(1)
go func() { go func() {
if _, err := io.Copy(c.stdin, stdinStreamRC); err != nil { if _, err := io.Copy(c.stdin, stdinStreamRC); err != nil {
glog.Errorf("Failed to pipe stdin for container attach %q: %v", c.id, err) logrus.WithError(err).Errorf("Failed to pipe stdin for container attach %q", c.id)
} }
glog.V(2).Infof("Attach stream %q closed", stdinKey) logrus.Infof("Attach stream %q closed", stdinKey)
if opts.StdinOnce && !opts.Tty { if opts.StdinOnce && !opts.Tty {
// Due to kubectl requirements and current docker behavior, when (opts.StdinOnce && // Due to kubectl requirements and current docker behavior, when (opts.StdinOnce &&
// opts.Tty) we have to close container stdin and keep stdout and stderr open until // opts.Tty) we have to close container stdin and keep stdout and stderr open until
@ -175,7 +175,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
c.stdin.Close() c.stdin.Close()
// Also closes the containerd side. // Also closes the containerd side.
if err := opts.CloseStdin(); err != nil { if err := opts.CloseStdin(); err != nil {
glog.Errorf("Failed to close stdin for container %q: %v", c.id, err) logrus.WithError(err).Errorf("Failed to close stdin for container %q", c.id)
} }
} else { } else {
if opts.Stdout != nil { if opts.Stdout != nil {
@ -191,7 +191,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
attachStream := func(key string, close <-chan struct{}) { attachStream := func(key string, close <-chan struct{}) {
<-close <-close
glog.V(2).Infof("Attach stream %q closed", key) logrus.Infof("Attach stream %q closed", key)
// Make sure stdin gets closed. // Make sure stdin gets closed.
if stdinStreamRC != nil { if stdinStreamRC != nil {
stdinStreamRC.Close() stdinStreamRC.Close()

View File

@ -21,7 +21,7 @@ import (
"sync" "sync"
"github.com/containerd/containerd/cio" "github.com/containerd/containerd/cio"
"github.com/golang/glog" "github.com/sirupsen/logrus"
cioutil "github.com/containerd/cri-containerd/pkg/ioutil" cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
) )
@ -68,13 +68,13 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
wg.Add(1) wg.Add(1)
go func() { go func() {
if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil { if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil {
glog.Errorf("Failed to redirect stdin for container exec %q: %v", e.id, err) logrus.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id)
} }
glog.V(2).Infof("Container exec %q stdin closed", e.id) logrus.Infof("Container exec %q stdin closed", e.id)
if opts.StdinOnce && !opts.Tty { if opts.StdinOnce && !opts.Tty {
e.stdin.Close() e.stdin.Close()
if err := opts.CloseStdin(); err != nil { if err := opts.CloseStdin(); err != nil {
glog.Errorf("Failed to close stdin for container exec %q: %v", e.id, err) logrus.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id)
} }
} else { } else {
if e.stdout != nil { if e.stdout != nil {
@ -90,7 +90,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) { attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) {
if _, err := io.Copy(stream, out); err != nil { if _, err := io.Copy(stream, out); err != nil {
glog.Errorf("Failed to pipe %q for container exec %q: %v", t, e.id, err) logrus.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id)
} }
out.Close() out.Close()
stream.Close() stream.Close()
@ -99,7 +99,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
} }
e.closer.wg.Done() e.closer.wg.Done()
wg.Done() wg.Done()
glog.V(2).Infof("Finish piping %q of container exec %q", t, e.id) logrus.Infof("Finish piping %q of container exec %q", t, e.id)
} }
if opts.Stdout != nil { if opts.Stdout != nil {

View File

@ -25,7 +25,7 @@ import (
"os" "os"
"time" "time"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
cioutil "github.com/containerd/cri-containerd/pkg/ioutil" cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
@ -53,7 +53,7 @@ func NewDiscardLogger() io.WriteCloser {
// NewCRILogger returns a write closer which redirect container log into // NewCRILogger returns a write closer which redirect container log into
// log file, and decorate the log line into CRI defined format. // log file, and decorate the log line into CRI defined format.
func NewCRILogger(path string, stream StreamType) (io.WriteCloser, error) { func NewCRILogger(path string, stream StreamType) (io.WriteCloser, error) {
glog.V(4).Infof("Start writing log file %q", path) logrus.Debugf("Start writing log file %q", path)
prc, pwc := io.Pipe() prc, pwc := io.Pipe()
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640) f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640)
if err != nil { if err != nil {
@ -74,11 +74,11 @@ func redirectLogs(path string, rc io.ReadCloser, wc io.WriteCloser, stream Strea
for { for {
lineBytes, isPrefix, err := r.ReadLine() lineBytes, isPrefix, err := r.ReadLine()
if err == io.EOF { if err == io.EOF {
glog.V(4).Infof("Finish redirecting log file %q", path) logrus.Debugf("Finish redirecting log file %q", path)
return return
} }
if err != nil { if err != nil {
glog.Errorf("An error occurred when redirecting log file %q: %v", path, err) logrus.WithError(err).Errorf("An error occurred when redirecting log file %q", path)
return return
} }
tagBytes := fullBytes tagBytes := fullBytes
@ -89,7 +89,7 @@ func redirectLogs(path string, rc io.ReadCloser, wc io.WriteCloser, stream Strea
data := bytes.Join([][]byte{timestampBytes, streamBytes, tagBytes, lineBytes}, delimiterBytes) data := bytes.Join([][]byte{timestampBytes, streamBytes, tagBytes, lineBytes}, delimiterBytes)
data = append(data, eol) data = append(data, eol)
if _, err := wc.Write(data); err != nil { if _, err := wc.Write(data); err != nil {
glog.Errorf("Fail to write %q log to log file %q: %v", stream, path, err) logrus.WithError(err).Errorf("Fail to write %q log to log file %q", stream, path)
} }
// Continue on write error to drain the input. // Continue on write error to drain the input.
} }

View File

@ -31,7 +31,7 @@ import (
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -60,10 +60,10 @@ func (c *criContainerdService) recover(ctx context.Context) error {
for _, sandbox := range sandboxes { for _, sandbox := range sandboxes {
sb, err := loadSandbox(ctx, sandbox) sb, err := loadSandbox(ctx, sandbox)
if err != nil { if err != nil {
glog.Errorf("Failed to load sandbox %q: %v", sandbox.ID(), err) logrus.WithError(err).Errorf("Failed to load sandbox %q", sandbox.ID())
continue continue
} }
glog.V(4).Infof("Loaded sandbox %+v", sb) logrus.Debugf("Loaded sandbox %+v", sb)
if err := c.sandboxStore.Add(sb); err != nil { if err := c.sandboxStore.Add(sb); err != nil {
return fmt.Errorf("failed to add sandbox %q to store: %v", sandbox.ID(), err) return fmt.Errorf("failed to add sandbox %q to store: %v", sandbox.ID(), err)
} }
@ -81,10 +81,10 @@ func (c *criContainerdService) recover(ctx context.Context) error {
containerDir := getContainerRootDir(c.config.RootDir, container.ID()) containerDir := getContainerRootDir(c.config.RootDir, container.ID())
cntr, err := loadContainer(ctx, container, containerDir) cntr, err := loadContainer(ctx, container, containerDir)
if err != nil { if err != nil {
glog.Errorf("Failed to load container %q: %v", container.ID(), err) logrus.WithError(err).Errorf("Failed to load container %q", container.ID())
continue continue
} }
glog.V(4).Infof("Loaded container %+v", cntr) logrus.Debugf("Loaded container %+v", cntr)
if err := c.containerStore.Add(cntr); err != nil { if err := c.containerStore.Add(cntr); err != nil {
return fmt.Errorf("failed to add container %q to store: %v", container.ID(), err) return fmt.Errorf("failed to add container %q to store: %v", container.ID(), err)
} }
@ -103,7 +103,7 @@ func (c *criContainerdService) recover(ctx context.Context) error {
return fmt.Errorf("failed to load images: %v", err) return fmt.Errorf("failed to load images: %v", err)
} }
for _, image := range images { for _, image := range images {
glog.V(4).Infof("Loaded image %+v", image) logrus.Debugf("Loaded image %+v", image)
if err := c.imageStore.Add(image); err != nil { if err := c.imageStore.Add(image); err != nil {
return fmt.Errorf("failed to add image %q to store: %v", image.ID, err) return fmt.Errorf("failed to add image %q to store: %v", image.ID, err)
} }
@ -148,7 +148,7 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir
// Load status from checkpoint. // Load status from checkpoint.
status, err := containerstore.LoadStatus(containerDir, id) status, err := containerstore.LoadStatus(containerDir, id)
if err != nil { if err != nil {
glog.Warningf("Failed to load container status for %q: %v", id, err) logrus.WithError(err).Warnf("Failed to load container status for %q", id)
status = unknownContainerStatus() status = unknownContainerStatus()
} }
@ -328,7 +328,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image,
for _, i := range cImages { for _, i := range cImages {
desc, err := i.Config(ctx) desc, err := i.Config(ctx)
if err != nil { if err != nil {
glog.Warningf("Failed to get image config for %q: %v", i.Name(), err) logrus.WithError(err).Warnf("Failed to get image config for %q", i.Name())
continue continue
} }
id := desc.Digest.String() id := desc.Digest.String()
@ -341,27 +341,27 @@ func loadImages(ctx context.Context, cImages []containerd.Image,
i := imgs[0] i := imgs[0]
ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default()) ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default())
if err != nil { if err != nil {
glog.Errorf("Failed to check image content readiness for %q: %v", i.Name(), err) logrus.WithError(err).Errorf("Failed to check image content readiness for %q", i.Name())
continue continue
} }
if !ok { if !ok {
glog.Warningf("The image content readiness for %q is not ok", i.Name()) logrus.Warnf("The image content readiness for %q is not ok", i.Name())
continue continue
} }
// Checking existence of top-level snapshot for each image being recovered. // Checking existence of top-level snapshot for each image being recovered.
unpacked, err := i.IsUnpacked(ctx, snapshotter) unpacked, err := i.IsUnpacked(ctx, snapshotter)
if err != nil { if err != nil {
glog.Warningf("Failed to Check whether image is unpacked for image %s: %v", i.Name(), err) logrus.WithError(err).Warnf("Failed to Check whether image is unpacked for image %s", i.Name())
continue continue
} }
if !unpacked { if !unpacked {
glog.Warningf("The image %s is not unpacked.", i.Name()) logrus.Warnf("The image %s is not unpacked.", i.Name())
// TODO(random-liu): Consider whether we should try unpack here. // TODO(random-liu): Consider whether we should try unpack here.
} }
info, err := getImageInfo(ctx, i) info, err := getImageInfo(ctx, i)
if err != nil { if err != nil {
glog.Warningf("Failed to get image info for %q: %v", i.Name(), err) logrus.WithError(err).Warnf("Failed to get image info for %q", i.Name())
continue continue
} }
image := imagestore.Image{ image := imagestore.Image{
@ -376,7 +376,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image,
name := i.Name() name := i.Name()
r, err := reference.ParseAnyReference(name) r, err := reference.ParseAnyReference(name)
if err != nil { if err != nil {
glog.Warningf("Failed to parse image reference %q: %v", name, err) logrus.WithError(err).Warnf("Failed to parse image reference %q", name)
continue continue
} }
if _, ok := r.(reference.Canonical); ok { if _, ok := r.(reference.Canonical); ok {
@ -387,7 +387,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image,
// This is an image id. // This is an image id.
continue continue
} else { } else {
glog.Warningf("Invalid image reference %q", name) logrus.Warnf("Invalid image reference %q", name)
} }
} }
images = append(images, image) images = append(images, image)
@ -407,7 +407,7 @@ func cleanupOrphanedSandboxDirs(cntrs []containerd.Container, sandboxesRoot stri
} }
for _, d := range dirs { for _, d := range dirs {
if !d.IsDir() { if !d.IsDir() {
glog.Warningf("Invalid file %q found in sandboxes directory", d.Name()) logrus.Warnf("Invalid file %q found in sandboxes directory", d.Name())
continue continue
} }
if _, ok := cntrsMap[d.Name()]; ok { if _, ok := cntrsMap[d.Name()]; ok {
@ -416,9 +416,9 @@ func cleanupOrphanedSandboxDirs(cntrs []containerd.Container, sandboxesRoot stri
} }
sandboxDir := filepath.Join(sandboxesRoot, d.Name()) sandboxDir := filepath.Join(sandboxesRoot, d.Name())
if err := system.EnsureRemoveAll(sandboxDir); err != nil { if err := system.EnsureRemoveAll(sandboxDir); err != nil {
glog.Warningf("Failed to remove sandbox directory %q: %v", sandboxDir, err) logrus.WithError(err).Warnf("Failed to remove sandbox directory %q", sandboxDir)
} else { } else {
glog.V(4).Infof("Cleanup orphaned sandbox directory %q", sandboxDir) logrus.Debugf("Cleanup orphaned sandbox directory %q", sandboxDir)
} }
} }
return nil return nil
@ -436,7 +436,7 @@ func cleanupOrphanedContainerDirs(cntrs []containerd.Container, containersRoot s
} }
for _, d := range dirs { for _, d := range dirs {
if !d.IsDir() { if !d.IsDir() {
glog.Warningf("Invalid file %q found in containers directory", d.Name()) logrus.Warnf("Invalid file %q found in containers directory", d.Name())
continue continue
} }
if _, ok := cntrsMap[d.Name()]; ok { if _, ok := cntrsMap[d.Name()]; ok {
@ -445,9 +445,9 @@ func cleanupOrphanedContainerDirs(cntrs []containerd.Container, containersRoot s
} }
containerDir := filepath.Join(containersRoot, d.Name()) containerDir := filepath.Join(containersRoot, d.Name())
if err := system.EnsureRemoveAll(containerDir); err != nil { if err := system.EnsureRemoveAll(containerDir); err != nil {
glog.Warningf("Failed to remove container directory %q: %v", containerDir, err) logrus.WithError(err).Warnf("Failed to remove container directory %q", containerDir)
} else { } else {
glog.V(4).Infof("Cleanup orphaned container directory %q", containerDir) logrus.Debugf("Cleanup orphaned container directory %q", containerDir)
} }
} }
return nil return nil

View File

@ -25,7 +25,7 @@ import (
"strings" "strings"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
) )
@ -83,7 +83,7 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read
return fmt.Errorf("failed to find nsenter: %v", err) return fmt.Errorf("failed to find nsenter: %v", err)
} }
glog.V(2).Infof("Executing port forwarding command: %s %s", nsenter, strings.Join(args, " ")) logrus.Infof("Executing port forwarding command: %s %s", nsenter, strings.Join(args, " "))
cmd := exec.Command(nsenter, args...) cmd := exec.Command(nsenter, args...)
cmd.Stdout = stream cmd.Stdout = stream
@ -106,17 +106,17 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read
} }
go func() { go func() {
if _, err := io.Copy(in, stream); err != nil { if _, err := io.Copy(in, stream); err != nil {
glog.Errorf("Failed to copy port forward input for %q port %d: %v", id, port, err) logrus.WithError(err).Errorf("Failed to copy port forward input for %q port %d", id, port)
} }
in.Close() in.Close()
glog.V(4).Infof("Finish copy port forward input for %q port %d: %v", id, port) logrus.Debugf("Finish copy port forward input for %q port %d: %v", id, port)
}() }()
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return fmt.Errorf("nsenter command returns error: %v, stderr: %q", err, stderr.String()) return fmt.Errorf("nsenter command returns error: %v, stderr: %q", err, stderr.String())
} }
glog.V(2).Infof("Finish port forwarding for %q port %d", id, port) logrus.Infof("Finish port forwarding for %q port %d", id, port)
return nil return nil
} }

View File

@ -22,10 +22,10 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/golang/glog"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"github.com/containerd/cri-containerd/pkg/log"
"github.com/containerd/cri-containerd/pkg/store" "github.com/containerd/cri-containerd/pkg/store"
) )
@ -39,7 +39,7 @@ func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime.
r.GetPodSandboxId(), err) r.GetPodSandboxId(), err)
} }
// Do not return error if the id doesn't exist. // Do not return error if the id doesn't exist.
glog.V(5).Infof("RemovePodSandbox called for sandbox %q that does not exist", log.Tracef("RemovePodSandbox called for sandbox %q that does not exist",
r.GetPodSandboxId()) r.GetPodSandboxId())
return &runtime.RemovePodSandboxResponse{}, nil return &runtime.RemovePodSandboxResponse{}, nil
} }
@ -88,7 +88,7 @@ func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime.
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("failed to delete sandbox container %q: %v", id, err) return nil, fmt.Errorf("failed to delete sandbox container %q: %v", id, err)
} }
glog.V(5).Infof("Remove called for sandbox container %q that does not exist", id, err) log.Tracef("Remove called for sandbox container %q that does not exist", id)
} }
// Remove sandbox from sandbox store. Note that once the sandbox is successfully // Remove sandbox from sandbox store. Note that once the sandbox is successfully

View File

@ -27,15 +27,16 @@ import (
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/golang/glog"
imagespec "github.com/opencontainers/image-spec/specs-go/v1" imagespec "github.com/opencontainers/image-spec/specs-go/v1"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"github.com/containerd/cri-containerd/pkg/annotations" "github.com/containerd/cri-containerd/pkg/annotations"
customopts "github.com/containerd/cri-containerd/pkg/containerd/opts" customopts "github.com/containerd/cri-containerd/pkg/containerd/opts"
"github.com/containerd/cri-containerd/pkg/log"
sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox"
"github.com/containerd/cri-containerd/pkg/util" "github.com/containerd/cri-containerd/pkg/util"
) )
@ -53,7 +54,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
// Generate unique id and name for the sandbox and reserve the name. // Generate unique id and name for the sandbox and reserve the name.
id := util.GenerateID() id := util.GenerateID()
name := makeSandboxName(config.GetMetadata()) name := makeSandboxName(config.GetMetadata())
glog.V(4).Infof("Generated id %q for sandbox %q", id, name) logrus.Debugf("Generated id %q for sandbox %q", id, name)
// Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the // Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the
// same sandbox. // same sandbox.
if err := c.sandboxNameIndex.Reserve(name, id); err != nil { if err := c.sandboxNameIndex.Reserve(name, id); err != nil {
@ -96,7 +97,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err := sandbox.NetNS.Remove(); err != nil { if err := sandbox.NetNS.Remove(); err != nil {
glog.Errorf("Failed to remove network namespace %s for sandbox %q: %v", sandbox.NetNSPath, id, err) logrus.WithError(err).Errorf("Failed to remove network namespace %s for sandbox %q", sandbox.NetNSPath, id)
} }
sandbox.NetNSPath = "" sandbox.NetNSPath = ""
} }
@ -116,7 +117,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
if retErr != nil { if retErr != nil {
// Teardown network if an error is returned. // Teardown network if an error is returned.
if err := c.netPlugin.TearDownPod(podNetwork); err != nil { if err := c.netPlugin.TearDownPod(podNetwork); err != nil {
glog.Errorf("Failed to destroy network for sandbox %q: %v", id, err) logrus.WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
} }
} }
}() }()
@ -139,7 +140,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to generate sandbox container spec: %v", err) return nil, fmt.Errorf("failed to generate sandbox container spec: %v", err)
} }
glog.V(4).Infof("Sandbox container spec: %+v", spec) logrus.Debugf("Sandbox container spec: %+v", spec)
var specOpts []oci.SpecOpts var specOpts []oci.SpecOpts
if uid := securityContext.GetRunAsUser(); uid != nil { if uid := securityContext.GetRunAsUser(); uid != nil {
@ -179,7 +180,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err := container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil { if err := container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
glog.Errorf("Failed to delete containerd container %q: %v", id, err) logrus.WithError(err).Errorf("Failed to delete containerd container %q", id)
} }
} }
}() }()
@ -194,8 +195,8 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
if retErr != nil { if retErr != nil {
// Cleanup the sandbox root directory. // Cleanup the sandbox root directory.
if err := c.os.RemoveAll(sandboxRootDir); err != nil { if err := c.os.RemoveAll(sandboxRootDir); err != nil {
glog.Errorf("Failed to remove sandbox root directory %q: %v", logrus.WithError(err).Errorf("Failed to remove sandbox root directory %q",
sandboxRootDir, err) sandboxRootDir)
} }
} }
}() }()
@ -207,14 +208,14 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
defer func() { defer func() {
if retErr != nil { if retErr != nil {
if err = c.unmountSandboxFiles(sandboxRootDir, config); err != nil { if err = c.unmountSandboxFiles(sandboxRootDir, config); err != nil {
glog.Errorf("Failed to unmount sandbox files in %q: %v", logrus.WithError(err).Errorf("Failed to unmount sandbox files in %q",
sandboxRootDir, err) sandboxRootDir)
} }
} }
}() }()
// Create sandbox task in containerd. // Create sandbox task in containerd.
glog.V(5).Infof("Create sandbox container (id=%q, name=%q).", log.Tracef("Create sandbox container (id=%q, name=%q).",
id, name) id, name)
// We don't need stdio for sandbox container. // We don't need stdio for sandbox container.
task, err := container.NewTask(ctx, containerdio.NullIO) task, err := container.NewTask(ctx, containerdio.NullIO)
@ -225,7 +226,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
if retErr != nil { if retErr != nil {
// Cleanup the sandbox container if an error is returned. // Cleanup the sandbox container if an error is returned.
if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil { if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil {
glog.Errorf("Failed to delete sandbox container %q: %v", id, err) logrus.WithError(err).Errorf("Failed to delete sandbox container %q", id)
} }
} }
}() }()

View File

@ -23,8 +23,8 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/golang/glog"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
@ -160,7 +160,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox,
if err == nil { if err == nil {
si.RuntimeSpec = spec si.RuntimeSpec = spec
} else { } else {
glog.Errorf("Failed to get sandbox container %q runtime spec: %v", sandbox.ID, err) logrus.WithError(err).Errorf("Failed to get sandbox container %q runtime spec", sandbox.ID)
} }
ctrInfo, err := container.Info(ctx) ctrInfo, err := container.Info(ctx)
@ -172,7 +172,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox,
si.SnapshotKey = ctrInfo.SnapshotKey si.SnapshotKey = ctrInfo.SnapshotKey
si.Snapshotter = ctrInfo.Snapshotter si.Snapshotter = ctrInfo.Snapshotter
} else { } else {
glog.Errorf("Failed to get sandbox container %q info: %v", sandbox.ID, err) logrus.WithError(err).Errorf("Failed to get sandbox container %q info", sandbox.ID)
} }
infoBytes, err := json.Marshal(si) infoBytes, err := json.Marshal(si)

View File

@ -23,7 +23,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/golang/glog" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
) )
@ -82,7 +82,7 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St
} }
} }
glog.V(2).Infof("TearDown network for sandbox %q successfully", id) logrus.Infof("TearDown network for sandbox %q successfully", id)
sandboxRoot := getSandboxRootDir(c.config.RootDir, id) sandboxRoot := getSandboxRootDir(c.config.RootDir, id)
if err := c.unmountSandboxFiles(sandboxRoot, sandbox.Config); err != nil { if err := c.unmountSandboxFiles(sandboxRoot, sandbox.Config); err != nil {

View File

@ -28,9 +28,9 @@ import (
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/sys" "github.com/containerd/containerd/sys"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/golang/glog"
runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor" runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp" runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp"
"github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -140,9 +140,9 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err) return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err)
} }
glog.V(2).Infof("Get device uuid %q for image filesystem %q", c.imageFSUUID, imageFSPath) logrus.Infof("Get device uuid %q for image filesystem %q", c.imageFSUUID, imageFSPath)
} else { } else {
glog.Warning("Skip retrieving imagefs UUID, kubelet will not be able to get imagefs capacity or perform imagefs disk eviction.") logrus.Warn("Skip retrieving imagefs UUID, kubelet will not be able to get imagefs capacity or perform imagefs disk eviction.")
} }
c.netPlugin, err = ocicni.InitCNI(config.NetworkPluginConfDir, config.NetworkPluginBinDir) c.netPlugin, err = ocicni.InitCNI(config.NetworkPluginConfDir, config.NetworkPluginBinDir)
@ -170,19 +170,19 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
// Run starts the cri-containerd service. // Run starts the cri-containerd service.
func (c *criContainerdService) Run() error { func (c *criContainerdService) Run() error {
glog.V(2).Info("Start cri-containerd service") logrus.Info("Start cri-containerd service")
glog.V(2).Infof("Start recovering state") logrus.Infof("Start recovering state")
if err := c.recover(context.Background()); err != nil { if err := c.recover(context.Background()); err != nil {
return fmt.Errorf("failed to recover state: %v", err) return fmt.Errorf("failed to recover state: %v", err)
} }
// Start event handler. // Start event handler.
glog.V(2).Info("Start event monitor") logrus.Info("Start event monitor")
eventMonitorCloseCh := c.eventMonitor.start() eventMonitorCloseCh := c.eventMonitor.start()
// Start snapshot stats syncer, it doesn't need to be stopped. // Start snapshot stats syncer, it doesn't need to be stopped.
glog.V(2).Info("Start snapshots syncer") logrus.Info("Start snapshots syncer")
snapshotsSyncer := newSnapshotsSyncer( snapshotsSyncer := newSnapshotsSyncer(
c.snapshotStore, c.snapshotStore,
c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter), c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter),
@ -191,18 +191,18 @@ func (c *criContainerdService) Run() error {
snapshotsSyncer.start() snapshotsSyncer.start()
// Start streaming server. // Start streaming server.
glog.V(2).Info("Start streaming server") logrus.Info("Start streaming server")
streamServerCloseCh := make(chan struct{}) streamServerCloseCh := make(chan struct{})
go func() { go func() {
if err := c.streamServer.Start(true); err != nil { if err := c.streamServer.Start(true); err != nil {
glog.Errorf("Failed to start streaming server: %v", err) logrus.WithError(err).Error("Failed to start streaming server")
} }
close(streamServerCloseCh) close(streamServerCloseCh)
}() }()
// Start grpc server. // Start grpc server.
// Unlink to cleanup the previous socket file. // Unlink to cleanup the previous socket file.
glog.V(2).Info("Start grpc server") logrus.Info("Start grpc server")
err := syscall.Unlink(c.config.SocketPath) err := syscall.Unlink(c.config.SocketPath)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to unlink socket file %q: %v", c.config.SocketPath, err) return fmt.Errorf("failed to unlink socket file %q: %v", c.config.SocketPath, err)
@ -214,7 +214,7 @@ func (c *criContainerdService) Run() error {
grpcServerCloseCh := make(chan struct{}) grpcServerCloseCh := make(chan struct{})
go func() { go func() {
if err := c.server.Serve(l); err != nil { if err := c.server.Serve(l); err != nil {
glog.Errorf("Failed to serve grpc grpc request: %v", err) logrus.WithError(err).Error("Failed to serve grpc grpc request")
} }
close(grpcServerCloseCh) close(grpcServerCloseCh)
}() }()
@ -228,17 +228,17 @@ func (c *criContainerdService) Run() error {
c.Stop() c.Stop()
<-eventMonitorCloseCh <-eventMonitorCloseCh
glog.V(2).Info("Event monitor stopped") logrus.Info("Event monitor stopped")
<-streamServerCloseCh <-streamServerCloseCh
glog.V(2).Info("Stream server stopped") logrus.Info("Stream server stopped")
<-grpcServerCloseCh <-grpcServerCloseCh
glog.V(2).Info("GRPC server stopped") logrus.Info("GRPC server stopped")
return nil return nil
} }
// Stop stops the cri-containerd service. // Stop stops the cri-containerd service.
func (c *criContainerdService) Stop() { func (c *criContainerdService) Stop() {
glog.V(2).Info("Stop cri-containerd service") logrus.Info("Stop cri-containerd service")
c.eventMonitor.stop() c.eventMonitor.stop()
c.streamServer.Stop() // nolint: errcheck c.streamServer.Stop() // nolint: errcheck
c.server.Stop() c.server.Stop()

View File

@ -23,7 +23,7 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
snapshot "github.com/containerd/containerd/snapshots" snapshot "github.com/containerd/containerd/snapshots"
"github.com/golang/glog" "github.com/sirupsen/logrus"
snapshotstore "github.com/containerd/cri-containerd/pkg/store/snapshot" snapshotstore "github.com/containerd/cri-containerd/pkg/store/snapshot"
) )
@ -59,7 +59,7 @@ func (s *snapshotsSyncer) start() {
// check the resource usage and optimize this. // check the resource usage and optimize this.
for { for {
if err := s.sync(); err != nil { if err := s.sync(); err != nil {
glog.Errorf("Failed to sync snapshot stats: %v", err) logrus.WithError(err).Error("Failed to sync snapshot stats")
} }
<-tick.C <-tick.C
} }
@ -99,7 +99,7 @@ func (s *snapshotsSyncer) sync() error {
usage, err := s.snapshotter.Usage(context.Background(), info.Name) usage, err := s.snapshotter.Usage(context.Background(), info.Name)
if err != nil { if err != nil {
if !errdefs.IsNotFound(err) { if !errdefs.IsNotFound(err) {
glog.Errorf("Failed to get usage for snapshot %q: %v", info.Name, err) logrus.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name)
} }
continue continue
} }

View File

@ -79,7 +79,7 @@ write_files:
LimitNPROC=infinity LimitNPROC=infinity
LimitCORE=infinity LimitCORE=infinity
ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \ ExecStart=/home/cri-containerd/usr/local/bin/cri-containerd \
--logtostderr --v=4 \ --log-level=debug \
--network-bin-dir=/home/cri-containerd/opt/cni/bin \ --network-bin-dir=/home/cri-containerd/opt/cni/bin \
--network-conf-dir=/home/cri-containerd/etc/cni/net.d --network-conf-dir=/home/cri-containerd/etc/cni/net.d