Skip to content

Commit

Permalink
Preserve tag when v1 pull by id is possible
Browse files Browse the repository at this point in the history
Also process all tags for an image id.
  • Loading branch information
Andy Goldstein authored and smarterclayton committed Mar 17, 2015
1 parent 3c028a5 commit ebbf8a6
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions pkg/image/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,47 @@ func (c *ImportController) Next(repo *api.ImageRepository) error {
return c.done(repo, err.Error())
}

// if there is a tag for the image by its id (tag=tag), we can pull by id
tag := tags[0]
if hasTag(tags, id) {
tag = id
}
pullRef := api.DockerImageReference{
Registry: ref.Registry,
Namespace: ref.Namespace,
Name: ref.Name,
Tag: tag,
idTagPresent := false
if len(tags) > 1 && hasTag(tags, id) {
// only set to true if we have at least 1 tag that isn't the image id
idTagPresent = true
}
for _, tag := range tags {
if idTagPresent && id == tag {
continue
}
pullRefTag := tag
if idTagPresent {
// if there is a tag for the image by its id (tag=tag), we can pull by id
pullRefTag = id
}
pullRef := api.DockerImageReference{
Registry: ref.Registry,
Namespace: ref.Namespace,
Name: ref.Name,
Tag: pullRefTag,
}

mapping := &api.ImageRepositoryMapping{
ObjectMeta: kapi.ObjectMeta{
Name: repo.Name,
Namespace: repo.Namespace,
},
Tag: tag,
Image: api.Image{
mapping := &api.ImageRepositoryMapping{
ObjectMeta: kapi.ObjectMeta{
Name: id,
Name: repo.Name,
Namespace: repo.Namespace,
},
Tag: tag,
Image: api.Image{
ObjectMeta: kapi.ObjectMeta{
Name: id,
},
DockerImageReference: pullRef.String(),
DockerImageMetadata: image,
},
DockerImageReference: pullRef.String(),
DockerImageMetadata: image,
},
}
if err := c.mappings.ImageRepositoryMappings(repo.Namespace).Create(mapping); err != nil {
if errors.IsNotFound(err) {
return c.done(repo, err.Error())
}
return err
if err := c.mappings.ImageRepositoryMappings(repo.Namespace).Create(mapping); err != nil {
if errors.IsNotFound(err) {
return c.done(repo, err.Error())
}
return err
}
}
}

Expand Down

0 comments on commit ebbf8a6

Please sign in to comment.