Kaynağa Gözat

ImageService: Pass ctx to Children

This only makes the containerd ImageService implementation respect
context cancellation though.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 2 yıl önce
ebeveyn
işleme
e0f36f9d8b

+ 1 - 3
daemon/containerd/image_children.go

@@ -15,9 +15,7 @@ import (
 // Children returns a slice of image ID which rootfs is a superset of the
 // rootfs of the given image ID, excluding images with exactly the same rootfs.
 // Called from list.go to filter containers.
-func (i *ImageService) Children(id image.ID) []image.ID {
-	ctx := context.TODO()
-
+func (i *ImageService) Children(ctx context.Context, id image.ID) []image.ID {
 	target, err := i.resolveDescriptor(ctx, id.String())
 	if err != nil {
 		logrus.WithError(err).Error("failed to get parent image")

+ 1 - 1
daemon/image_service.go

@@ -75,7 +75,7 @@ type ImageService interface {
 
 	GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error)
 	DistributionServices() images.DistributionServices
-	Children(id image.ID) []image.ID
+	Children(ctx context.Context, id image.ID) []image.ID
 	Cleanup() error
 	StorageDriver() string
 	UpdateConfig(maxDownloads, maxUploads int)

+ 1 - 1
daemon/images/service.go

@@ -109,7 +109,7 @@ func (i *ImageService) CountImages() int {
 // Children returns the children image.IDs for a parent image.
 // called from list.go to filter containers
 // TODO: refactor to expose an ancestry for image.ID?
-func (i *ImageService) Children(id image.ID) []image.ID {
+func (i *ImageService) Children(_ context.Context, id image.ID) []image.ID {
 	return i.imageStore.Children(id)
 }
 

+ 4 - 4
daemon/list.go

@@ -328,7 +328,7 @@ func (daemon *Daemon) foldFilter(ctx context.Context, view *container.View, conf
 				return nil
 			}
 			// Then walk down the graph and put the imageIds in imagesFilter
-			populateImageFilterByParents(imagesFilter, img.ID(), daemon.imageService.Children)
+			populateImageFilterByParents(ctx, imagesFilter, img.ID(), daemon.imageService.Children)
 			return nil
 		})
 	}
@@ -594,10 +594,10 @@ func (daemon *Daemon) refreshImage(ctx context.Context, s *container.Snapshot, f
 	return &c, nil
 }
 
-func populateImageFilterByParents(ancestorMap map[image.ID]bool, imageID image.ID, getChildren func(image.ID) []image.ID) {
+func populateImageFilterByParents(ctx context.Context, ancestorMap map[image.ID]bool, imageID image.ID, getChildren func(context.Context, image.ID) []image.ID) {
 	if !ancestorMap[imageID] {
-		for _, id := range getChildren(imageID) {
-			populateImageFilterByParents(ancestorMap, id, getChildren)
+		for _, id := range getChildren(ctx, imageID) {
+			populateImageFilterByParents(ctx, ancestorMap, id, getChildren)
 		}
 		ancestorMap[imageID] = true
 	}