Merge pull request #1202 from Random-Liu/not-cache-image-handler
Do not cache image handler.
This commit is contained in:
		@@ -114,6 +114,10 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrapf(err, "failed to resolve image %q", config.GetImage().GetImage())
 | 
			
		||||
	}
 | 
			
		||||
	containerdImage, err := c.toContainerdImage(ctx, image)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrapf(err, "failed to get image from containerd %q", image.ID)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Run container using the same runtime with sandbox.
 | 
			
		||||
	sandboxInfo, err := sandbox.Container.Info(ctx)
 | 
			
		||||
@@ -179,7 +183,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
 | 
			
		||||
		// the runtime (runc) a chance to modify (e.g. to create mount
 | 
			
		||||
		// points corresponding to spec.Mounts) before making the
 | 
			
		||||
		// rootfs readonly (requested by spec.Root.Readonly).
 | 
			
		||||
		customopts.WithNewSnapshot(id, image.Image),
 | 
			
		||||
		customopts.WithNewSnapshot(id, containerdImage),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(volumeMounts) > 0 {
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/BurntSushi/toml"
 | 
			
		||||
	"github.com/containerd/containerd"
 | 
			
		||||
	"github.com/containerd/containerd/containers"
 | 
			
		||||
	"github.com/containerd/containerd/runtime/linux/runctypes"
 | 
			
		||||
	runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
 | 
			
		||||
@@ -254,6 +255,15 @@ func (c *criService) localResolve(refOrID string) (imagestore.Image, error) {
 | 
			
		||||
	return c.imageStore.Get(imageID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// toContainerdImage converts an image object in image store to containerd image handler.
 | 
			
		||||
func (c *criService) toContainerdImage(ctx context.Context, image imagestore.Image) (containerd.Image, error) {
 | 
			
		||||
	// image should always have at least one reference.
 | 
			
		||||
	if len(image.References) == 0 {
 | 
			
		||||
		return nil, errors.Errorf("invalid image with no reference %q", image.ID)
 | 
			
		||||
	}
 | 
			
		||||
	return c.client.GetImage(ctx, image.References[0])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// getUserFromImage gets uid or user name of the image user.
 | 
			
		||||
// If user is numeric, it will be treated as uid; or else, it is treated as user name.
 | 
			
		||||
func getUserFromImage(user string) (*int64, string) {
 | 
			
		||||
 
 | 
			
		||||
@@ -98,6 +98,10 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrapf(err, "failed to get sandbox image %q", c.config.SandboxImage)
 | 
			
		||||
	}
 | 
			
		||||
	containerdImage, err := c.toContainerdImage(ctx, *image)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, errors.Wrapf(err, "failed to get image from containerd %q", image.ID)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ociRuntime, err := c.getSandboxRuntime(config, r.GetRuntimeHandler())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -187,7 +191,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
 | 
			
		||||
	}
 | 
			
		||||
	opts := []containerd.NewContainerOpts{
 | 
			
		||||
		containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
 | 
			
		||||
		customopts.WithNewSnapshot(id, image.Image),
 | 
			
		||||
		customopts.WithNewSnapshot(id, containerdImage),
 | 
			
		||||
		containerd.WithSpec(spec, specOpts...),
 | 
			
		||||
		containerd.WithContainerLabels(sandboxLabels),
 | 
			
		||||
		containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata),
 | 
			
		||||
 
 | 
			
		||||
@@ -47,8 +47,6 @@ type Image struct {
 | 
			
		||||
	Size int64
 | 
			
		||||
	// ImageSpec is the oci image structure which describes basic information about the image.
 | 
			
		||||
	ImageSpec imagespec.Image
 | 
			
		||||
	// Containerd image reference
 | 
			
		||||
	Image containerd.Image
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Store stores all images.
 | 
			
		||||
@@ -152,7 +150,6 @@ func getImage(ctx context.Context, i containerd.Image) (*Image, error) {
 | 
			
		||||
		ChainID:    chainID.String(),
 | 
			
		||||
		Size:       size,
 | 
			
		||||
		ImageSpec:  ociimage,
 | 
			
		||||
		Image:      i,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user