Skip to content

Commit 4770618

Browse files
authored
Merge pull request containerd#10349 from thaJeztah/less_logrus
Remove some logrus imports
2 parents 0975ec0 + ed64e65 commit 4770618

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

core/mount/mount_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"time"
3030

3131
"github.com/containerd/containerd/v2/pkg/userns"
32-
"github.com/sirupsen/logrus"
32+
"github.com/containerd/log"
3333
"golang.org/x/sys/unix"
3434
)
3535

@@ -253,11 +253,11 @@ func doPrepareIDMappedOverlay(lowerDirs []string, usernsFd int) (tmpLowerDirs []
253253
cleanUp := func() {
254254
for _, lowerDir := range tmpLowerDirs {
255255
if err := unix.Unmount(lowerDir, 0); err != nil {
256-
logrus.WithError(err).Warnf("failed to unmount temp lowerdir %s", lowerDir)
256+
log.L.WithError(err).Warnf("failed to unmount temp lowerdir %s", lowerDir)
257257
}
258258
}
259259
if terr := os.RemoveAll(filepath.Clean(filepath.Join(tmpLowerDirs[0], ".."))); terr != nil {
260-
logrus.WithError(terr).Warnf("failed to remove temporary overlay lowerdir's")
260+
log.L.WithError(terr).Warnf("failed to remove temporary overlay lowerdir's")
261261
}
262262
}
263263
for i, lowerDir := range lowerDirs {

core/transfer/local/pull.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/containerd/errdefs"
3131
"github.com/containerd/log"
3232
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
33-
"github.com/sirupsen/logrus"
3433
)
3534

3635
func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetcher, is transfer.ImageStorer, tops *transfer.Config) error {
@@ -57,28 +56,28 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
5756

5857
// Verify image before pulling.
5958
for vfName, vf := range ts.config.Verifiers {
60-
log := log.G(ctx).WithFields(logrus.Fields{
59+
logger := log.G(ctx).WithFields(log.Fields{
6160
"name": name,
6261
"digest": desc.Digest.String(),
6362
"verifier": vfName,
6463
})
65-
log.Debug("Verifying image pull")
64+
logger.Debug("Verifying image pull")
6665

6766
jdg, err := vf.VerifyImage(ctx, name, desc)
6867
if err != nil {
69-
log.WithError(err).Error("No judgement received from verifier")
68+
logger.WithError(err).Error("No judgement received from verifier")
7069
return fmt.Errorf("blocking pull of %v with digest %v: image verifier %v returned error: %w", name, desc.Digest.String(), vfName, err)
7170
}
72-
log = log.WithFields(logrus.Fields{
71+
logger = logger.WithFields(log.Fields{
7372
"ok": jdg.OK,
7473
"reason": jdg.Reason,
7574
})
7675

7776
if !jdg.OK {
78-
log.Warn("Image verifier blocked pull")
77+
logger.Warn("Image verifier blocked pull")
7978
return fmt.Errorf("image verifier %s blocked pull of %v with digest %v for reason: %v", vfName, name, desc.Digest.String(), jdg.Reason)
8079
}
81-
log.Debug("Image verifier allowed pull")
80+
logger.Debug("Image verifier allowed pull")
8281
}
8382

8483
// TODO: Handle already exists
@@ -89,7 +88,7 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
8988
tops.Progress(transfer.Progress{
9089
Event: "fetching image content",
9190
Name: name,
92-
//Digest: img.Target.Digest.String(),
91+
// Digest: img.Target.Digest.String(),
9392
})
9493
}
9594

@@ -114,7 +113,7 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
114113

115114
ctx, cancel := context.WithCancel(ctx)
116115
if tops.Progress != nil {
117-
progressTracker = NewProgressTracker(name, "downloading") //Pass in first name as root
116+
progressTracker = NewProgressTracker(name, "downloading") // Pass in first name as root
118117
go progressTracker.HandleProgress(ctx, tops.Progress, NewContentStatusTracker(store))
119118
defer progressTracker.Wait()
120119
}

pkg/shim/shim.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
"github.com/containerd/plugin"
4444
"github.com/containerd/plugin/registry"
4545
"github.com/containerd/ttrpc"
46-
"github.com/sirupsen/logrus"
4746
)
4847

4948
// Publisher for events
@@ -171,12 +170,9 @@ func setRuntime() {
171170

172171
func setLogger(ctx context.Context, id string) (context.Context, error) {
173172
l := log.G(ctx)
174-
l.Logger.SetFormatter(&logrus.TextFormatter{
175-
TimestampFormat: log.RFC3339NanoFixed,
176-
FullTimestamp: true,
177-
})
173+
_ = log.SetFormat(log.TextFormat)
178174
if debugFlag {
179-
l.Logger.SetLevel(log.DebugLevel)
175+
_ = log.SetLevel("debug")
180176
}
181177
f, err := openLog(ctx, id)
182178
if err != nil {

pkg/shim/shim_unix.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/containerd/containerd/v2/pkg/sys/reaper"
3131
"github.com/containerd/fifo"
3232
"github.com/containerd/log"
33-
"github.com/sirupsen/logrus"
3433
"golang.org/x/sys/unix"
3534
)
3635

@@ -71,7 +70,7 @@ func serveListener(path string) (net.Listener, error) {
7170
return l, nil
7271
}
7372

74-
func reap(ctx context.Context, logger *logrus.Entry, signals chan os.Signal) error {
73+
func reap(ctx context.Context, logger *log.Entry, signals chan os.Signal) error {
7574
logger.Debug("starting signal loop")
7675

7776
for {
@@ -92,7 +91,7 @@ func reap(ctx context.Context, logger *logrus.Entry, signals chan os.Signal) err
9291
}
9392
}
9493

95-
func handleExitSignals(ctx context.Context, logger *logrus.Entry, cancel context.CancelFunc) {
94+
func handleExitSignals(ctx context.Context, logger *log.Entry, cancel context.CancelFunc) {
9695
ch := make(chan os.Signal, 32)
9796
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
9897

pkg/shim/shim_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"os"
2424

2525
"github.com/containerd/errdefs"
26+
"github.com/containerd/log"
2627
"github.com/containerd/ttrpc"
27-
"github.com/sirupsen/logrus"
2828
)
2929

3030
func setupSignals(config Config) (chan os.Signal, error) {
@@ -46,11 +46,11 @@ func serveListener(path string) (net.Listener, error) {
4646
return nil, errdefs.ErrNotImplemented
4747
}
4848

49-
func reap(ctx context.Context, logger *logrus.Entry, signals chan os.Signal) error {
49+
func reap(ctx context.Context, logger *log.Entry, signals chan os.Signal) error {
5050
return errdefs.ErrNotImplemented
5151
}
5252

53-
func handleExitSignals(ctx context.Context, logger *logrus.Entry, cancel context.CancelFunc) {
53+
func handleExitSignals(ctx context.Context, logger *log.Entry, cancel context.CancelFunc) {
5454
}
5555

5656
func openLog(ctx context.Context, _ string) (io.Writer, error) {

0 commit comments

Comments
 (0)