replace direct uses of logrus for containerd/log

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-06-12 01:19:26 +02:00
parent 8bcd7f3ee1
commit e4ad51ff49
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
36 changed files with 133 additions and 125 deletions

View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"strings"
"github.com/containerd/log"
"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/cli/cli/command"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -105,7 +105,7 @@ func invokeAndCollectHooks(ctx context.Context, dockerCli command.Cli, rootCmd,
var appended bool
nextSteps, appended = appendNextSteps(nextSteps, processedHook)
if !appended {
logrus.Debugf("Plugin %s responded with an empty hook message %q. Ignoring.", pluginName, string(hookReturn))
log.G(ctx).Debugf("Plugin %s responded with an empty hook message %q. Ignoring.", pluginName, string(hookReturn))
}
}
return nextSteps

View File

@ -10,7 +10,7 @@ import (
"runtime"
"sync"
"github.com/sirupsen/logrus"
"github.com/containerd/log"
)
// EnvKey represents the well-known environment variable used to pass the
@ -32,7 +32,7 @@ func NewPluginServer(h func(net.Conn)) (*PluginServer, error) {
if err != nil {
return nil, err
}
logrus.Trace("Plugin server listening on ", l.Addr())
log.L.Logger.Trace("Plugin server listening on ", l.Addr())
if h == nil {
h = func(net.Conn) {}
@ -95,7 +95,7 @@ func (pl *PluginServer) Addr() net.Addr {
//
// The error value is that of the underlying [net.Listner.Close] call.
func (pl *PluginServer) Close() error {
logrus.Trace("Closing plugin server")
log.L.Logger.Trace("Closing plugin server")
// Close connections first to ensure the connections get io.EOF instead
// of a connection reset.
pl.closeAllConns()

View File

@ -4,6 +4,7 @@ import (
"context"
"io"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
@ -12,7 +13,6 @@ import (
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -180,6 +180,6 @@ func resizeTTY(ctx context.Context, dockerCli command.Cli, containerID string) {
// After the above resizing occurs, the call to MonitorTtySize below will handle resetting back
// to the actual size.
if err := MonitorTtySize(ctx, dockerCli, containerID, false); err != nil {
logrus.Debugf("Error monitoring TTY size: %s", err)
log.G(ctx).Debugf("Error monitoring TTY size: %s", err)
}
}

View File

@ -6,6 +6,7 @@ import (
"io"
"os"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
@ -15,7 +16,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -198,7 +198,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *co
}
if err := <-errCh; err != nil {
logrus.Debugf("Error hijack: %s", err)
log.G(ctx).Debugf("Error hijack: %s", err)
return err
}

View File

@ -7,12 +7,12 @@ import (
"runtime"
"sync"
"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)
// The default escape key sequence: ctrl-p, ctrl-q
@ -97,7 +97,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
if h.detachKeys != "" {
customEscapeKeys, err := term.ToBytes(h.detachKeys)
if err != nil {
logrus.Warnf("invalid detach escape keys, using default: %s", err)
log.G(context.TODO()).Warnf("invalid detach escape keys, using default: %s", err)
} else {
escapeKeys = customEscapeKeys
}
@ -129,10 +129,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
}
logrus.Debug("[hijack] End of stdout")
log.G(context.TODO()).Debug("[hijack] End of stdout")
if err != nil {
logrus.Debugf("Error receiveStdout: %s", err)
log.G(context.TODO()).Debugf("Error receiveStdout: %s", err)
}
outputDone <- err
@ -153,7 +153,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// messages will be in normal type.
restoreInput()
logrus.Debug("[hijack] End of stdin")
log.G(context.TODO()).Debug("[hijack] End of stdin")
if _, ok := err.(term.EscapeError); ok {
detached <- err
@ -164,12 +164,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// This error will also occur on the receive
// side (from stdout) where it will be
// propagated back to the caller.
logrus.Debugf("Error sendStdin: %s", err)
log.G(context.TODO()).Debugf("Error sendStdin: %s", err)
}
}
if err := h.resp.CloseWrite(); err != nil {
logrus.Debugf("Couldn't send EOF: %s", err)
log.G(context.TODO()).Debugf("Couldn't send EOF: %s", err)
}
close(inputDone)

View File

@ -2,6 +2,7 @@ package container
import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
@ -13,6 +14,7 @@ import (
"strings"
"time"
"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/opts"
@ -23,7 +25,6 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
cdi "tags.cncf.io/container-device-interface/pkg/parser"
)
@ -366,7 +367,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
mounts := copts.mounts.Value()
if len(mounts) > 0 && copts.volumeDriver != "" {
logrus.Warn("`--volume-driver` is ignored for volumes specified via `--mount`. Use `--mount type=volume,volume-driver=...` instead.")
log.G(context.TODO()).Warn("`--volume-driver` is ignored for volumes specified via `--mount`. Use `--mount type=volume,volume-driver=...` instead.")
}
var binds []string
volumes := copts.volumes.GetMap()

View File

@ -8,6 +8,7 @@ import (
"strings"
"syscall"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
@ -16,7 +17,6 @@ import (
"github.com/moby/sys/signal"
"github.com/moby/term"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -228,7 +228,7 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
return nil
}
logrus.Debugf("Error hijack: %s", err)
log.G(ctx).Debugf("Error hijack: %s", err)
return err
}
}

View File

@ -5,9 +5,9 @@ import (
"os"
gosignal "os/signal"
"github.com/containerd/log"
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)
// ForwardAllSignals forwards signals to the container
@ -49,7 +49,7 @@ func ForwardAllSignals(ctx context.Context, apiClient client.ContainerAPIClient,
}
if err := apiClient.ContainerKill(ctx, cid, sig); err != nil {
logrus.Debugf("Error sending signal: %s", err)
log.G(ctx).Debugf("Error sending signal: %s", err)
}
}
}

View File

@ -8,6 +8,7 @@ import (
"sync"
"time"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
@ -17,7 +18,6 @@ import (
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -337,7 +337,7 @@ func (eh *eventHandler) watch(c <-chan events.Message) {
if !exists {
continue
}
logrus.Debugf("event handler: received event: %v", e)
log.G(context.TODO()).Debugf("event handler: received event: %v", e)
go h(e)
}
}

View File

@ -7,10 +7,10 @@ import (
"sync"
"time"
"github.com/containerd/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type stats struct {
@ -51,7 +51,7 @@ func (s *stats) isKnownContainer(cid string) (int, bool) {
}
func collect(ctx context.Context, s *Stats, cli client.APIClient, streamStats bool, waitFirst *sync.WaitGroup) {
logrus.Debugf("collecting stats for %s", s.Container)
log.G(ctx).Debugf("collecting stats for %s", s.Container)
var (
getFirst bool
previousCPU uint64

View File

@ -8,11 +8,11 @@ import (
"runtime"
"time"
"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)
// resizeTtyTo resizes tty to specific height and width
@ -34,7 +34,7 @@ func resizeTtyTo(ctx context.Context, apiClient client.ContainerAPIClient, id st
}
if err != nil {
logrus.Debugf("Error resize: %s\r", err)
log.G(ctx).Debugf("Error resize: %s\r", err)
}
return err
}

View File

@ -5,12 +5,12 @@ import (
"errors"
"strconv"
"github.com/containerd/log"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containerID string, waitRemove bool) <-chan int {
@ -41,7 +41,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
return
case result := <-resultC:
if result.Error != nil {
logrus.Errorf("Error waiting for container: %v", result.Error.Message)
log.G(ctx).Errorf("Error waiting for container: %v", result.Error.Message)
statusC <- 125
} else {
statusC <- int(result.StatusCode)
@ -50,7 +50,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
if errors.Is(err, context.Canceled) {
return
}
logrus.Errorf("error waiting for container: %v", err)
log.G(ctx).Errorf("error waiting for container: %v", err)
statusC <- 125
}
}()
@ -80,7 +80,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
if v, ok := e.Actor.Attributes["exitCode"]; ok {
code, cerr := strconv.Atoi(v)
if cerr != nil {
logrus.Errorf("failed to convert exitcode '%q' to int: %v", v, cerr)
log.G(ctx).Errorf("failed to convert exitcode '%q' to int: %v", v, cerr)
} else {
exitCode = code
}
@ -93,7 +93,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
go func() {
removeErr = apiClient.ContainerRemove(ctx, containerID, container.RemoveOptions{RemoveVolumes: true})
if removeErr != nil {
logrus.Errorf("error removing container: %v", removeErr)
log.G(ctx).Errorf("error removing container: %v", removeErr)
cancel() // cancel the event Q
}
}()
@ -124,7 +124,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
return
}
case err := <-errq:
logrus.Errorf("error getting events from daemon: %v", err)
log.G(eventCtx).Errorf("error getting events from daemon: %v", err)
return
}
}

View File

@ -8,6 +8,7 @@ import (
"io"
"sort"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/streams"
@ -19,7 +20,6 @@ import (
"github.com/docker/docker/registry"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/tuf/data"
)
@ -256,7 +256,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag()))
}
logrus.Debugf("retrieving target for %s role", t.Role)
log.G(context.TODO()).Debugf("retrieving target for %s role", t.Role)
r, err := convertTarget(t.Target)
return []target{r}, err
}

View File

@ -5,15 +5,16 @@ package inspect
import (
"bytes"
"context"
"encoding/json"
"io"
"strings"
"text/template"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/templates"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// Inspector defines an interface to implement to process elements
@ -84,7 +85,7 @@ func Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFu
}
if err := inspector.Flush(); err != nil {
logrus.Errorf("%s\n", err)
log.G(context.TODO()).Errorf("%s\n", err)
}
if len(inspectErrs) != 0 {

View File

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
@ -15,7 +16,6 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -107,7 +107,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options pluginCreateO
compression := archive.Uncompressed
if options.compress {
logrus.Debugf("compression enabled")
log.G(ctx).Debugf("compression enabled")
compression = archive.Gzip
}

View File

@ -1,8 +1,10 @@
package service
import (
"context"
"encoding/hex"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/trust"
@ -10,7 +12,6 @@ import (
"github.com/docker/docker/registry"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/theupdateframework/notary/tuf/data"
)
@ -43,7 +44,7 @@ func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm
return errors.Wrap(err, "failed to resolve image digest using content trust")
}
resolvedFamiliar := reference.FamiliarString(resolvedImage)
logrus.Debugf("resolved image tag to %s using content trust", resolvedFamiliar)
log.G(context.TODO()).Debugf("resolved image tag to %s using content trust", resolvedFamiliar)
service.TaskTemplate.ContainerSpec.Image = resolvedFamiliar
}
@ -73,7 +74,7 @@ func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference
return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", reference.FamiliarString(ref)))
}
logrus.Debugf("retrieving target for %s role\n", t.Role)
log.G(context.TODO()).Debugf("retrieving target for %s role\n", t.Role)
h, ok := t.Hashes["sha256"]
if !ok {
return nil, errors.New("no valid hash, expecting sha256")

View File

@ -5,11 +5,11 @@ import (
"io"
"os"
"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -74,10 +74,10 @@ func runDialStdio(ctx context.Context, dockerCli command.Cli) error {
func copier(to halfWriteCloser, from halfReadCloser, debugDescription string) error {
defer func() {
if err := from.CloseRead(); err != nil {
logrus.Errorf("error while CloseRead (%s): %v", debugDescription, err)
log.G(context.TODO()).Errorf("error while CloseRead (%s): %v", debugDescription, err)
}
if err := to.CloseWrite(); err != nil {
logrus.Errorf("error while CloseWrite (%s): %v", debugDescription, err)
log.G(context.TODO()).Errorf("error while CloseWrite (%s): %v", debugDescription, err)
}
}()
if _, err := io.Copy(to, from); err != nil {

View File

@ -7,11 +7,11 @@ import (
"sort"
"strings"
"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/image"
"github.com/docker/cli/cli/trust"
"github.com/fvbommel/sortorder"
"github.com/sirupsen/logrus"
"github.com/theupdateframework/notary"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/tuf/data"
@ -70,7 +70,7 @@ func lookupTrustInfo(ctx context.Context, cli command.Cli, remote string) ([]tru
// Retrieve all released signatures, match them, and pretty print them
allSignedTargets, err := notaryRepo.GetAllTargetMetadataByName(tag)
if err != nil {
logrus.Debug(trust.NotaryError(remote, err))
log.G(ctx).Debug(trust.NotaryError(remote, err))
// print an empty table if we don't have signed targets, but have an initialized notary repo
if _, ok := err.(client.ErrNoSuchTarget); !ok {
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("no signatures or cannot access %s", remote)
@ -87,7 +87,7 @@ func lookupTrustInfo(ctx context.Context, cli command.Cli, remote string) ([]tru
// get delegation roles with the canonical key IDs
delegationRoles, err := notaryRepo.GetDelegationRoles()
if err != nil {
logrus.Debugf("no delegation roles found, or error fetching them for %s: %v", remote, err)
log.G(ctx).Debugf("no delegation roles found, or error fetching them for %s: %v", remote, err)
}
return signatureRows, adminRolesWithSigs, delegationRoles, nil

View File

@ -4,6 +4,7 @@
package loader
import (
"context"
"fmt"
"path"
"path/filepath"
@ -13,6 +14,7 @@ import (
"strings"
"time"
"github.com/containerd/log"
interp "github.com/docker/cli/cli/compose/interpolation"
"github.com/docker/cli/cli/compose/schema"
"github.com/docker/cli/cli/compose/template"
@ -24,7 +26,6 @@ import (
"github.com/go-viper/mapstructure/v2"
"github.com/google/shlex"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
@ -519,7 +520,7 @@ func expandUser(srcPath string, lookupEnv template.Mapping) string {
if strings.HasPrefix(srcPath, "~") {
home, ok := lookupEnv("HOME")
if !ok {
logrus.Warn("cannot expand '~', because the environment lacks HOME")
log.G(context.TODO()).Warn("cannot expand '~', because the environment lacks HOME")
return srcPath
}
return strings.Replace(srcPath, "~", home, 1)
@ -559,7 +560,7 @@ func LoadNetworks(source map[string]any, version string) (map[string]types.Netwo
return nil, errors.Errorf("network %s: network.external.name and network.name conflict; only use network.name", name)
}
if versions.GreaterThanOrEqualTo(version, "3.5") {
logrus.Warnf("network %s: network.external.name is deprecated in favor of network.name", name)
log.G(context.TODO()).Warnf("network %s: network.external.name is deprecated in favor of network.name", name)
}
network.Name = network.External.Name
network.External.Name = ""
@ -602,7 +603,7 @@ func LoadVolumes(source map[string]any, version string) (map[string]types.Volume
return nil, errors.Errorf("volume %s: volume.external.name and volume.name conflict; only use volume.name", name)
}
if versions.GreaterThanOrEqualTo(version, "3.4") {
logrus.Warnf("volume %s: volume.external.name is deprecated in favor of volume.name", name)
log.G(context.TODO()).Warnf("volume %s: volume.external.name is deprecated in favor of volume.name", name)
}
volume.Name = volume.External.Name
volume.External.Name = ""
@ -663,7 +664,7 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi
return obj, errors.Errorf("%[1]s %[2]s: %[1]s.external.name and %[1]s.name conflict; only use %[1]s.name", objType, name)
}
if versions.GreaterThanOrEqualTo(details.Version, "3.5") {
logrus.Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name)
log.G(context.TODO()).Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name)
}
obj.Name = obj.External.Name
obj.External.Name = ""

View File

@ -5,15 +5,16 @@ package loader
import (
"bytes"
"context"
"os"
"runtime"
"sort"
"testing"
"time"
"github.com/containerd/log"
"github.com/docker/cli/cli/compose/types"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sirupsen/logrus"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip"
@ -1377,9 +1378,9 @@ func TestLoadVolumesWarnOnDeprecatedExternalNameVersion34(t *testing.T) {
func patchLogrus() (*bytes.Buffer, func()) {
buf := new(bytes.Buffer)
out := logrus.StandardLogger().Out
logrus.SetOutput(buf)
return buf, func() { logrus.SetOutput(out) }
out := log.G(context.TODO()).Logger.Out
log.G(context.TODO()).Logger.SetOutput(buf)
return buf, func() { log.G(context.TODO()).Logger.SetOutput(out) }
}
func TestLoadVolumesWarnOnDeprecatedExternalNameVersion33(t *testing.T) {

View File

@ -1,6 +1,7 @@
package configfile
import (
"context"
"encoding/base64"
"encoding/json"
"io"
@ -8,10 +9,10 @@ import (
"path/filepath"
"strings"
"github.com/containerd/log"
"github.com/docker/cli/cli/config/credentials"
"github.com/docker/cli/cli/config/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// ConfigFile ~/.docker/config.json file info
@ -153,7 +154,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
temp.Close()
if retErr != nil {
if err := os.Remove(temp.Name()); err != nil {
logrus.WithError(err).WithField("file", temp.Name()).Debug("Error cleaning up temp file")
log.G(context.TODO()).WithError(err).WithField("file", temp.Name()).Debug("Error cleaning up temp file")
}
}
}()
@ -303,7 +304,7 @@ func (configFile *ConfigFile) GetAllCredentials() (map[string]types.AuthConfig,
for registryHostname := range configFile.CredentialHelpers {
newAuth, err := configFile.GetAuthConfig(registryHostname)
if err != nil {
logrus.WithError(err).Warnf("Failed to get credentials for registry: %s", registryHostname)
log.G(context.TODO()).WithError(err).Warnf("Failed to get credentials for registry: %s", registryHostname)
continue
}
auths[registryHostname] = newAuth

View File

@ -28,19 +28,19 @@ import (
"syscall"
"time"
"github.com/containerd/log"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// New returns net.Conn
func New(_ context.Context, cmd string, args ...string) (net.Conn, error) {
func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
var (
c commandConn
err error
)
c.cmd = exec.Command(cmd, args...)
// we assume that args never contains sensitive information
logrus.Debugf("commandconn: starting %s with %v", cmd, args)
log.G(ctx).Debugf("commandconn: starting %s with %v", cmd, args)
c.cmd.Env = os.Environ()
c.cmd.SysProcAttr = &syscall.SysProcAttr{}
setPdeathsig(c.cmd)
@ -224,11 +224,11 @@ func (c *commandConn) Close() error {
defer c.closing.Store(false)
if err := c.CloseRead(); err != nil {
logrus.Warnf("commandConn.Close: CloseRead: %v", err)
log.G(context.TODO()).Warnf("commandConn.Close: CloseRead: %v", err)
return err
}
if err := c.CloseWrite(); err != nil {
logrus.Warnf("commandConn.Close: CloseWrite: %v", err)
log.G(context.TODO()).Warnf("commandConn.Close: CloseWrite: %v", err)
return err
}
@ -244,17 +244,17 @@ func (c *commandConn) RemoteAddr() net.Addr {
}
func (c *commandConn) SetDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetDeadline(%v)", t)
log.G(context.TODO()).Debugf("unimplemented call: SetDeadline(%v)", t)
return nil
}
func (c *commandConn) SetReadDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetReadDeadline(%v)", t)
log.G(context.TODO()).Debugf("unimplemented call: SetReadDeadline(%v)", t)
return nil
}
func (c *commandConn) SetWriteDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
log.G(context.TODO()).Debugf("unimplemented call: SetWriteDeadline(%v)", t)
return nil
}
@ -278,7 +278,7 @@ type stderrWriter struct {
}
func (w *stderrWriter) Write(p []byte) (int, error) {
logrus.Debugf("%s%s", w.debugPrefix, string(p))
log.G(context.TODO()).Debug(w.debugPrefix + string(p))
w.stderrMu.Lock()
if w.stderr.Len() > 4096 {
w.stderr.Reset()

View File

@ -1,11 +1,12 @@
package context
import (
"context"
"os"
"github.com/containerd/log"
"github.com/docker/cli/cli/context/store"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
const (
@ -62,7 +63,7 @@ func LoadTLSData(s store.Reader, contextName, endpointName string) (*TLSData, er
case keyKey:
tlsData.Key = data
default:
logrus.Warnf("unknown file in context %s TLS bundle: %s", contextName, f)
log.G(context.TODO()).Warnf("unknown file in context %s TLS bundle: %s", contextName, f)
}
}
return &tlsData, nil

View File

@ -3,22 +3,22 @@ package debug
import (
"os"
"github.com/sirupsen/logrus"
"github.com/containerd/log"
"go.opentelemetry.io/otel"
)
// Enable sets the DEBUG env var to true
// and makes the logger to log at debug level.
func Enable() {
os.Setenv("DEBUG", "1")
logrus.SetLevel(logrus.DebugLevel)
_ = os.Setenv("DEBUG", "1")
_ = log.SetLevel("debug")
}
// Disable sets the DEBUG env var to false
// and makes the logger to log at info level.
func Disable() {
os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel)
_ = os.Setenv("DEBUG", "")
_ = log.SetLevel("info")
}
// IsEnabled checks whether the debug flag is set or not.
@ -33,5 +33,5 @@ func IsEnabled() bool {
// The default is to log to the debug level which is only
// enabled when debugging is enabled.
var OTELErrorHandler otel.ErrorHandler = otel.ErrorHandlerFunc(func(err error) {
logrus.WithError(err).Debug("otel error")
log.L.WithError(err).Debug("otel error")
})

View File

@ -4,20 +4,20 @@ import (
"os"
"testing"
"github.com/sirupsen/logrus"
"github.com/containerd/log"
)
func TestEnable(t *testing.T) {
defer func() {
os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel)
_ = os.Setenv("DEBUG", "")
_ = log.SetLevel("info")
}()
Enable()
if os.Getenv("DEBUG") != "1" {
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
}
if logrus.GetLevel() != logrus.DebugLevel {
t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
if log.GetLevel() != log.DebugLevel {
t.Fatalf("expected log level %v, got %v\n", log.DebugLevel, log.GetLevel())
}
}
@ -26,8 +26,8 @@ func TestDisable(t *testing.T) {
if os.Getenv("DEBUG") != "" {
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
}
if logrus.GetLevel() != logrus.InfoLevel {
t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
if log.GetLevel() != log.InfoLevel {
t.Fatalf("expected log level %v, got %v\n", log.InfoLevel, log.GetLevel())
}
}

View File

@ -5,11 +5,11 @@ import (
"os"
"path/filepath"
"github.com/containerd/log"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/opts"
"github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
@ -135,14 +135,11 @@ func (o *ClientOptions) SetDefaultOptions(flags *pflag.FlagSet) {
// SetLogLevel sets the logrus logging level
func SetLogLevel(logLevel string) {
if logLevel != "" {
lvl, err := logrus.ParseLevel(logLevel)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n", logLevel)
os.Exit(1)
}
logrus.SetLevel(lvl)
} else {
logrus.SetLevel(logrus.InfoLevel)
if logLevel == "" {
logLevel = "info"
}
if err := log.SetLevel(logLevel); err != nil {
_, _ = fmt.Fprintln(os.Stderr, "Unable to parse logging level:", logLevel)
os.Exit(1)
}
}

View File

@ -6,6 +6,7 @@ import (
"net/http"
"strings"
"github.com/containerd/log"
"github.com/distribution/reference"
manifesttypes "github.com/docker/cli/cli/manifest/types"
"github.com/docker/cli/cli/trust"
@ -14,7 +15,6 @@ import (
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// RegistryClient is a client used to communicate with a Docker distribution
@ -86,14 +86,14 @@ func (c *client) MountBlob(ctx context.Context, sourceRef reference.Canonical, t
lu, err := repo.Blobs(ctx).Create(ctx, distributionclient.WithMountFrom(sourceRef))
switch err.(type) {
case distribution.ErrBlobMounted:
logrus.Debugf("mount of blob %s succeeded", sourceRef)
log.G(ctx).Debugf("mount of blob %s succeeded", sourceRef)
return nil
case nil:
default:
return errors.Wrapf(err, "failed to mount blob %s to %s", sourceRef, targetRef)
}
lu.Cancel(ctx)
logrus.Debugf("mount of blob %s created", sourceRef)
log.G(ctx).Debugf("mount of blob %s created", sourceRef)
return ErrBlobCreated{From: sourceRef, Target: targetRef}
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli/manifest/types"
"github.com/docker/distribution"
@ -17,7 +18,6 @@ import (
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// fetchManifest pulls a manifest from a registry and returns it. An error
@ -229,7 +229,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
for _, endpoint := range endpoints {
if endpoint.URL.Scheme != "https" {
if _, confirmedTLS := confirmedTLSRegistries[endpoint.URL.Host]; confirmedTLS {
logrus.Debugf("skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL)
log.G(ctx).Debugf("skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL)
continue
}
}
@ -240,7 +240,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
repoEndpoint := repositoryEndpoint{endpoint: endpoint, info: repoInfo}
repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint)
if err != nil {
logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)
log.G(ctx).Debugf("error %s with repo endpoint %+v", err, repoEndpoint)
if _, ok := err.(ErrHTTPProto); ok {
continue
}
@ -248,7 +248,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
}
if endpoint.URL.Scheme == "http" && !c.insecureRegistry {
logrus.Debugf("skipping non-tls registry endpoint: %s", endpoint.URL)
log.G(ctx).Debugf("skipping non-tls registry endpoint: %s", endpoint.URL)
continue
}
done, err := each(ctx, repo, namedRef)
@ -257,10 +257,10 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
if endpoint.URL.Scheme == "https" {
confirmedTLSRegistries[endpoint.URL.Host] = true
}
logrus.Debugf("continuing on error (%T) %s", err, err)
log.G(ctx).Debugf("continuing on error (%T) %s", err, err)
continue
}
logrus.Debugf("not continuing on error (%T) %s", err, err)
log.G(ctx).Debugf("not continuing on error (%T) %s", err, err)
return err
}
if done {
@ -279,7 +279,7 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi
var serviceOpts registry.ServiceOptions
if insecure {
logrus.Debugf("allowing insecure registry for: %s", reference.Domain(namedRef))
log.G(context.TODO()).Debugf("allowing insecure registry for: %s", reference.Domain(namedRef))
serviceOpts.InsecureRegistries = []string{reference.Domain(namedRef)}
}
registryService, err := registry.NewService(serviceOpts)
@ -287,7 +287,7 @@ func allEndpoints(namedRef reference.Named, insecure bool) ([]registry.APIEndpoi
return []registry.APIEndpoint{}, err
}
endpoints, err := registryService.LookupPullEndpoints(reference.Domain(repoInfo.Name))
logrus.Debugf("endpoints for %s: %v", namedRef, endpoints)
log.G(context.TODO()).Debugf("endpoints for %s: %v", namedRef, endpoints)
return endpoints, err
}

View File

@ -1,11 +1,12 @@
package streams
import (
"context"
"io"
"os"
"github.com/containerd/log"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)
// Out is an output stream to write normal program output. It implements
@ -42,7 +43,7 @@ func (o *Out) GetTtySize() (height uint, width uint) {
}
ws, err := term.GetWinsize(o.fd)
if err != nil {
logrus.WithError(err).Debug("Error getting TTY size")
log.G(context.TODO()).WithError(err).Debug("Error getting TTY size")
if ws == nil {
return 0, 0
}

View File

@ -12,6 +12,7 @@ import (
"path/filepath"
"time"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli/config"
"github.com/docker/distribution/registry/client/auth"
@ -22,7 +23,6 @@ import (
"github.com/docker/go-connections/tlsconfig"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/theupdateframework/notary"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/passphrase"
@ -108,7 +108,7 @@ func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo
if err != nil {
return nil, err
}
logrus.Debugf("reading certificate directory: %s", certDir)
log.G(context.TODO()).Debugf("reading certificate directory: %s", certDir)
if err := registry.ReadCertsDirectory(cfg, certDir); err != nil {
return nil, err
@ -143,7 +143,7 @@ func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo
resp, err := pingClient.Do(req)
if err != nil {
// Ignore error on ping to operate in offline mode
logrus.Debugf("Error pinging notary server %q: %s", endpointStr, err)
log.G(context.TODO()).Debugf("Error pinging notary server %q: %s", endpointStr, err)
} else {
defer resp.Body.Close()
@ -212,7 +212,7 @@ func GetPassphraseRetriever(in io.Reader, out io.Writer) notary.PassRetriever {
func NotaryError(repoName string, err error) error {
switch err.(type) {
case *json.SyntaxError:
logrus.Debugf("Notary syntax error: %s", err)
log.G(context.TODO()).Debugf("Notary syntax error: %s", err)
return errors.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName)
case signed.ErrExpired:
return errors.Errorf("Error: remote repository %s out-of-date: %v", repoName, err)

View File

@ -9,6 +9,7 @@ import (
"strings"
"syscall"
"github.com/containerd/log"
"github.com/docker/cli/cli"
pluginmanager "github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli-plugins/socket"
@ -21,7 +22,6 @@ import (
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.opentelemetry.io/otel"
@ -43,7 +43,7 @@ func dockerMain() int {
fmt.Fprintln(os.Stderr, err)
return 1
}
logrus.SetOutput(dockerCli.Err())
log.G(ctx).Logger.SetOutput(dockerCli.Err())
otel.SetErrorHandler(debug.OTELErrorHandler)
if err := runDocker(ctx, dockerCli); err != nil {

View File

@ -7,9 +7,9 @@ import (
"os"
"testing"
"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/debug"
"github.com/sirupsen/logrus"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -29,7 +29,7 @@ func TestClientDebugEnabled(t *testing.T) {
err = cmd.PersistentPreRunE(cmd, []string{})
assert.NilError(t, err)
assert.Check(t, is.Equal("1", os.Getenv("DEBUG")))
assert.Check(t, is.Equal(logrus.DebugLevel, logrus.GetLevel()))
assert.Check(t, is.Equal(log.DebugLevel, log.GetLevel()))
}
var discard = io.NopCloser(bytes.NewBuffer(nil))

View File

@ -1,6 +1,7 @@
package opts
import (
"context"
"encoding/csv"
"errors"
"fmt"
@ -9,9 +10,9 @@ import (
"strconv"
"strings"
"github.com/containerd/log"
mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/go-units"
"github.com/sirupsen/logrus"
)
// MountOpt is a Value type for parsing mounts
@ -114,7 +115,7 @@ func (m *MountOpt) Set(value string) error {
if err != nil {
return fmt.Errorf("invalid value for %s: %s", key, val)
}
logrus.Warn("bind-nonrecursive is deprecated, use bind-recursive=disabled instead")
log.G(context.TODO()).Warn("bind-nonrecursive is deprecated, use bind-recursive=disabled instead")
case "bind-recursive":
switch val {
case "enabled": // read-only mounts are recursively read-only if Engine >= v25 && kernel >= v5.12, otherwise writable

View File

@ -1,6 +1,7 @@
package opts
import (
"context"
"encoding/csv"
"errors"
"fmt"
@ -9,9 +10,9 @@ import (
"strconv"
"strings"
"github.com/containerd/log"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"
)
const (
@ -149,7 +150,7 @@ func ConvertPortToPortConfig(
for _, binding := range portBindings[port] {
if p := net.ParseIP(binding.HostIP); p != nil && !p.IsUnspecified() {
logrus.Warnf("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'", net.JoinHostPort(binding.HostIP, binding.HostPort), port)
log.G(context.TODO()).Warnf("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'", net.JoinHostPort(binding.HostIP, binding.HostPort), port)
}
startHostPort, endHostPort, err := nat.ParsePortRange(binding.HostPort)

View File

@ -2,12 +2,13 @@ package opts
import (
"bytes"
"context"
"os"
"testing"
"github.com/containerd/log"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -342,7 +343,8 @@ func TestConvertPortToPortConfigWithIP(t *testing.T) {
}
var b bytes.Buffer
logrus.SetOutput(&b)
log.G(context.TODO()).Logger.SetOutput(&b)
defer log.G(context.TODO()).Logger.SetOutput(os.Stderr)
for _, tc := range testCases {
tc := tc
t.Run(tc.value, func(t *testing.T) {
@ -357,7 +359,6 @@ func TestConvertPortToPortConfigWithIP(t *testing.T) {
}
})
}
logrus.SetOutput(os.Stderr)
}
func assertContains(t *testing.T, portConfigs []swarm.PortConfig, expected swarm.PortConfig) {

View File

@ -8,6 +8,7 @@ go 1.21.0
require (
dario.cat/mergo v1.0.0
github.com/containerd/log v0.1.0
github.com/containerd/platforms v0.2.1
github.com/creack/pty v1.1.21
github.com/distribution/reference v0.6.0
@ -31,7 +32,6 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/theupdateframework/notary v0.7.1-0.20210315103452-bf96a202a09a
@ -60,7 +60,6 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
@ -82,6 +81,7 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
go.etcd.io/etcd/raft/v3 v3.5.6 // indirect