Fix bug in listing owned tags
We were indexing into a map using the docker_image_id, but the ancestors use the *image id*. Also cleans up the code and adds some tests. Fixes https://jira.prod.coreos.systems/browse/QS-55
This commit is contained in:
parent
7254dece06
commit
1b6ecb6c1c
5 changed files with 27 additions and 145 deletions
|
@ -172,14 +172,11 @@ class RepositoryTagImages(RepositoryParamResource):
|
|||
if tag_image is None:
|
||||
raise NotFound()
|
||||
|
||||
# Find all the parent images for the tag.
|
||||
parent_images = model.get_parent_images(namespace, repository, tag_image.docker_image_id)
|
||||
image_map = {str(tag_image.docker_image_id): tag_image}
|
||||
|
||||
for image in parent_images:
|
||||
image_map[str(image.docker_image_id)] = image
|
||||
|
||||
image_map_all = dict(image_map)
|
||||
all_images = [tag_image] + list(parent_images)
|
||||
image_map = {image.docker_image_id: image for image in all_images}
|
||||
skip_set = set()
|
||||
|
||||
# Filter the images returned to those not found in the ancestry of any of the other tags in
|
||||
# the repository.
|
||||
|
@ -189,18 +186,13 @@ class RepositoryTagImages(RepositoryParamResource):
|
|||
if current_tag.name == tag:
|
||||
continue
|
||||
|
||||
# Remove the tag's image ID.
|
||||
tag_image_id = str(current_tag.docker_image_id)
|
||||
image_map.pop(tag_image_id, None)
|
||||
|
||||
# Remove any ancestors:
|
||||
for ancestor_id in current_tag.image.ancestors.split('/'):
|
||||
image_map.pop(ancestor_id, None)
|
||||
skip_set.add(current_tag.image.ancestor_id)
|
||||
skip_set = skip_set | set(current_tag.image.ancestor_id_list)
|
||||
|
||||
return {
|
||||
'images': [
|
||||
image.to_dict(image_map_all) for image in all_images
|
||||
if not parsed_args['owned'] or (str(image.docker_image_id) in image_map)
|
||||
image.to_dict(image_map) for image in all_images
|
||||
if not parsed_args['owned'] or (image.ancestor_id not in skip_set)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue