Browse code

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 authored on 2023/06/30 16:37:45
Showing 1 changed files
... ...
@@ -53,9 +53,16 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
53 53
 func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdimages.Image) error {
54 54
 	danglingImage := from
55 55
 
56
+	danglingImage.Labels = make(map[string]string)
57
+	for k, v := range from.Labels {
58
+		switch k {
59
+		case containerdimages.AnnotationImageName, ocispec.AnnotationRefName:
60
+			// Don't copy name labels.
61
+		default:
62
+			danglingImage.Labels[k] = v
63
+		}
64
+	}
56 65
 	danglingImage.Name = danglingImageName(from.Target.Digest)
57
-	delete(danglingImage.Labels, containerdimages.AnnotationImageName)
58
-	delete(danglingImage.Labels, ocispec.AnnotationRefName)
59 66
 
60 67
 	_, err := i.client.ImageService().Create(context.Background(), danglingImage)
61 68
 	// If it already exists, then just continue.