Browse Source

Merge pull request #45609 from thaJeztah/constantly_numb

c8d: ImageService.softImageDelete: use OCI and containerd constants
Sebastiaan van Stijn 2 years ago
parent
commit
f1d5385515
1 changed files with 6 additions and 5 deletions
  1. 6 5
      daemon/containerd/soft_delete.go

+ 6 - 5
daemon/containerd/soft_delete.go

@@ -7,6 +7,7 @@ import (
 	containerdimages "github.com/containerd/containerd/images"
 	"github.com/docker/docker/errdefs"
 	"github.com/opencontainers/go-digest"
+	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 	"github.com/pkg/errors"
 )
 
@@ -18,10 +19,10 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
 
 	// If the image already exists, persist it as dangling image
 	// but only if no other image has the same target.
-	digest := img.Target.Digest.String()
-	imgs, err := is.List(ctx, "target.digest=="+digest)
+	dgst := img.Target.Digest.String()
+	imgs, err := is.List(ctx, "target.digest=="+dgst)
 	if err != nil {
-		return errdefs.System(errors.Wrapf(err, "failed to check if there are images targeting digest %s", digest))
+		return errdefs.System(errors.Wrapf(err, "failed to check if there are images targeting digest %s", dgst))
 	}
 
 	// From this point explicitly ignore the passed context
@@ -32,8 +33,8 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
 		danglingImage := img
 
 		danglingImage.Name = danglingImageName(img.Target.Digest)
-		delete(danglingImage.Labels, "io.containerd.image.name")
-		delete(danglingImage.Labels, "org.opencontainers.image.ref.name")
+		delete(danglingImage.Labels, containerdimages.AnnotationImageName)
+		delete(danglingImage.Labels, ocispec.AnnotationRefName)
 
 		_, err = is.Create(context.Background(), danglingImage)