From 3d68005c04c63d405b46065a8383030f6e59062a Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Wed, 17 Jan 2018 09:23:01 +0000 Subject: [PATCH] Replace glog with logrus Signed-off-by: Lantao Liu --- integration/test_utils.go | 4 +- pkg/containerd/opts/container.go | 4 +- pkg/server/container_attach.go | 4 +- pkg/server/container_create.go | 18 +-- pkg/server/container_execsync.go | 16 +-- pkg/server/container_remove.go | 9 +- pkg/server/container_start.go | 4 +- pkg/server/container_status.go | 6 +- pkg/server/container_stop.go | 12 +- pkg/server/container_update_resources.go | 4 +- pkg/server/events.go | 24 ++-- pkg/server/image_load.go | 6 +- pkg/server/image_pull.go | 10 +- pkg/server/image_remove.go | 6 +- pkg/server/image_status.go | 4 +- pkg/server/instrumented_service.go | 151 ++++++++++++----------- pkg/server/io/container_io.go | 18 +-- pkg/server/io/exec_io.go | 12 +- pkg/server/io/logger.go | 10 +- pkg/server/restart.go | 42 +++---- pkg/server/sandbox_portforward.go | 10 +- pkg/server/sandbox_remove.go | 6 +- pkg/server/sandbox_run.go | 25 ++-- pkg/server/sandbox_status.go | 6 +- pkg/server/sandbox_stop.go | 4 +- pkg/server/service.go | 30 ++--- pkg/server/snapshots.go | 6 +- 27 files changed, 227 insertions(+), 224 deletions(-) diff --git a/integration/test_utils.go b/integration/test_utils.go index 06f755033..900442b20 100644 --- a/integration/test_utils.go +++ b/integration/test_utils.go @@ -23,7 +23,7 @@ import ( "time" "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/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/remote" @@ -53,7 +53,7 @@ var ( func init() { if err := ConnectDaemons(); err != nil { - glog.Exitf("Failed to connect daemons: %v", err) + logrus.WithError(err).Fatalf("Failed to connect daemons") } } diff --git a/pkg/containerd/opts/container.go b/pkg/containerd/opts/container.go index 1eb0ca3fb..861378c2c 100644 --- a/pkg/containerd/opts/container.go +++ b/pkg/containerd/opts/container.go @@ -27,8 +27,8 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/fs" "github.com/containerd/containerd/mount" - "github.com/golang/glog" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the @@ -81,7 +81,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts { } defer func() { 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 { err = uerr } diff --git a/pkg/server/container_attach.go b/pkg/server/container_attach.go index 75bcf7de2..901d2ecf3 100644 --- a/pkg/server/container_attach.go +++ b/pkg/server/container_attach.go @@ -21,7 +21,7 @@ import ( "io" "github.com/containerd/containerd" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/client-go/tools/remotecommand" "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) { 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) } }) diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index 3303e924e..890261b16 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -33,13 +33,13 @@ import ( "github.com/containerd/containerd/oci" "github.com/containerd/typeurl" "github.com/davecgh/go-spew/spew" - "github.com/golang/glog" imagespec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/runc/libcontainer/devices" runtimespec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/validate" "github.com/opencontainers/selinux/go-selinux/label" + "github.com/sirupsen/logrus" "github.com/syndtr/gocapability/capability" "golang.org/x/net/context" "golang.org/x/sys/unix" @@ -92,7 +92,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C // the same container. id := util.GenerateID() 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 { 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 { // Cleanup the container root directory. if err = c.os.RemoveAll(containerRootDir); err != nil { - glog.Errorf("Failed to remove container root directory %q: %v", - containerRootDir, err) + logrus.WithError(err).Errorf("Failed to remove container root directory %q", + 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) } - 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. opts := []containerd.NewContainerOpts{ @@ -184,7 +184,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C defer func() { if retErr != 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() { if retErr != 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 { // Cleanup container checkpoint on error. 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 } 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") } diff --git a/pkg/server/container_execsync.go b/pkg/server/container_execsync.go index 11f6e5234..af04cdfca 100644 --- a/pkg/server/container_execsync.go +++ b/pkg/server/container_execsync.go @@ -25,7 +25,7 @@ import ( "github.com/containerd/containerd" containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "golang.org/x/sys/unix" "k8s.io/client-go/tools/remotecommand" @@ -114,7 +114,7 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o opts.stderr = cio.NewDiscardLogger() } 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) var execIO *cio.ExecIO process, err := task.Exec(ctx, execID, pspec, @@ -129,7 +129,7 @@ func (c *criContainerdService) execInContainer(ctx context.Context, id string, o } defer func() { 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) { 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. 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()) <-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) case exitRes := <-exitCh: 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 { return nil, fmt.Errorf("failed while waiting for exec %q: %v", execID, err) } <-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 } } diff --git a/pkg/server/container_remove.go b/pkg/server/container_remove.go index 36ca6bbed..0cbbb5001 100644 --- a/pkg/server/container_remove.go +++ b/pkg/server/container_remove.go @@ -22,10 +22,11 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/docker/docker/pkg/system" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" + "github.com/containerd/cri-containerd/pkg/log" "github.com/containerd/cri-containerd/pkg/store" 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) } // 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 } id := container.ID @@ -53,7 +54,7 @@ func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.R if retErr != nil { // Reset removing if remove failed. 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) { 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. diff --git a/pkg/server/container_start.go b/pkg/server/container_start.go index 4e9dead66..88dc8f5cb 100644 --- a/pkg/server/container_start.go +++ b/pkg/server/container_start.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd" containerdio "github.com/containerd/containerd/cio" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" @@ -133,7 +133,7 @@ func (c *criContainerdService) startContainer(ctx context.Context, defer func() { if retErr != 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) } } }() diff --git a/pkg/server/container_status.go b/pkg/server/container_status.go index a4de30d5c..f78892d46 100644 --- a/pkg/server/container_status.go +++ b/pkg/server/container_status.go @@ -20,8 +20,8 @@ import ( "encoding/json" "fmt" - "github.com/golang/glog" runtimespec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" @@ -131,7 +131,7 @@ func toCRIContainerInfo(ctx context.Context, container containerstore.Container, if err == nil { ci.RuntimeSpec = spec } 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) @@ -139,7 +139,7 @@ func toCRIContainerInfo(ctx context.Context, container containerstore.Container, ci.SnapshotKey = ctrInfo.SnapshotKey ci.Snapshotter = ctrInfo.Snapshotter } 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) diff --git a/pkg/server/container_stop.go b/pkg/server/container_stop.go index f0baf4c3b..361067fac 100644 --- a/pkg/server/container_stop.go +++ b/pkg/server/container_stop.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/docker/docker/pkg/signal" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "golang.org/x/sys/unix" "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. state := container.Status.Get().State() 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)) return nil } @@ -87,7 +87,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont 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) if err != nil { if !errdefs.IsNotFound(err) { @@ -108,7 +108,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont if err == 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) @@ -119,7 +119,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont return nil } // 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 err = task.Kill(ctx, unix.SIGKILL, containerd.WithKillAll); err != nil { 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 // it is already stopped. - glog.Warningf("Container %q was removed during stopping", id) + logrus.Warnf("Container %q was removed during stopping", id) return nil } // TODO(random-liu): Use channel with event handler instead of polling. diff --git a/pkg/server/container_update_resources.go b/pkg/server/container_update_resources.go index fd4c5ce5d..fac7a1b43 100644 --- a/pkg/server/container_update_resources.go +++ b/pkg/server/container_update_resources.go @@ -24,8 +24,8 @@ import ( "github.com/containerd/containerd/containers" "github.com/containerd/containerd/errdefs" "github.com/containerd/typeurl" - "github.com/golang/glog" runtimespec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" @@ -80,7 +80,7 @@ func (c *criContainerdService) updateContainerResources(ctx context.Context, if retErr != nil { // Reset spec on error. 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) } } }() diff --git a/pkg/server/events.go b/pkg/server/events.go index 5fc1357d1..120c2443c 100644 --- a/pkg/server/events.go +++ b/pkg/server/events.go @@ -22,7 +22,7 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/typeurl" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" containerstore "github.com/containerd/cri-containerd/pkg/store/container" @@ -59,10 +59,10 @@ func (em *eventMonitor) start() <-chan struct{} { for { select { 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) 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) return } @@ -81,7 +81,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { c := em.c any, err := typeurl.UnmarshalAny(evt.Event) 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 } switch any.(type) { @@ -91,13 +91,13 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { // TODO(random-liu): [P2] Handle containerd-shim exit. case *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) if err != nil { if _, err := c.sandboxStore.Get(e.ContainerID); err == nil { return } - glog.Errorf("Failed to get container %q: %v", e.ContainerID, err) + logrus.WithError(err).Errorf("Failed to get container %q", e.ContainerID) return } if e.Pid != cntr.Status.Get().Pid { @@ -112,7 +112,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { ) if err != nil { 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 } } else { @@ -120,7 +120,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { if _, err = task.Delete(context.Background()); err != nil { // TODO(random-liu): [P0] Enqueue the event and retry. 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 } // Move on to make sure container status is updated. @@ -138,26 +138,26 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { return status, 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. return } case *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) if err != nil { if _, err := c.sandboxStore.Get(e.ContainerID); err == nil { 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) { status.Reason = oomExitReason return status, 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 } } diff --git a/pkg/server/image_load.go b/pkg/server/image_load.go index e55d738df..27ada0db1 100644 --- a/pkg/server/image_load.go +++ b/pkg/server/image_load.go @@ -22,7 +22,7 @@ import ( "os" "path/filepath" - "github.com/golang/glog" + "github.com/sirupsen/logrus" api "github.com/containerd/cri-containerd/pkg/api/v1" "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) } 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. } 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 { 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 } diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go index 836dce793..bf6634fe5 100644 --- a/pkg/server/image_pull.go +++ b/pkg/server/image_pull.go @@ -26,8 +26,8 @@ import ( "github.com/containerd/containerd/errdefs" containerdimages "github.com/containerd/containerd/images" "github.com/containerd/containerd/remotes/docker" - "github.com/golang/glog" imagespec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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. ref := namedRef.String() 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{ @@ -111,9 +111,9 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma } // 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 { - 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. } @@ -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) img := imagestore.Image{ ID: imageID, diff --git a/pkg/server/image_remove.go b/pkg/server/image_remove.go index 523d743dc..3ff6c006b 100644 --- a/pkg/server/image_remove.go +++ b/pkg/server/image_remove.go @@ -21,7 +21,7 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/images" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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. // So we decide to leave it. // 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:]...) continue } cID := desc.Digest.String() 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:]...) continue } diff --git a/pkg/server/image_status.go b/pkg/server/image_status.go index d0dd8082e..7159ea448 100644 --- a/pkg/server/image_status.go +++ b/pkg/server/image_status.go @@ -20,7 +20,7 @@ import ( "encoding/json" "fmt" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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 { info["info"] = string(m) } 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() } diff --git a/pkg/server/instrumented_service.go b/pkg/server/instrumented_service.go index c2aff1cbb..6f2ce041d 100644 --- a/pkg/server/instrumented_service.go +++ b/pkg/server/instrumented_service.go @@ -17,11 +17,12 @@ limitations under the License. package server import ( - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" api "github.com/containerd/cri-containerd/pkg/api/v1" + "github.com/containerd/cri-containerd/pkg/log" ) // 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) { - glog.V(2).Infof("RunPodSandbox with config %+v", r.GetConfig()) + logrus.Infof("RunPodSandbox with config %+v", r.GetConfig()) defer func() { 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 { - 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) } 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() { if err != nil { - glog.Errorf("ListPodSandbox failed, error: %v", err) + logrus.WithError(err).Error("ListPodSandbox failed") } 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) } 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() { 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 { - 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) } 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() { 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 { - 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) } 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() { 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 { - glog.V(2).Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId()) + logrus.Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId()) } }() return in.criContainerdService.RemovePodSandbox(ctx, r) } 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() { 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 { - 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) } 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()) defer func() { if err != nil { - glog.Errorf("CreateContainer within sandbox %q for %+v failed, error: %v", - r.GetPodSandboxId(), r.GetConfig().GetMetadata(), err) + logrus.WithError(err).Errorf("CreateContainer within sandbox %q for %+v failed", + r.GetPodSandboxId(), r.GetConfig().GetMetadata()) } 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()) } }() @@ -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) { - glog.V(2).Infof("StartContainer for %q", r.GetContainerId()) + logrus.Infof("StartContainer for %q", r.GetContainerId()) defer func() { 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 { - 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) } 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() { 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 { - glog.V(5).Infof("ListContainers with filter %+v returns containers %+v", + log.Tracef("ListContainers with filter %+v returns containers %+v", 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) { - glog.V(5).Infof("ContainerStatus for %q", r.GetContainerId()) + log.Tracef("ContainerStatus for %q", r.GetContainerId()) defer func() { 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 { - 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) } 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() { 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 { - 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) } 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() { 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 { - 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) } 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() { 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 { - glog.V(2).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.Infof("ExecSync for %q returns with exit code %d", r.GetContainerId(), res.GetExitCode()) + logrus.Debugf("ExecSync for %q outputs - stdout: %q, stderr: %q", r.GetContainerId(), 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) { - 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()) defer func() { 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 { - 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) } 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() { 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 { - 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) } 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() { 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 { - 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) } 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() { 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 { - glog.V(2).Infof("PullImage %q returns image reference %q", + logrus.Infof("PullImage %q returns image reference %q", 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) { - glog.V(5).Infof("ListImages with filter %+v", r.GetFilter()) + log.Tracef("ListImages with filter %+v", r.GetFilter()) defer func() { 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 { - 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()) } }() @@ -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) { - glog.V(5).Infof("ImageStatus for %q", r.GetImage().GetImage()) + log.Tracef("ImageStatus for %q", r.GetImage().GetImage()) defer func() { 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 { - 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()) } }() @@ -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) { - glog.V(2).Infof("RemoveImage %q", r.GetImage().GetImage()) + logrus.Infof("RemoveImage %q", r.GetImage().GetImage()) defer func() { 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 { - 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) } 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() { if err != nil { - glog.Errorf("ImageFsInfo failed, error: %v", err) + logrus.WithError(err).Error("ImageFsInfo failed") } 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) } 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() { 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 { - 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) } 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() { if err != nil { - glog.Errorf("ListContainerStats failed, error: %v", err) + logrus.WithError(err).Error("ListContainerStats failed") } 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) } 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() { if err != nil { - glog.Errorf("LoadImage failed, error: %v", err) + logrus.WithError(err).Error("LoadImage failed") } 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) diff --git a/pkg/server/io/container_io.go b/pkg/server/io/container_io.go index 0c7504b9b..b8d166a38 100644 --- a/pkg/server/io/container_io.go +++ b/pkg/server/io/container_io.go @@ -23,7 +23,7 @@ import ( "sync" "github.com/containerd/containerd/cio" - "github.com/golang/glog" + "github.com/sirupsen/logrus" cioutil "github.com/containerd/cri-containerd/pkg/ioutil" "github.com/containerd/cri-containerd/pkg/util" @@ -125,24 +125,24 @@ func (c *ContainerIO) Pipe() { wg.Add(1) go func() { 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.stdoutGroup.Close() 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 { wg.Add(1) go func() { 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.stderrGroup.Close() 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) go func() { 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 { // 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 @@ -175,7 +175,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error { c.stdin.Close() // Also closes the containerd side. 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 { if opts.Stdout != nil { @@ -191,7 +191,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error { attachStream := func(key string, close <-chan struct{}) { <-close - glog.V(2).Infof("Attach stream %q closed", key) + logrus.Infof("Attach stream %q closed", key) // Make sure stdin gets closed. if stdinStreamRC != nil { stdinStreamRC.Close() diff --git a/pkg/server/io/exec_io.go b/pkg/server/io/exec_io.go index 72c36b6bc..2614ca4b3 100644 --- a/pkg/server/io/exec_io.go +++ b/pkg/server/io/exec_io.go @@ -21,7 +21,7 @@ import ( "sync" "github.com/containerd/containerd/cio" - "github.com/golang/glog" + "github.com/sirupsen/logrus" cioutil "github.com/containerd/cri-containerd/pkg/ioutil" ) @@ -68,13 +68,13 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { wg.Add(1) go func() { 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 { e.stdin.Close() 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 { 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) { 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() stream.Close() @@ -99,7 +99,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { } e.closer.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 { diff --git a/pkg/server/io/logger.go b/pkg/server/io/logger.go index 2b85ff3e1..68ef5db22 100644 --- a/pkg/server/io/logger.go +++ b/pkg/server/io/logger.go @@ -25,7 +25,7 @@ import ( "os" "time" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" 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 // log file, and decorate the log line into CRI defined format. 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() f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640) if err != nil { @@ -74,11 +74,11 @@ func redirectLogs(path string, rc io.ReadCloser, wc io.WriteCloser, stream Strea for { lineBytes, isPrefix, err := r.ReadLine() if err == io.EOF { - glog.V(4).Infof("Finish redirecting log file %q", path) + logrus.Debugf("Finish redirecting log file %q", path) return } 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 } 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 = append(data, eol) 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. } diff --git a/pkg/server/restart.go b/pkg/server/restart.go index c2079c8aa..22d0cdb4c 100644 --- a/pkg/server/restart.go +++ b/pkg/server/restart.go @@ -31,7 +31,7 @@ import ( "github.com/containerd/typeurl" "github.com/docker/distribution/reference" "github.com/docker/docker/pkg/system" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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 { sb, err := loadSandbox(ctx, sandbox) 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 } - glog.V(4).Infof("Loaded sandbox %+v", sb) + logrus.Debugf("Loaded sandbox %+v", sb) if err := c.sandboxStore.Add(sb); err != nil { 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()) cntr, err := loadContainer(ctx, container, containerDir) 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 } - glog.V(4).Infof("Loaded container %+v", cntr) + logrus.Debugf("Loaded container %+v", cntr) if err := c.containerStore.Add(cntr); err != nil { 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) } 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 { 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. status, err := containerstore.LoadStatus(containerDir, id) 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() } @@ -328,7 +328,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image, for _, i := range cImages { desc, err := i.Config(ctx) 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 } id := desc.Digest.String() @@ -341,27 +341,27 @@ func loadImages(ctx context.Context, cImages []containerd.Image, i := imgs[0] ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default()) 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 } 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 } // Checking existence of top-level snapshot for each image being recovered. unpacked, err := i.IsUnpacked(ctx, snapshotter) 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 } 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. } info, err := getImageInfo(ctx, i) 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 } image := imagestore.Image{ @@ -376,7 +376,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image, name := i.Name() r, err := reference.ParseAnyReference(name) 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 } if _, ok := r.(reference.Canonical); ok { @@ -387,7 +387,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image, // This is an image id. continue } else { - glog.Warningf("Invalid image reference %q", name) + logrus.Warnf("Invalid image reference %q", name) } } images = append(images, image) @@ -407,7 +407,7 @@ func cleanupOrphanedSandboxDirs(cntrs []containerd.Container, sandboxesRoot stri } for _, d := range dirs { 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 } if _, ok := cntrsMap[d.Name()]; ok { @@ -416,9 +416,9 @@ func cleanupOrphanedSandboxDirs(cntrs []containerd.Container, sandboxesRoot stri } sandboxDir := filepath.Join(sandboxesRoot, d.Name()) 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 { - glog.V(4).Infof("Cleanup orphaned sandbox directory %q", sandboxDir) + logrus.Debugf("Cleanup orphaned sandbox directory %q", sandboxDir) } } return nil @@ -436,7 +436,7 @@ func cleanupOrphanedContainerDirs(cntrs []containerd.Container, containersRoot s } for _, d := range dirs { 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 } if _, ok := cntrsMap[d.Name()]; ok { @@ -445,9 +445,9 @@ func cleanupOrphanedContainerDirs(cntrs []containerd.Container, containersRoot s } containerDir := filepath.Join(containersRoot, d.Name()) 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 { - glog.V(4).Infof("Cleanup orphaned container directory %q", containerDir) + logrus.Debugf("Cleanup orphaned container directory %q", containerDir) } } return nil diff --git a/pkg/server/sandbox_portforward.go b/pkg/server/sandbox_portforward.go index def0e6a6a..696e36e3a 100644 --- a/pkg/server/sandbox_portforward.go +++ b/pkg/server/sandbox_portforward.go @@ -25,7 +25,7 @@ import ( "strings" "github.com/containerd/containerd" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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) } - 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.Stdout = stream @@ -106,17 +106,17 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read } go func() { 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() - 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 { 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 } diff --git a/pkg/server/sandbox_remove.go b/pkg/server/sandbox_remove.go index ccfe1e646..1fe92acf7 100644 --- a/pkg/server/sandbox_remove.go +++ b/pkg/server/sandbox_remove.go @@ -22,10 +22,10 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/docker/docker/pkg/system" - "github.com/golang/glog" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" + "github.com/containerd/cri-containerd/pkg/log" "github.com/containerd/cri-containerd/pkg/store" ) @@ -39,7 +39,7 @@ func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime. r.GetPodSandboxId(), err) } // 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()) return &runtime.RemovePodSandboxResponse{}, nil } @@ -88,7 +88,7 @@ func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime. if !errdefs.IsNotFound(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 diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 8d089657d..0d0dfd4a2 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -27,15 +27,16 @@ import ( "github.com/containerd/containerd/oci" "github.com/containerd/typeurl" "github.com/cri-o/ocicni/pkg/ocicni" - "github.com/golang/glog" imagespec "github.com/opencontainers/image-spec/specs-go/v1" runtimespec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "golang.org/x/sys/unix" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "github.com/containerd/cri-containerd/pkg/annotations" 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" "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. id := util.GenerateID() 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 // same sandbox. 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() { if retErr != 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 = "" } @@ -116,7 +117,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run if retErr != nil { // Teardown network if an error is returned. 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 { 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 if uid := securityContext.GetRunAsUser(); uid != nil { @@ -179,7 +180,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run defer func() { if retErr != 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 { // Cleanup the sandbox root directory. if err := c.os.RemoveAll(sandboxRootDir); err != nil { - glog.Errorf("Failed to remove sandbox root directory %q: %v", - sandboxRootDir, err) + logrus.WithError(err).Errorf("Failed to remove sandbox root directory %q", + sandboxRootDir) } } }() @@ -207,14 +208,14 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run defer func() { if retErr != nil { if err = c.unmountSandboxFiles(sandboxRootDir, config); err != nil { - glog.Errorf("Failed to unmount sandbox files in %q: %v", - sandboxRootDir, err) + logrus.WithError(err).Errorf("Failed to unmount sandbox files in %q", + sandboxRootDir) } } }() // 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) // We don't need stdio for sandbox container. task, err := container.NewTask(ctx, containerdio.NullIO) @@ -225,7 +226,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run if retErr != nil { // Cleanup the sandbox container if an error is returned. 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) } } }() diff --git a/pkg/server/sandbox_status.go b/pkg/server/sandbox_status.go index 6da474720..662af1cb9 100644 --- a/pkg/server/sandbox_status.go +++ b/pkg/server/sandbox_status.go @@ -23,8 +23,8 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" - "github.com/golang/glog" runtimespec "github.com/opencontainers/runtime-spec/specs-go" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" @@ -160,7 +160,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox, if err == nil { si.RuntimeSpec = spec } 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) @@ -172,7 +172,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox, si.SnapshotKey = ctrInfo.SnapshotKey si.Snapshotter = ctrInfo.Snapshotter } 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) diff --git a/pkg/server/sandbox_stop.go b/pkg/server/sandbox_stop.go index b86a0c443..39c35fbf9 100644 --- a/pkg/server/sandbox_stop.go +++ b/pkg/server/sandbox_stop.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/cri-o/ocicni/pkg/ocicni" - "github.com/golang/glog" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "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) if err := c.unmountSandboxFiles(sandboxRoot, sandbox.Config); err != nil { diff --git a/pkg/server/service.go b/pkg/server/service.go index b23c44742..e931d6ff6 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -28,9 +28,9 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/sys" "github.com/cri-o/ocicni/pkg/ocicni" - "github.com/golang/glog" runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor" runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp" + "github.com/sirupsen/logrus" "golang.org/x/net/context" "golang.org/x/sys/unix" "google.golang.org/grpc" @@ -140,9 +140,9 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error if err != nil { 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 { - 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) @@ -170,19 +170,19 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error // Run starts the cri-containerd service. 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 { return fmt.Errorf("failed to recover state: %v", err) } // Start event handler. - glog.V(2).Info("Start event monitor") + logrus.Info("Start event monitor") eventMonitorCloseCh := c.eventMonitor.start() // 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( c.snapshotStore, c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter), @@ -191,18 +191,18 @@ func (c *criContainerdService) Run() error { snapshotsSyncer.start() // Start streaming server. - glog.V(2).Info("Start streaming server") + logrus.Info("Start streaming server") streamServerCloseCh := make(chan struct{}) go func() { 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) }() // Start grpc server. // 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) if err != nil && !os.IsNotExist(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{}) go func() { 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) }() @@ -228,17 +228,17 @@ func (c *criContainerdService) Run() error { c.Stop() <-eventMonitorCloseCh - glog.V(2).Info("Event monitor stopped") + logrus.Info("Event monitor stopped") <-streamServerCloseCh - glog.V(2).Info("Stream server stopped") + logrus.Info("Stream server stopped") <-grpcServerCloseCh - glog.V(2).Info("GRPC server stopped") + logrus.Info("GRPC server stopped") return nil } // Stop stops the cri-containerd service. func (c *criContainerdService) Stop() { - glog.V(2).Info("Stop cri-containerd service") + logrus.Info("Stop cri-containerd service") c.eventMonitor.stop() c.streamServer.Stop() // nolint: errcheck c.server.Stop() diff --git a/pkg/server/snapshots.go b/pkg/server/snapshots.go index 99822dde2..846f1d75f 100644 --- a/pkg/server/snapshots.go +++ b/pkg/server/snapshots.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd/errdefs" snapshot "github.com/containerd/containerd/snapshots" - "github.com/golang/glog" + "github.com/sirupsen/logrus" snapshotstore "github.com/containerd/cri-containerd/pkg/store/snapshot" ) @@ -59,7 +59,7 @@ func (s *snapshotsSyncer) start() { // check the resource usage and optimize this. for { 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 } @@ -99,7 +99,7 @@ func (s *snapshotsSyncer) sync() error { usage, err := s.snapshotter.Usage(context.Background(), info.Name) if err != nil { 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 }