Browse Source

c8d/softDelete: Deep copy Labels

So we don't override the original Labels in the passed image object.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 2 năm trước cách đây
mục cha
commit
a6d5db3f9b
1 tập tin đã thay đổi với 9 bổ sung2 xóa
  1. 9 2
      daemon/containerd/soft_delete.go

+ 9 - 2
daemon/containerd/soft_delete.go

@@ -53,9 +53,16 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
 func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdimages.Image) error {
 func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdimages.Image) error {
 	danglingImage := from
 	danglingImage := from
 
 
+	danglingImage.Labels = make(map[string]string)
+	for k, v := range from.Labels {
+		switch k {
+		case containerdimages.AnnotationImageName, ocispec.AnnotationRefName:
+			// Don't copy name labels.
+		default:
+			danglingImage.Labels[k] = v
+		}
+	}
 	danglingImage.Name = danglingImageName(from.Target.Digest)
 	danglingImage.Name = danglingImageName(from.Target.Digest)
-	delete(danglingImage.Labels, containerdimages.AnnotationImageName)
-	delete(danglingImage.Labels, ocispec.AnnotationRefName)
 
 
 	_, err := i.client.ImageService().Create(context.Background(), danglingImage)
 	_, err := i.client.ImageService().Create(context.Background(), danglingImage)
 	// If it already exists, then just continue.
 	// If it already exists, then just continue.