Merge pull request #46590 from vvoland/c8d-tag-ctx-withoutcancel
daemon/c8d: Use WithoutCancel instead of context.Background
This commit is contained in:
commit
f0698dae14
6 changed files with 17 additions and 11 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
@ -136,7 +137,7 @@ func (i *ImageService) deleteAll(ctx context.Context, img images.Image, force, p
|
|||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err := i.unleaseSnapshotsFromDeletedConfigs(context.Background(), possiblyDeletedConfigs); err != nil {
|
||||
if err := i.unleaseSnapshotsFromDeletedConfigs(compatcontext.WithoutCancel(ctx), possiblyDeletedConfigs); err != nil {
|
||||
log.G(ctx).WithError(err).Warn("failed to unlease snapshots")
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
@ -147,7 +148,7 @@ func (i *ImageService) pruneUnused(ctx context.Context, filterFunc imageFilterFu
|
|||
|
||||
// Workaround for https://github.com/moby/buildkit/issues/3797
|
||||
defer func() {
|
||||
if err := i.unleaseSnapshotsFromDeletedConfigs(context.Background(), possiblyDeletedConfigs); err != nil {
|
||||
if err := i.unleaseSnapshotsFromDeletedConfigs(compatcontext.WithoutCancel(ctx), possiblyDeletedConfigs); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/distribution"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
@ -129,7 +130,7 @@ func (i *ImageService) PullImage(ctx context.Context, ref reference.Named, platf
|
|||
logger.Info("image pulled")
|
||||
|
||||
// The pull succeeded, so try to remove any dangling image we have for this target
|
||||
err = i.client.ImageService().Delete(context.Background(), danglingImageName(img.Target().Digest))
|
||||
err = i.client.ImageService().Delete(compatcontext.WithoutCancel(ctx), danglingImageName(img.Target().Digest))
|
||||
if err != nil && !cerrdefs.IsNotFound(err) {
|
||||
// Image pull succeeded, but cleaning up the dangling image failed. Ignore the
|
||||
// error to not mark the pull as failed.
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -49,7 +50,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re
|
|||
return errors.Wrapf(err, "failed to delete previous image %s", replacedImg.Name)
|
||||
}
|
||||
|
||||
if _, err = is.Create(context.Background(), newImg); err != nil {
|
||||
if _, err = is.Create(compatcontext.WithoutCancel(ctx), newImg); err != nil {
|
||||
return errdefs.System(errors.Wrapf(err, "failed to create an image %s with target %s after deleting the existing one",
|
||||
newImg.Name, imageID.String()))
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re
|
|||
defer i.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), events.ActionTag)
|
||||
|
||||
// The tag succeeded, check if the source image is dangling
|
||||
sourceDanglingImg, err := is.Get(context.Background(), danglingImageName(target.Digest))
|
||||
sourceDanglingImg, err := is.Get(compatcontext.WithoutCancel(ctx), danglingImageName(target.Digest))
|
||||
if err != nil {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
logger.WithError(err).Warn("unexpected error when checking if source image is dangling")
|
||||
|
@ -79,13 +80,13 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re
|
|||
imageLabelClassicBuilderParent: builderLabel,
|
||||
}
|
||||
|
||||
if _, err := is.Update(context.Background(), newImg, "labels"); err != nil {
|
||||
if _, err := is.Update(compatcontext.WithoutCancel(ctx), newImg, "labels"); err != nil {
|
||||
logger.WithError(err).Warnf("failed to set %s label on the newly tagged image", imageLabelClassicBuilderParent)
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the source dangling image, as it's no longer dangling.
|
||||
if err := is.Delete(context.Background(), sourceDanglingImg.Name); err != nil {
|
||||
if err := is.Delete(compatcontext.WithoutCancel(ctx), sourceDanglingImg.Name); err != nil {
|
||||
logger.WithError(err).Warn("unexpected error when deleting dangling image")
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/remotes"
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/opencontainers/go-digest"
|
||||
|
@ -52,7 +53,7 @@ func (j *jobs) showProgress(ctx context.Context, out progress.Output, updater pr
|
|||
}
|
||||
}
|
||||
case <-ctx.Done():
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
|
||||
ctx, cancel := context.WithTimeout(compatcontext.WithoutCancel(ctx), time.Millisecond*500)
|
||||
defer cancel()
|
||||
updater.UpdateProgress(ctx, j, out, start)
|
||||
close(lastUpdate)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
cerrdefs "github.com/containerd/containerd/errdefs"
|
||||
containerdimages "github.com/containerd/containerd/images"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -32,7 +33,7 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
|
|||
|
||||
// Create dangling image if this is the last image pointing to this target.
|
||||
if len(imgs) == 1 {
|
||||
err = i.ensureDanglingImage(context.Background(), img)
|
||||
err = i.ensureDanglingImage(compatcontext.WithoutCancel(ctx), img)
|
||||
|
||||
// Error out in case we couldn't persist the old image.
|
||||
if err != nil {
|
||||
|
@ -42,7 +43,7 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
|
|||
}
|
||||
|
||||
// Free the target name.
|
||||
err = is.Delete(context.Background(), img.Name)
|
||||
err = is.Delete(compatcontext.WithoutCancel(ctx), img.Name)
|
||||
if err != nil {
|
||||
if !cerrdefs.IsNotFound(err) {
|
||||
return errdefs.System(errors.Wrapf(err, "failed to delete image %s which existed a moment before", img.Name))
|
||||
|
@ -66,7 +67,7 @@ func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdi
|
|||
}
|
||||
danglingImage.Name = danglingImageName(from.Target.Digest)
|
||||
|
||||
_, err := i.client.ImageService().Create(context.Background(), danglingImage)
|
||||
_, err := i.client.ImageService().Create(compatcontext.WithoutCancel(ctx), danglingImage)
|
||||
// If it already exists, then just continue.
|
||||
if cerrdefs.IsAlreadyExists(err) {
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue