Cleanup logrus imports
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
@@ -21,8 +21,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/blockio"
|
||||
)
|
||||
|
||||
@@ -37,7 +36,7 @@ func (c *criService) blockIOClassFromAnnotations(containerName string, container
|
||||
if cls != "" && !blockio.IsEnabled() {
|
||||
if c.config.ContainerdConfig.IgnoreBlockIONotEnabledErrors {
|
||||
cls = ""
|
||||
logrus.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err)
|
||||
log.L.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err)
|
||||
} else {
|
||||
return "", fmt.Errorf("blockio disabled, refusing to set blockio class of container %q to %q", containerName, cls)
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
cni "github.com/containerd/go-cni"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// cniNetConfSyncer is used to reload cni network conf triggered by fs change
|
||||
@@ -70,7 +70,7 @@ func newCNINetConfSyncer(confDir string, netPlugin cni.CNI, loadOpts []cni.Opt)
|
||||
}
|
||||
|
||||
if err := syncer.netPlugin.Load(syncer.loadOpts...); err != nil {
|
||||
logrus.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods")
|
||||
log.L.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods")
|
||||
syncer.updateLastStatus(err)
|
||||
}
|
||||
return syncer, nil
|
||||
@@ -83,7 +83,7 @@ func (syncer *cniNetConfSyncer) syncLoop() error {
|
||||
select {
|
||||
case event, ok := <-syncer.watcher.Events:
|
||||
if !ok {
|
||||
logrus.Debugf("cni watcher channel is closed")
|
||||
log.L.Debugf("cni watcher channel is closed")
|
||||
return nil
|
||||
}
|
||||
// Only reload config when receiving write/rename/remove
|
||||
@@ -92,21 +92,21 @@ func (syncer *cniNetConfSyncer) syncLoop() error {
|
||||
// TODO(fuweid): Might only reload target cni config
|
||||
// files to prevent no-ops.
|
||||
if event.Has(fsnotify.Chmod) || event.Has(fsnotify.Create) {
|
||||
logrus.Debugf("ignore event from cni conf dir: %s", event)
|
||||
log.L.Debugf("ignore event from cni conf dir: %s", event)
|
||||
continue
|
||||
}
|
||||
logrus.Debugf("receiving change event from cni conf dir: %s", event)
|
||||
log.L.Debugf("receiving change event from cni conf dir: %s", event)
|
||||
|
||||
lerr := syncer.netPlugin.Load(syncer.loadOpts...)
|
||||
if lerr != nil {
|
||||
logrus.WithError(lerr).
|
||||
log.L.WithError(lerr).
|
||||
Errorf("failed to reload cni configuration after receiving fs change event(%s)", event)
|
||||
}
|
||||
syncer.updateLastStatus(lerr)
|
||||
|
||||
case err := <-syncer.watcher.Errors:
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to continue sync cni conf change")
|
||||
log.L.WithError(err).Error("failed to continue sync cni conf change")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
)
|
||||
|
||||
@@ -62,7 +61,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
|
||||
state := container.Status.Get().State()
|
||||
if state == runtime.ContainerState_CONTAINER_RUNNING ||
|
||||
state == runtime.ContainerState_CONTAINER_UNKNOWN {
|
||||
logrus.Infof("Forcibly stopping container %q", id)
|
||||
log.L.Infof("Forcibly stopping container %q", id)
|
||||
if err := c.stopContainer(ctx, container, 0); err != nil {
|
||||
return nil, fmt.Errorf("failed to forcibly stop container %q: %w", id, err)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
containerdio "github.com/containerd/containerd/cio"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
cio "github.com/containerd/containerd/pkg/cri/io"
|
||||
@@ -241,7 +240,7 @@ func (c *criService) createContainerLoggers(logPath string, tty bool) (stdout io
|
||||
if stderrCh != nil {
|
||||
<-stderrCh
|
||||
}
|
||||
logrus.Debugf("Finish redirecting log file %q, closing it", logPath)
|
||||
log.L.Debugf("Finish redirecting log file %q, closing it", logPath)
|
||||
f.Close()
|
||||
}()
|
||||
} else {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
containerdio "github.com/containerd/containerd/cio"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/events"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/cri/constants"
|
||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||
@@ -115,7 +116,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string,
|
||||
case exitRes := <-exitCh:
|
||||
exitStatus, exitedAt, err := exitRes.Result()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("failed to get task exit status for %q", id)
|
||||
log.L.WithError(err).Errorf("failed to get task exit status for %q", id)
|
||||
exitStatus = unknownExitCode
|
||||
exitedAt = time.Now()
|
||||
}
|
||||
@@ -128,7 +129,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string,
|
||||
ExitedAt: protobuf.ToTimestamp(exitedAt),
|
||||
}
|
||||
|
||||
logrus.Debugf("received exit event %+v", e)
|
||||
log.L.Debugf("received exit event %+v", e)
|
||||
|
||||
err = func() error {
|
||||
dctx := ctrdutil.NamespacedContext()
|
||||
@@ -147,7 +148,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string,
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e)
|
||||
log.L.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e)
|
||||
em.backOff.enBackOff(id, e)
|
||||
}
|
||||
return
|
||||
@@ -166,7 +167,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string
|
||||
case exitRes := <-exitCh:
|
||||
exitStatus, exitedAt, err := exitRes.Result()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("failed to get task exit status for %q", id)
|
||||
log.L.WithError(err).Errorf("failed to get task exit status for %q", id)
|
||||
exitStatus = unknownExitCode
|
||||
exitedAt = time.Now()
|
||||
}
|
||||
@@ -179,7 +180,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string
|
||||
ExitedAt: protobuf.ToTimestamp(exitedAt),
|
||||
}
|
||||
|
||||
logrus.Debugf("received exit event %+v", e)
|
||||
log.L.Debugf("received exit event %+v", e)
|
||||
|
||||
err = func() error {
|
||||
dctx := ctrdutil.NamespacedContext()
|
||||
@@ -198,7 +199,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("failed to handle container TaskExit event %+v", e)
|
||||
log.L.WithError(err).Errorf("failed to handle container TaskExit event %+v", e)
|
||||
em.backOff.enBackOff(id, e)
|
||||
}
|
||||
return
|
||||
@@ -251,14 +252,14 @@ func (em *eventMonitor) start() <-chan error {
|
||||
for {
|
||||
select {
|
||||
case e := <-em.ch:
|
||||
logrus.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic)
|
||||
log.L.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic)
|
||||
if e.Namespace != constants.K8sContainerdNamespace {
|
||||
logrus.Debugf("Ignoring events in namespace - %q", e.Namespace)
|
||||
log.L.Debugf("Ignoring events in namespace - %q", e.Namespace)
|
||||
break
|
||||
}
|
||||
id, evt, err := convertEvent(e.Event)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to convert event %+v", e)
|
||||
log.L.WithError(err).Errorf("Failed to convert event %+v", e)
|
||||
break
|
||||
}
|
||||
if em.backOff.isInBackOff(id) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
clabels "github.com/containerd/containerd/labels"
|
||||
"github.com/containerd/containerd/log"
|
||||
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
||||
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
|
||||
imagestore "github.com/containerd/containerd/pkg/cri/store/image"
|
||||
@@ -295,7 +296,7 @@ func buildLabels(configLabels, imageConfigLabels map[string]string, containerTyp
|
||||
} else {
|
||||
// In case the image label is invalid, we output a warning and skip adding it to the
|
||||
// container.
|
||||
logrus.WithError(err).Warnf("unable to add image label with key %s to the container", k)
|
||||
log.L.WithError(err).Warnf("unable to add image label with key %s to the container", k)
|
||||
}
|
||||
}
|
||||
// labels from the CRI request (config) will override labels in the image config
|
||||
@@ -517,7 +518,7 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status)
|
||||
func (c *criService) generateAndSendContainerEvent(ctx context.Context, containerID string, sandboxID string, eventType runtime.ContainerEventType) {
|
||||
podSandboxStatus, err := c.getPodSandboxStatus(ctx, sandboxID)
|
||||
if err != nil {
|
||||
logrus.Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err)
|
||||
log.L.Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err)
|
||||
podSandboxStatus = nil
|
||||
}
|
||||
containerStatuses, err := c.getContainerStatuses(ctx, sandboxID)
|
||||
|
||||
@@ -21,8 +21,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/rdt"
|
||||
)
|
||||
|
||||
@@ -40,7 +39,7 @@ func (c *criService) rdtClassFromAnnotations(containerName string, containerAnno
|
||||
|
||||
if err != nil {
|
||||
if !rdt.IsEnabled() && c.config.ContainerdConfig.IgnoreRdtNotEnabledErrors {
|
||||
logrus.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err)
|
||||
log.L.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err)
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
)
|
||||
|
||||
@@ -50,7 +49,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
|
||||
// If the sandbox is still running, not ready, or in an unknown state, forcibly stop it.
|
||||
// Even if it's in a NotReady state, this will close its network namespace, if open.
|
||||
// This can happen if the task process associated with the Pod died or it was killed.
|
||||
logrus.Infof("Forcibly stopping sandbox %q", id)
|
||||
log.L.Infof("Forcibly stopping sandbox %q", id)
|
||||
if err := c.stopPodSandbox(ctx, sandbox); err != nil {
|
||||
return nil, fmt.Errorf("failed to forcibly stop sandbox %q: %w", id, err)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/containerd/typeurl/v2"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
selinux "github.com/opencontainers/selinux/go-selinux"
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
@@ -765,7 +764,7 @@ func (c *criService) getSandboxRuntime(config *runtime.PodSandboxConfig, runtime
|
||||
}
|
||||
|
||||
func logDebugCNIResult(ctx context.Context, sandboxID string, result *cni.Result) {
|
||||
if logrus.GetLevel() < logrus.DebugLevel {
|
||||
if log.GetLevel() < log.DebugLevel {
|
||||
return
|
||||
}
|
||||
cniResult, err := json.Marshal(result)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/oci"
|
||||
"github.com/containerd/containerd/pkg/cri/instrument"
|
||||
"github.com/containerd/containerd/pkg/cri/nri"
|
||||
@@ -144,7 +145,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri.
|
||||
}
|
||||
|
||||
c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter)
|
||||
logrus.Infof("Get image filesystem path %q", c.imageFSPath)
|
||||
log.L.Infof("Get image filesystem path %q", c.imageFSPath)
|
||||
|
||||
if err := c.initPlatform(); err != nil {
|
||||
return nil, fmt.Errorf("initialize platform: %w", err)
|
||||
@@ -203,20 +204,20 @@ func (c *criService) RegisterTCP(s *grpc.Server) error {
|
||||
|
||||
// Run starts the CRI service.
|
||||
func (c *criService) Run() error {
|
||||
logrus.Info("Start subscribing containerd event")
|
||||
log.L.Info("Start subscribing containerd event")
|
||||
c.eventMonitor.subscribe(c.client)
|
||||
|
||||
logrus.Infof("Start recovering state")
|
||||
log.L.Infof("Start recovering state")
|
||||
if err := c.recover(ctrdutil.NamespacedContext()); err != nil {
|
||||
return fmt.Errorf("failed to recover state: %w", err)
|
||||
}
|
||||
|
||||
// Start event handler.
|
||||
logrus.Info("Start event monitor")
|
||||
log.L.Info("Start event monitor")
|
||||
eventMonitorErrCh := c.eventMonitor.start()
|
||||
|
||||
// Start snapshot stats syncer, it doesn't need to be stopped.
|
||||
logrus.Info("Start snapshots syncer")
|
||||
log.L.Info("Start snapshots syncer")
|
||||
snapshotsSyncer := newSnapshotsSyncer(
|
||||
c.snapshotStore,
|
||||
c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter),
|
||||
@@ -229,7 +230,7 @@ func (c *criService) Run() error {
|
||||
var netSyncGroup sync.WaitGroup
|
||||
for name, h := range c.cniNetConfMonitor {
|
||||
netSyncGroup.Add(1)
|
||||
logrus.Infof("Start cni network conf syncer for %s", name)
|
||||
log.L.Infof("Start cni network conf syncer for %s", name)
|
||||
go func(h *cniNetConfSyncer) {
|
||||
cniNetConfMonitorErrCh <- h.syncLoop()
|
||||
netSyncGroup.Done()
|
||||
@@ -248,12 +249,12 @@ func (c *criService) Run() error {
|
||||
}
|
||||
|
||||
// Start streaming server.
|
||||
logrus.Info("Start streaming server")
|
||||
log.L.Info("Start streaming server")
|
||||
streamServerErrCh := make(chan error)
|
||||
go func() {
|
||||
defer close(streamServerErrCh)
|
||||
if err := c.streamServer.Start(true); err != nil && err != http.ErrServerClosed {
|
||||
logrus.WithError(err).Error("Failed to start streaming server")
|
||||
log.L.WithError(err).Error("Failed to start streaming server")
|
||||
streamServerErrCh <- err
|
||||
}
|
||||
}()
|
||||
@@ -281,11 +282,11 @@ func (c *criService) Run() error {
|
||||
if err := <-eventMonitorErrCh; err != nil {
|
||||
eventMonitorErr = err
|
||||
}
|
||||
logrus.Info("Event monitor stopped")
|
||||
log.L.Info("Event monitor stopped")
|
||||
if err := <-streamServerErrCh; err != nil {
|
||||
streamServerErr = err
|
||||
}
|
||||
logrus.Info("Stream server stopped")
|
||||
log.L.Info("Stream server stopped")
|
||||
if eventMonitorErr != nil {
|
||||
return fmt.Errorf("event monitor error: %w", eventMonitorErr)
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/cap"
|
||||
"github.com/containerd/containerd/pkg/userns"
|
||||
cni "github.com/containerd/go-cni"
|
||||
"github.com/opencontainers/selinux/go-selinux"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// networkAttachCount is the minimum number of networks the PodSandbox
|
||||
@@ -35,13 +35,13 @@ const networkAttachCount = 2
|
||||
func (c *criService) initPlatform() (err error) {
|
||||
if userns.RunningInUserNS() {
|
||||
if !(c.config.DisableCgroup && !c.apparmorEnabled() && c.config.RestrictOOMScoreAdj) {
|
||||
logrus.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true")
|
||||
log.L.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true")
|
||||
}
|
||||
}
|
||||
|
||||
if c.config.EnableSelinux {
|
||||
if !selinux.GetEnabled() {
|
||||
logrus.Warn("Selinux is not supported")
|
||||
log.L.Warn("Selinux is not supported")
|
||||
}
|
||||
if r := c.config.SelinuxCategoryRange; r > 0 {
|
||||
selinux.CategoryRange = uint32(r)
|
||||
|
||||
@@ -22,11 +22,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
snapshot "github.com/containerd/containerd/snapshots"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
snapshotstore "github.com/containerd/containerd/pkg/cri/store/snapshot"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
snapshot "github.com/containerd/containerd/snapshots"
|
||||
)
|
||||
|
||||
// snapshotsSyncer syncs snapshot stats periodically. imagefs info and container stats
|
||||
@@ -60,7 +59,7 @@ func (s *snapshotsSyncer) start() {
|
||||
// check the resource usage and optimize this.
|
||||
for {
|
||||
if err := s.sync(); err != nil {
|
||||
logrus.WithError(err).Error("Failed to sync snapshot stats")
|
||||
log.L.WithError(err).Error("Failed to sync snapshot stats")
|
||||
}
|
||||
<-tick.C
|
||||
}
|
||||
@@ -101,7 +100,7 @@ func (s *snapshotsSyncer) sync() error {
|
||||
usage, err := s.snapshotter.Usage(ctx, info.Name)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name)
|
||||
log.L.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user