Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@Random-Liu
Copy link
Member

@Random-Liu Random-Liu commented Jul 26, 2018

Fixes #760.
Based on #864.

This PR:

  • Creates an in memory cache of containerd image references.
    • The cache is updated when:
      a) cri plugin creates or removes an image reference. This makes sure image reference cache is up-to-date after cri pulling or deleting an image.
      b) Event monitor receives an image event (create/update/delete). This makes sure image references created/deleted outside of cri can trigger a cache update, e.g. ctr --namespace=k8s.io images pull.
    • All other cri functions, which only read data image information, will treat the cache as the source of truth for images, so that cri doesn't need to frequently access containerd metadata/content store and easily index by image id.
    • Please note that all data in the cache is generated from containerd. a) and b) above only triggers a cache update. This makes sure there is no multi-writer race condition.
  • Merge RepoTags and RepoDigests into a References field in the image store. For containerd, there is only image reference, only CRI has the RepoTag and RepoDigest concepts.
    • The References field reflects the references in containerd regardless of the reference format.
    • When cri generates CRI image status, it goes through all references, and pick out RepoTags and RepoDigests.
    • When cri pulls images, we'll still create repodigest and repotag as the image references, because of kubelet can't see images loaded into containerd #760 (comment). However, when users use ctr --namespace=k8s.io images pull to pull images, they can do whatever they want. They just need to understand that if their image doesn't have a reference in repotag or repodigest format, the corresponding CRI fields RepoTags and RepoDigests will be empty.

With this PR:

  1. cri will be able to see images pulled/loaded with ctr, and we can remove ctr cri command once we have ctr import ready.
  2. repotag which has pointed to a new image, won't show up in RepoTags field of the old image. We have this bug before this PR.

/cc @crosbymichael @dmcgowan @stevvooe

@Random-Liu Random-Liu added this to the v1.12 milestone Jul 26, 2018
@Random-Liu Random-Liu force-pushed the cache-image-reference branch 2 times, most recently from c5741aa to 96ece38 Compare July 26, 2018 17:25
Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review comments.

// Get returns the image with specified id. Returns store.ErrNotExist if the
// image doesn't exist.
func (s *Store) Get(id string) (Image, error) {
func (s *store) get(id string) (Image, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest updating the function descriptions. For example, here we should mention returns any error found from docker/distribution/digestSet.Lookup, such as digest.ErrDigestNotFound (returned as storeutil.ErrNotExist), digest.ErrDigestInvalidFormat, and digest.ErrDigestAmbiguous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// nil without error if the reference doesn't exist.
func (c *criService) localResolve(ctx context.Context, refOrID string) (*imagestore.Image, error) {
// localResolve resolves image reference locally and returns corresponding image metadata. It
// store.ErrNotExist if the reference doesn't exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/./or docker/distribution/digestset.ErrDigestInvalidFormat, or ErrDigestAmbiguous./

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a todo, we should not be eating the err returned from util.NormalizeImageRef. We are currently assuming it must be a digest if it's not a valid image ref.. but it could just be a poorly formed image ref and not a digest. But right now if it's a poorly formed image ref we return the error from digest lookup. Let's keep "both" errors and combine them here, so the user can see it's not a valid digest or image reference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// localResolve resolves image reference locally and returns corresponding image metadata. It returns
// nil without error if the reference doesn't exist.
func (c *criService) localResolve(ctx context.Context, refOrID string) (*imagestore.Image, error) {
// localResolve resolves image reference locally and returns corresponding image metadata. It
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/It/It returns/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// start starts the event monitor which monitors and handles all container events. It returns
// start starts the event monitor which monitors and handles all important events. It returns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/important/subscribed/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
return errors.Wrap(err, "failed to update container status for TaskOOM event")
}
case *eventtypes.ImageCreate:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@dmcgowan
Copy link
Member

This approach looks good

@Random-Liu Random-Liu force-pushed the cache-image-reference branch from 96ece38 to 953d67d Compare September 10, 2018 18:31
@Random-Liu
Copy link
Member Author

@mikebrow Addressed comments.

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/LGTM

@Random-Liu
Copy link
Member Author

Something with travis. All test passing, but the bullet doesn't turn green.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants