From cf9afb29812f587e7957ebb81d0944531e0ab19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20R=C3=BCegg?= Date: Tue, 31 Mar 2020 11:22:08 +0200 Subject: [PATCH] Only search active images for matched tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of search all found image stream tags only search for matched tags since these are the ones that concern us. Signed-off-by: Simon Rüegg --- cmd/history.go | 2 +- pkg/openshift/imagestream.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/history.go b/cmd/history.go index 2b7728b..13c92ea 100644 --- a/cmd/history.go +++ b/cmd/history.go @@ -81,7 +81,7 @@ func ExecuteHistoryCleanupCommand(args []string) error { } var matchingTags = cleanup.GetMatchingTags(&gitCandidates, &imageStreamTags, matchOption) - activeImageStreamTags, err := openshift.GetActiveImageStreamTags(namespace, image, imageStreamTags) + activeImageStreamTags, err := openshift.GetActiveImageStreamTags(namespace, image, matchingTags) if err != nil { return fmt.Errorf("could not retrieve active image stream tags for '%s/%s': %w", namespace, image, err) } diff --git a/pkg/openshift/imagestream.go b/pkg/openshift/imagestream.go index d68c873..f3bf9ef 100644 --- a/pkg/openshift/imagestream.go +++ b/pkg/openshift/imagestream.go @@ -24,6 +24,9 @@ var ( // GetActiveImageStreamTags retrieves the image streams tags referenced in some Kubernetes resources func GetActiveImageStreamTags(namespace, imageStream string, imageStreamTags []string) (activeImageStreamTags []string, funcError error) { + if len(imageStreamTags) == 0 { + return []string{}, nil + } funk.ForEach(resources, func(resource schema.GroupVersionResource) { funk.ForEach(imageStreamTags, func(imageStreamTag string) { if funk.ContainsString(activeImageStreamTags, imageStreamTag) {