mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: replace uses of errdefs package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
)
|
||||
@@ -22,7 +23,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (*container.Pa
|
||||
return nil, containerFileNotFound{path, name}
|
||||
}
|
||||
// TODO(thaJeztah): check if daemon.containerStatPath returns any errors that are not typed; if not, then return as-is
|
||||
if errdefs.IsInvalidParameter(err) {
|
||||
if cerrdefs.IsInvalidArgument(err) {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errdefs.System(err)
|
||||
@@ -45,7 +46,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
|
||||
return nil, nil, containerFileNotFound{path, name}
|
||||
}
|
||||
// TODO(thaJeztah): check if daemon.containerArchivePath returns any errors that are not typed; if not, then return as-is
|
||||
if errdefs.IsInvalidParameter(err) {
|
||||
if cerrdefs.IsInvalidArgument(err) {
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, nil, errdefs.System(err)
|
||||
@@ -71,7 +72,7 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
|
||||
return containerFileNotFound{path, name}
|
||||
}
|
||||
// TODO(thaJeztah): check if daemon.containerExtractToDir returns any errors that are not typed; if not, then return as-is
|
||||
if errdefs.IsInvalidParameter(err) {
|
||||
if cerrdefs.IsInvalidArgument(err) {
|
||||
return err
|
||||
}
|
||||
return errdefs.System(err)
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/api/types/swarm/runtime"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/plugin"
|
||||
v2 "github.com/docker/docker/plugin/v2"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@@ -200,7 +200,7 @@ func (p *Controller) Wait(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func isNotFound(err error) bool {
|
||||
return errdefs.IsNotFound(err)
|
||||
return cerrdefs.IsNotFound(err)
|
||||
}
|
||||
|
||||
// Shutdown is the shutdown phase from swarmkit
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/libnetwork"
|
||||
"github.com/docker/go-connections/nat"
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
@@ -66,7 +66,7 @@ func (r *controller) Task() (*api.Task, error) {
|
||||
func (r *controller) ContainerStatus(ctx context.Context) (*api.ContainerStatus, error) {
|
||||
ctnr, err := r.adapter.inspect(ctx)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
@@ -77,7 +77,7 @@ func (r *controller) ContainerStatus(ctx context.Context) (*api.ContainerStatus,
|
||||
func (r *controller) PortStatus(ctx context.Context) (*api.PortStatus, error) {
|
||||
ctnr, err := r.adapter.inspect(ctx)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (r *controller) Prepare(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
if err := r.adapter.create(ctx); err != nil {
|
||||
if errdefs.IsConflict(err) {
|
||||
if cerrdefs.IsConflict(err) {
|
||||
if _, err := r.adapter.inspect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func (r *controller) Shutdown(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err := r.adapter.shutdown(ctx); err != nil {
|
||||
if !errdefs.IsNotFound(err) && !errdefs.IsNotModified(err) {
|
||||
if !cerrdefs.IsNotFound(err) && !cerrdefs.IsNotModified(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -390,7 +390,7 @@ func (r *controller) Shutdown(ctx context.Context) error {
|
||||
// Try removing networks referenced in this task in case this
|
||||
// task is the last one referencing it
|
||||
if err := r.adapter.removeNetworks(ctx); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -409,7 +409,7 @@ func (r *controller) Terminate(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err := r.adapter.terminate(ctx); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ func (r *controller) Remove(ctx context.Context) error {
|
||||
|
||||
// It may be necessary to shut down the task before removing it.
|
||||
if err := r.Shutdown(ctx); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
// This may fail if the task was already shut down.
|
||||
@@ -439,7 +439,7 @@ func (r *controller) Remove(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err := r.adapter.remove(ctx); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ func (r *controller) waitReady(pctx context.Context) error {
|
||||
|
||||
ctnr, err := r.adapter.inspect(ctx)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
return errors.Wrap(err, "inspect container failed")
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
volumetypes "github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/daemon/cluster/convert"
|
||||
"github.com/docker/docker/errdefs"
|
||||
@@ -90,7 +91,7 @@ func (c *Cluster) RemoveVolume(nameOrID string, force bool) error {
|
||||
return c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
||||
volume, err := getVolume(ctx, state.controlClient, nameOrID)
|
||||
if err != nil {
|
||||
if force && errdefs.IsNotFound(err) {
|
||||
if force && cerrdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
@@ -899,7 +900,7 @@ func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerPrefi
|
||||
nc, err := daemon.GetContainer(connectedContainerPrefixOrName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("joining network namespace of container: %w", err)
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
// Deliberately masking "not found" errors, because failing to find
|
||||
// the network container is a system error. We return a system error,
|
||||
// not an "invalid parameter" because getNetworkedContainer is called
|
||||
|
||||
@@ -85,7 +85,7 @@ func (c cacheAdaptor) Get(id image.ID) (*image.Image, error) {
|
||||
|
||||
var config container.Config
|
||||
if err := readJSON(ctx, c.is.content, configDesc, &config); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"configDigest": dgst,
|
||||
"error": err,
|
||||
|
||||
@@ -87,7 +87,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s
|
||||
return nil, nil, err
|
||||
}
|
||||
imgDesc, err := i.resolveDescriptor(ctx, refOrID)
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
return nil, nil, err
|
||||
}
|
||||
if img != nil {
|
||||
@@ -152,7 +152,7 @@ func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConf
|
||||
|
||||
img, err := i.GetImage(ctx, name, backend.GetImageOpts{Platform: platform})
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) && img != nil && platform != nil {
|
||||
if cerrdefs.IsNotFound(err) && img != nil && platform != nil {
|
||||
imgPlat := ocispec.Platform{
|
||||
OS: img.OS,
|
||||
Architecture: img.BaseImgArch(),
|
||||
|
||||
@@ -259,7 +259,7 @@ func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, platf
|
||||
if err := i.ensureDanglingImage(ctx, img); err != nil {
|
||||
log.G(ctx).WithError(err).Warnf("failed to keep the previous image for %s as dangling", img.Name)
|
||||
}
|
||||
} else if !errdefs.IsNotFound(err) {
|
||||
} else if !cerrdefs.IsNotFound(err) {
|
||||
log.G(ctx).WithError(err).Warn("failed to retrieve image: %w", err)
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -241,7 +241,7 @@ func (i *ImageService) multiPlatformSummary(ctx context.Context, img c8dimages.I
|
||||
})
|
||||
|
||||
available, err := img.CheckContentAvailable(ctx)
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
logger.WithError(err).Warn("checking availability of platform specific manifest failed")
|
||||
return nil
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func (i *ImageService) multiPlatformSummary(ctx context.Context, img c8dimages.I
|
||||
// so we don't error out the whole list in case the error is related to
|
||||
// the content itself (e.g. corrupted data) or just manifest kind that
|
||||
// we don't know about (yet).
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
logger.WithError(err).Debug("pseudo image check failed")
|
||||
return nil
|
||||
}
|
||||
@@ -660,7 +660,7 @@ func setupLabelFilter(ctx context.Context, store content.Store, fltrs filters.Ar
|
||||
}
|
||||
var cfg configLabels
|
||||
if err := readJSON(ctx, store, desc, &cfg); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/containerd/containerd/v2/core/content"
|
||||
"github.com/containerd/containerd/v2/pkg/namespaces"
|
||||
"github.com/containerd/containerd/v2/plugins/content/local"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/testutils/labelstore"
|
||||
"github.com/docker/docker/internal/testutils/specialimage"
|
||||
"github.com/moby/go-archive"
|
||||
@@ -62,7 +62,7 @@ func TestImageLoadMissing(t *testing.T) {
|
||||
|
||||
err = tryLoad(ctx, t, imgDataDir, linuxAmd64)
|
||||
assert.Check(t, is.Error(err, "image emptyindex:latest was loaded, but doesn't provide the requested platform (linux/amd64)"))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
clearStore(ctx, t)
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestImageLoadMissing(t *testing.T) {
|
||||
|
||||
err = tryLoad(ctx, t, imgDataDir, linuxArm64)
|
||||
assert.Check(t, is.ErrorContains(err, "doesn't provide the requested platform (linux/arm64)"))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
|
||||
clearStore(ctx, t)
|
||||
@@ -87,7 +87,7 @@ func TestImageLoadMissing(t *testing.T) {
|
||||
t.Run("platform not included in index", func(t *testing.T) {
|
||||
err = tryLoad(ctx, t, imgDataDir, linuxArmv5)
|
||||
assert.Check(t, is.Error(err, "image multiplatform:latest was loaded, but doesn't provide the requested platform (linux/arm/v5)"))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
|
||||
clearStore(ctx, t)
|
||||
@@ -106,7 +106,7 @@ func TestImageLoadMissing(t *testing.T) {
|
||||
|
||||
err = tryLoad(ctx, t, imgDataDir, linuxArm64)
|
||||
assert.Check(t, is.ErrorContains(err, "requested platform (linux/arm64) found, but some content is missing"))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor
|
||||
opts = append(opts, containerd.WithResolver(resolver))
|
||||
|
||||
oldImage, err := i.resolveImage(ctx, ref.String())
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ func findMissingMountable(ctx context.Context, store content.Store, queue *jobs,
|
||||
|
||||
sources, err := getDigestSources(ctx, store, target.Digest)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
log.G(ctx).WithField("target", target).Debug("distribution source label not found")
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
c8dimages "github.com/containerd/containerd/v2/core/images"
|
||||
"github.com/containerd/containerd/v2/pkg/namespaces"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/testutils/specialimage"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -279,10 +279,10 @@ func singleManifestSelected(platform ocispec.Platform) func(t *testing.T, img c8
|
||||
|
||||
// candidateNotFound asserts that the no matching candidate was found.
|
||||
func candidateNotFound(t *testing.T, _ c8dimages.Image, desc ocispec.Descriptor, err error) {
|
||||
assert.Check(t, errdefs.IsNotFound(err), "expected NotFound error, got %v, candidate: %v", err, desc.Platform)
|
||||
assert.Check(t, cerrdefs.IsNotFound(err), "expected NotFound error, got %v, candidate: %v", err, desc.Platform)
|
||||
}
|
||||
|
||||
// multipleCandidates asserts that multiple matching candidates were found and no decision could be made.
|
||||
func multipleCandidates(t *testing.T, _ c8dimages.Image, desc ocispec.Descriptor, err error) {
|
||||
assert.Check(t, errdefs.IsConflict(err), "expected Conflict error, got %v, candidate: %v", err, desc.Platform)
|
||||
assert.Check(t, cerrdefs.IsConflict(err), "expected Conflict error, got %v, candidate: %v", err, desc.Platform)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/v2/pkg/namespaces"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/testutils/specialimage"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -54,7 +54,7 @@ func TestImageMultiplatformSaveShallowWithNative(t *testing.T) {
|
||||
})
|
||||
t.Run("export missing", func(t *testing.T) {
|
||||
err = imgSvc.ExportImage(ctx, []string{img.Name}, &arm64, io.Discard)
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestImageMultiplatformSaveShallowWithoutNative(t *testing.T) {
|
||||
})
|
||||
t.Run("export native", func(t *testing.T) {
|
||||
err = imgSvc.ExportImage(ctx, []string{img.Name}, &native, io.Discard)
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
t.Run("export arm64", func(t *testing.T) {
|
||||
err = imgSvc.ExportImage(ctx, []string{img.Name}, &arm64, io.Discard)
|
||||
|
||||
@@ -182,7 +182,7 @@ func (p *pullProgress) UpdateProgress(ctx context.Context, ongoing *jobs, out pr
|
||||
for idx, desc := range p.layers {
|
||||
sn, err := findMatchingSnapshot(ctx, p.snapshotter, desc)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/oci"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
volumemounts "github.com/docker/docker/volume/mounts"
|
||||
@@ -110,7 +110,7 @@ func (daemon *Daemon) populateVolume(ctx context.Context, c *container.Container
|
||||
uid, gid := daemon.idMapping.RootPair()
|
||||
volumePath, cleanup, err := mnt.Setup(ctx, c.MountLabel, idtools.Identity{UID: uid, GID: gid}, nil)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
log.G(ctx).WithError(err).Debugf("can't copy data from %s:%s, to %s", c.ID, mnt.Destination, volumePath)
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
containerd "github.com/containerd/containerd/v2/client"
|
||||
"github.com/containerd/containerd/v2/defaults"
|
||||
"github.com/containerd/containerd/v2/pkg/dialer"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/distribution/reference"
|
||||
dist "github.com/docker/distribution"
|
||||
@@ -52,7 +53,6 @@ import (
|
||||
"github.com/docker/docker/distribution"
|
||||
dmetadata "github.com/docker/docker/distribution/metadata"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/internal/metrics"
|
||||
"github.com/docker/docker/layer"
|
||||
@@ -361,7 +361,7 @@ func (daemon *Daemon) restore(cfg *configStore) error {
|
||||
|
||||
var es *containerd.ExitStatus
|
||||
|
||||
if err := c.RestoreTask(context.Background(), daemon.containerd); err != nil && !errdefs.IsNotFound(err) {
|
||||
if err := c.RestoreTask(context.Background(), daemon.containerd); err != nil && !cerrdefs.IsNotFound(err) {
|
||||
logger(c).WithError(err).Error("failed to restore container with containerd")
|
||||
return
|
||||
}
|
||||
@@ -378,13 +378,13 @@ func (daemon *Daemon) restore(cfg *configStore) error {
|
||||
if !alive {
|
||||
logger(c).Debug("cleaning up dead container process")
|
||||
es, err = tsk.Delete(context.Background())
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
logger(c).WithError(err).Error("failed to delete task from containerd")
|
||||
return
|
||||
}
|
||||
} else if !cfg.LiveRestoreEnabled {
|
||||
logger(c).Debug("shutting down container considered alive by containerd")
|
||||
if err := daemon.shutdownContainer(c); err != nil && !errdefs.IsNotFound(err) {
|
||||
if err := daemon.shutdownContainer(c); err != nil && !cerrdefs.IsNotFound(err) {
|
||||
baseLogger.WithError(err).Error("error shutting down container")
|
||||
return
|
||||
}
|
||||
@@ -699,7 +699,7 @@ func (daemon *Daemon) restartSwarmContainers(ctx context.Context, cfg *configSto
|
||||
func (daemon *Daemon) registerLink(parent, child *container.Container, alias string) error {
|
||||
fullName := path.Join(parent.Name, alias)
|
||||
if err := daemon.containersReplica.ReserveName(fullName, child.ID); err != nil {
|
||||
if errdefs.IsConflict(err) {
|
||||
if cerrdefs.IsConflict(err) {
|
||||
log.G(context.TODO()).Warnf("error registering link for %s, to %s, as alias %s, ignoring: %v", parent.ID, child.ID, alias, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/libnetwork"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
volumesservice "github.com/docker/docker/volume/service"
|
||||
@@ -310,7 +310,7 @@ func TestFindNetworkErrorType(t *testing.T) {
|
||||
_, err := d.FindNetwork("fakeNet")
|
||||
var nsn libnetwork.ErrNoSuchNetwork
|
||||
ok := errors.As(err, &nsn)
|
||||
if !errdefs.IsNotFound(err) || !ok {
|
||||
if !cerrdefs.IsNotFound(err) || !ok {
|
||||
t.Error("The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/cgroups/v3"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/api/types/blkiodev"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
@@ -1535,7 +1536,7 @@ func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *
|
||||
}
|
||||
child, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
// Trying to link to a non-existing container is not valid, and
|
||||
// should return an "invalid parameter" error. Returning a "not
|
||||
// found" error here would make the client report the container's
|
||||
@@ -1548,7 +1549,7 @@ func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *
|
||||
cid := child.HostConfig.NetworkMode.ConnectedContainer()
|
||||
child, err = daemon.GetContainer(cid)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
// Trying to link to a non-existing container is not valid, and
|
||||
// should return an "invalid parameter" error. Returning a "not
|
||||
// found" error here would make the client report the container's
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@@ -75,7 +75,7 @@ func TestContainerDelete(t *testing.T) {
|
||||
d.containers.Add(c.ID, c)
|
||||
|
||||
err := d.ContainerRm(c.ID, &backend.ContainerRmConfig{ForceRemove: false})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsConflict))
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsConflict))
|
||||
assert.Check(t, is.ErrorContains(err, tc.errMsg))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"io"
|
||||
"runtime"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
@@ -166,7 +166,7 @@ func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConf
|
||||
}
|
||||
|
||||
img, err := i.GetImage(ctx, name, backend.GetImageOpts{Platform: platform})
|
||||
if errdefs.IsNotFound(err) && img != nil && platform != nil {
|
||||
if cerrdefs.IsNotFound(err) && img != nil && platform != nil {
|
||||
imgPlat := ocispec.Platform{
|
||||
OS: img.OS,
|
||||
Architecture: img.BaseImgArch(),
|
||||
@@ -211,7 +211,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s
|
||||
if err != nil && opts.PullOption == backend.PullOptionNoPull {
|
||||
return nil, nil, err
|
||||
}
|
||||
if err != nil && !errdefs.IsNotFound(err) {
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
return nil, nil, err
|
||||
}
|
||||
if img != nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
@@ -162,7 +163,7 @@ func imageDeleteFailed(ref string, err error) bool {
|
||||
switch {
|
||||
case err == nil:
|
||||
return false
|
||||
case errdefs.IsConflict(err), errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
|
||||
case cerrdefs.IsConflict(err), errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
|
||||
return true
|
||||
default:
|
||||
log.G(context.TODO()).Warnf("failed to prune image %s: %v", ref, err)
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/v2/core/leases"
|
||||
"github.com/containerd/containerd/v2/pkg/namespaces"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/distribution"
|
||||
progressutils "github.com/docker/docker/distribution/utils"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/metrics"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
@@ -43,7 +43,7 @@ func (i *ImageService) PullImage(ctx context.Context, ref reference.Named, platf
|
||||
|
||||
// Note that this is a special case where GetImage returns both an image
|
||||
// and an error: https://github.com/docker/docker/blob/v20.10.7/daemon/images/image.go#L175-L183
|
||||
if errdefs.IsNotFound(err) && img != nil {
|
||||
if cerrdefs.IsNotFound(err) && img != nil {
|
||||
po := streamformatter.NewJSONProgressOutput(outStream, false)
|
||||
progress.Messagef(po, "", `WARNING: %s`, err.Error())
|
||||
log.G(ctx).WithError(err).WithField("image", reference.FamiliarName(ref)).Warn("ignoring platform mismatch on single-arch image")
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/rootless"
|
||||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"github.com/pkg/errors"
|
||||
@@ -180,7 +179,7 @@ func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version,
|
||||
}
|
||||
|
||||
if err := daemon.fillRootlessVersion(ctx, v); err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warn("Failed to fill rootless version")
|
||||
@@ -207,7 +206,7 @@ func (daemon *Daemon) populateInitCommit(ctx context.Context, v *system.Info, cf
|
||||
|
||||
rv, err := exec.CommandContext(ctx, initBinary, "--version").Output()
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warnf("Failed to retrieve %s version", initBinary)
|
||||
@@ -262,7 +261,7 @@ func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version)
|
||||
err = func() error {
|
||||
rv, err := exec.CommandContext(ctx, "slirp4netns", "--version").Output()
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warn("Failed to retrieve slirp4netns version")
|
||||
@@ -290,7 +289,7 @@ func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version)
|
||||
err = func() error {
|
||||
out, err := exec.CommandContext(ctx, "vpnkit", "--version").Output()
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warn("Failed to retrieve vpnkit version")
|
||||
@@ -426,7 +425,7 @@ func noNewPrivileges(cfg *config.Config) bool {
|
||||
func (daemon *Daemon) populateContainerdCommit(ctx context.Context, v *system.Commit) error {
|
||||
rv, err := daemon.containerd.Version(ctx)
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warnf("Failed to retrieve containerd version")
|
||||
@@ -439,7 +438,7 @@ func (daemon *Daemon) populateContainerdCommit(ctx context.Context, v *system.Co
|
||||
func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *types.Version) error {
|
||||
rv, err := daemon.containerd.Version(ctx)
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warn("Failed to retrieve containerd version")
|
||||
@@ -480,7 +479,7 @@ func populateInitVersion(ctx context.Context, cfg *configStore, v *types.Version
|
||||
|
||||
rv, err := exec.CommandContext(ctx, initBinary, "--version").Output()
|
||||
if err != nil {
|
||||
if errdefs.IsContext(err) {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).WithError(err).Warnf("Failed to retrieve %s version", initBinary)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
@@ -108,7 +109,7 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, stopSign
|
||||
}
|
||||
|
||||
if err := task.Kill(context.Background(), stopSignal); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
unpause = false
|
||||
log.G(context.TODO()).WithFields(log.Fields{
|
||||
"error": err,
|
||||
@@ -205,7 +206,7 @@ func (daemon *Daemon) Kill(container *containerpkg.Container) error {
|
||||
// killPossiblyDeadProcess is a wrapper around killSig() suppressing "no such process" error.
|
||||
func (daemon *Daemon) killPossiblyDeadProcess(container *containerpkg.Container, sig syscall.Signal) error {
|
||||
err := daemon.killWithSignal(container, sig)
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
err = errNoSuchProcess{container.GetPID(), sig}
|
||||
log.G(context.TODO()).Debug(err)
|
||||
return err
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
@@ -244,7 +245,7 @@ func (daemon *Daemon) filterByNameIDMatches(view *container.View, filter *listCo
|
||||
for id := range matches {
|
||||
c, err := view.Get(id)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
// ignore error
|
||||
continue
|
||||
}
|
||||
@@ -375,7 +376,7 @@ func (daemon *Daemon) foldFilter(ctx context.Context, view *container.View, conf
|
||||
|
||||
func idOrNameFilter(view *container.View, value string) (*container.Snapshot, error) {
|
||||
filter, err := view.Get(value)
|
||||
if err != nil && errdefs.IsNotFound(err) {
|
||||
if err != nil && cerrdefs.IsNotFound(err) {
|
||||
// Try name search instead
|
||||
found := ""
|
||||
searchName := strings.TrimPrefix(value, "/")
|
||||
@@ -634,7 +635,7 @@ func (daemon *Daemon) refreshImage(ctx context.Context, s *container.Snapshot) *
|
||||
// reason. Update the Image to the specific ID of the original image it
|
||||
// resolved to when the container was created.
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"error": err,
|
||||
"containerID": c.ID,
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/metrics"
|
||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||
"github.com/docker/docker/restartmanager"
|
||||
@@ -250,7 +250,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
|
||||
if !c.Running {
|
||||
ctr, err := daemon.containerd.LoadContainer(context.Background(), c.ID)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
// The container was started by not-docker and so could have been deleted by
|
||||
// not-docker before we got around to loading it from containerd.
|
||||
log.G(context.TODO()).WithFields(log.Fields{
|
||||
@@ -263,7 +263,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
|
||||
}
|
||||
tsk, err := ctr.Task(context.Background())
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
log.G(context.TODO()).WithFields(log.Fields{
|
||||
"error": err,
|
||||
"container": c.ID,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/names"
|
||||
@@ -68,7 +69,7 @@ func (daemon *Daemon) reserveName(id, name string) (string, error) {
|
||||
}
|
||||
|
||||
if err := daemon.containersReplica.ReserveName(name, id); err != nil {
|
||||
if errdefs.IsConflict(err) {
|
||||
if cerrdefs.IsConflict(err) {
|
||||
id, err := daemon.containersReplica.Snapshot().GetID(name)
|
||||
if err != nil {
|
||||
log.G(context.TODO()).Errorf("got unexpected error while looking up reserved name: %v", err)
|
||||
@@ -94,7 +95,7 @@ func (daemon *Daemon) generateAndReserveName(id string) (string, error) {
|
||||
}
|
||||
|
||||
if err := daemon.containersReplica.ReserveName(name, id); err != nil {
|
||||
if errdefs.IsConflict(err) {
|
||||
if cerrdefs.IsConflict(err) {
|
||||
continue
|
||||
}
|
||||
return "", err
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
runcoptions "github.com/containerd/containerd/api/types/runc/options"
|
||||
runtimeoptions "github.com/containerd/containerd/api/types/runtimeoptions/v1"
|
||||
"github.com/containerd/containerd/v2/plugins"
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -341,7 +341,7 @@ func TestGetRuntime(t *testing.T) {
|
||||
} else {
|
||||
assert.Check(t, is.Equal(shim, ""))
|
||||
assert.Check(t, is.Nil(opts))
|
||||
assert.Check(t, errdefs.IsInvalidParameter(err), "[%T] %[1]v", err)
|
||||
assert.Check(t, cerrdefs.IsInvalidArgument(err), "[%T] %[1]v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package daemon // import "github.com/docker/docker/daemon"
|
||||
import (
|
||||
"context"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/platform"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ func (daemon *Daemon) stats(c *container.Container) (*containertypes.StatsRespon
|
||||
// Obtain the stats from HCS via libcontainerd
|
||||
stats, err := task.Stats(context.Background())
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return nil, containerNotFound(c.ID)
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/errdefs"
|
||||
@@ -86,7 +87,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
|
||||
isRestarting := ctr.Restarting
|
||||
tsk, err := ctr.GetRunningTask()
|
||||
ctr.Unlock()
|
||||
if errdefs.IsConflict(err) || isRestarting {
|
||||
if cerrdefs.IsConflict(err) || isRestarting {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user