improve calling for content
Signed-off-by: yason <yan.xuean@zte.com.cn>
This commit is contained in:
parent
c89e555150
commit
41c8763e2b
@ -315,7 +315,7 @@ type imageInfo struct {
|
||||
}
|
||||
|
||||
// getImageInfo gets image info from containerd.
|
||||
func getImageInfo(ctx context.Context, image containerd.Image, provider content.Provider) (*imageInfo, error) {
|
||||
func getImageInfo(ctx context.Context, image containerd.Image) (*imageInfo, error) {
|
||||
// Get image information.
|
||||
diffIDs, err := image.RootFS(ctx)
|
||||
if err != nil {
|
||||
@ -334,7 +334,7 @@ func getImageInfo(ctx context.Context, image containerd.Image, provider content.
|
||||
}
|
||||
id := desc.Digest.String()
|
||||
|
||||
rb, err := content.ReadBlob(ctx, provider, desc.Digest)
|
||||
rb, err := content.ReadBlob(ctx, image.ContentStore(), desc.Digest)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read image config from content store: %v", err)
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func (c *criContainerdService) LoadImage(ctx context.Context, r *api.LoadImageRe
|
||||
glog.Warningf("Failed to unpack image %q: %v", repoTag, err)
|
||||
// Do not fail image importing. Unpack will be retried when container creation.
|
||||
}
|
||||
info, err := getImageInfo(ctx, image, c.client.ContentStore())
|
||||
info, err := getImageInfo(ctx, image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get image %q info: %v", repoTag, err)
|
||||
}
|
||||
|
@ -114,8 +114,15 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
|
||||
// Do not fail image pulling. Unpack will be retried before container creation.
|
||||
}
|
||||
|
||||
// Get image information.
|
||||
info, err := getImageInfo(ctx, image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get image information: %v", err)
|
||||
}
|
||||
imageID := info.id
|
||||
|
||||
repoDigest, repoTag := getRepoDigestAndTag(namedRef, image.Target().Digest, isSchema1)
|
||||
for _, r := range []string{repoTag, repoDigest} {
|
||||
for _, r := range []string{repoTag, repoDigest, imageID} {
|
||||
if r == "" {
|
||||
continue
|
||||
}
|
||||
@ -123,16 +130,7 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
|
||||
return nil, fmt.Errorf("failed to update image reference %q: %v", r, err)
|
||||
}
|
||||
}
|
||||
// Get image information.
|
||||
info, err := getImageInfo(ctx, image, c.client.ContentStore())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get image information: %v", err)
|
||||
}
|
||||
imageID := info.id
|
||||
|
||||
if err := c.createImageReference(ctx, imageID, image.Target()); err != nil {
|
||||
return nil, fmt.Errorf("failed to update image reference %q: %v", imageID, err)
|
||||
}
|
||||
glog.V(4).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
|
||||
repoTag, repoDigest)
|
||||
img := imagestore.Image{
|
||||
@ -158,7 +156,7 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
|
||||
// by someone else anytime, before/during/after we create the metadata. We should always
|
||||
// check the actual state in containerd before using the image or returning status of the
|
||||
// image.
|
||||
return &runtime.PullImageResponse{ImageRef: img.ID}, err
|
||||
return &runtime.PullImageResponse{ImageRef: img.ID}, nil
|
||||
}
|
||||
|
||||
// ParseAuth parses AuthConfig and returns username and password/secret required by containerd.
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
containerdio "github.com/containerd/containerd/cio"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
containerdimages "github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
@ -99,7 +98,7 @@ func (c *criContainerdService) recover(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list images: %v", err)
|
||||
}
|
||||
images, err := loadImages(ctx, cImages, c.client.ContentStore(), c.config.ContainerdConfig.Snapshotter)
|
||||
images, err := loadImages(ctx, cImages, c.config.ContainerdConfig.Snapshotter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load images: %v", err)
|
||||
}
|
||||
@ -322,7 +321,7 @@ func loadSandbox(ctx context.Context, cntr containerd.Container) (sandboxstore.S
|
||||
// loadImages loads images from containerd.
|
||||
// TODO(random-liu): Check whether image is unpacked, because containerd put image reference
|
||||
// into store before image is unpacked.
|
||||
func loadImages(ctx context.Context, cImages []containerd.Image, provider content.Provider,
|
||||
func loadImages(ctx context.Context, cImages []containerd.Image,
|
||||
snapshotter string) ([]imagestore.Image, error) {
|
||||
// Group images by image id.
|
||||
imageMap := make(map[string][]containerd.Image)
|
||||
@ -340,7 +339,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
|
||||
// imgs len must be > 0, or else the entry will not be created in
|
||||
// previous loop.
|
||||
i := imgs[0]
|
||||
ok, _, _, _, err := containerdimages.Check(ctx, provider, i.Target(), platforms.Default())
|
||||
ok, _, _, _, err := containerdimages.Check(ctx, i.ContentStore(), i.Target(), platforms.Default())
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to check image content readiness for %q: %v", i.Name(), err)
|
||||
continue
|
||||
@ -360,7 +359,7 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
|
||||
// TODO(random-liu): Consider whether we should try unpack here.
|
||||
}
|
||||
|
||||
info, err := getImageInfo(ctx, i, provider)
|
||||
info, err := getImageInfo(ctx, i)
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to get image info for %q: %v", i.Name(), err)
|
||||
continue
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/api/services/tasks/v1"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/sys"
|
||||
@ -96,8 +95,6 @@ type criContainerdService struct {
|
||||
snapshotStore *snapshotstore.Store
|
||||
// taskService is containerd tasks client.
|
||||
taskService tasks.TasksClient
|
||||
// contentStoreService is the containerd content service client.
|
||||
contentStoreService content.Store
|
||||
// imageStoreService is the containerd service to store and track
|
||||
// image metadata.
|
||||
imageStoreService images.Store
|
||||
@ -143,7 +140,6 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
|
||||
containerNameIndex: registrar.NewRegistrar(),
|
||||
taskService: client.TaskService(),
|
||||
imageStoreService: client.ImageService(),
|
||||
contentStoreService: client.ContentStore(),
|
||||
client: client,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user