Skip to content

Commit

Permalink
Delete tag if its history is empty
Browse files Browse the repository at this point in the history
During a run of prune images, history of a tag may get emptied. When an
image with the same tag is re-pushed, the operation will fail because
the history list is not expected to be empty.

This patch checks the history list for non-emptiness before returning a
valid tag event and ensures that tag is deleted from ImageStream's
status.tags  when the last item has been removed from its history during
a prune.

Signed-off-by: Michal Minar <miminar@redhat.com>
  • Loading branch information
Michal Minar committed Dec 14, 2015
1 parent 1bf495c commit 3a6035d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/image/api/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ func LatestTaggedImage(stream *ImageStream, tag string) *TagEvent {
// find the most recent tag event with an image reference
if stream.Status.Tags != nil {
if history, ok := stream.Status.Tags[tag]; ok {
if len(history.Items) == 0 {
return nil
}
return &history.Items[0]
}
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/image/prune/imagepruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,12 @@ func pruneStreams(g graph.Graph, imageNodes []*imagegraph.ImageNode, streamPrune
updatedTags.Insert(tag)
}
}
stream.Status.Tags[tag] = newHistory
if len(newHistory.Items) == 0 {
glog.V(4).Infof("Removing tag %q from status.tags of ImageStream %s/%s", tag, stream.Namespace, stream.Name)
delete(stream.Status.Tags, tag)
} else {
stream.Status.Tags[tag] = newHistory
}
}

updatedStream, err := streamPruner.PruneImageStream(stream, imageNode.Image, updatedTags.List())
Expand Down

0 comments on commit 3a6035d

Please sign in to comment.