From 3a6035d24cefcd017a6544713694cd8ec4e162f8 Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Mon, 14 Dec 2015 11:36:47 +0100 Subject: [PATCH] Delete tag if its history is empty 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 --- pkg/image/api/helper.go | 3 +++ pkg/image/prune/imagepruner.go | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/image/api/helper.go b/pkg/image/api/helper.go index bdf4a88343c0..633aded4b8bc 100644 --- a/pkg/image/api/helper.go +++ b/pkg/image/api/helper.go @@ -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] } } diff --git a/pkg/image/prune/imagepruner.go b/pkg/image/prune/imagepruner.go index 051a5ad3914e..b73a691dda77 100644 --- a/pkg/image/prune/imagepruner.go +++ b/pkg/image/prune/imagepruner.go @@ -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())