Skip to content

Commit 0677dee

Browse files
committed
Fix bug searching builders with tags that reference other tags
If builder nodejs:latest tracks nodejs:4 and a search term matches only the nodejs:latest description, the version select appears empty in the add to project catalog. Fix this by only matching search terms in the nodejs:4 description (but still match searches for "latest").
1 parent 3f779bc commit 0677dee

File tree

3 files changed

+92
-40
lines changed

3 files changed

+92
-40
lines changed

app/scripts/directives/catalog/catalogImage.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
angular.module('openshiftConsole')
4-
.directive('catalogImage', function($filter) {
4+
.directive('catalogImage', function($filter, CatalogService) {
55
return {
66
restrict: 'E',
77
// Replace the catalog-template element so that the tiles are all equal height as flexbox items.
@@ -23,10 +23,7 @@ angular.module('openshiftConsole')
2323
var tagTags = {};
2424
_.each(specTags, function(tag) {
2525
tagTags[tag.name] = imageStreamTagTags($scope.imageStream, tag.name);
26-
if (tag.from &&
27-
tag.from.kind === 'ImageStreamTag' &&
28-
tag.from.name.indexOf(':') === -1 &&
29-
!tag.from.namespace) {
26+
if (CatalogService.referencesSameImageStream(tag)) {
3027
referenceTags[tag.name] = true;
3128
$scope.referencedBy[tag.from.name] = $scope.referencedBy[tag.from.name] || [];
3229
$scope.referencedBy[tag.from.name].push(tag.name);

app/scripts/services/catalog.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ angular.module("openshiftConsole")
123123
return templatesByCategory;
124124
};
125125

126+
var referencesSameImageStream = function(specTag) {
127+
return specTag.from &&
128+
specTag.from.kind === 'ImageStreamTag' &&
129+
specTag.from.name.indexOf(':') === -1 &&
130+
!specTag.from.namespace;
131+
};
132+
126133
// Don't use KeywordService for image stream filtering so we can add
127134
// special handling for image stream tags. Match keywords (array of regex)
128135
// against image streams and image stream tags, returning a copy of the
@@ -137,7 +144,23 @@ angular.module("openshiftConsole")
137144
_.each(imageStreams, function(imageStream) {
138145
var name = _.get(imageStream, 'metadata.name', '');
139146
var displayName = getDisplayName(imageStream, true);
140-
var matchingTags = _.indexBy(imageStream.spec.tags, 'name');
147+
var specTags = [];
148+
var references = {};
149+
var referencedBy = {};
150+
_.each(imageStream.spec.tags, function(tag) {
151+
// If the tag follows another, track the reference.
152+
if (referencesSameImageStream(tag)) {
153+
references[tag.name] = tag.from.name;
154+
referencedBy[tag.from.name] = referencedBy[tag.from.name] || [];
155+
referencedBy[tag.from.name].push(tag.name);
156+
return;
157+
}
158+
159+
// If the tag doesn't follow another, consider it in the search.
160+
specTags.push(tag);
161+
});
162+
163+
var matchingTags = _.indexBy(specTags, 'name');
141164

142165
// Find tags that match every keyword. Search image stream name, image
143166
// stream display name, and tag names, and tag descriptions. If a
@@ -153,7 +176,7 @@ angular.module("openshiftConsole")
153176
}
154177

155178
// Check tag descriptions.
156-
_.each(imageStream.spec.tags, function(tag) {
179+
_.each(specTags, function(tag) {
157180
// If this is not a builder or is hidden, don't match the tag.
158181
var tagTags = _.get(tag, 'annotations.tags', '');
159182
if (!/\bbuilder\b/.test(tagTags) || /\bhidden\b/.test(tagTags)) {
@@ -166,6 +189,16 @@ angular.module("openshiftConsole")
166189
return;
167190
}
168191

192+
// Search any tag names that reference this tag as well. For
193+
// instance, searching for "latest" should match nodejs:4 if
194+
// nodejs:latest references nodejs:4
195+
var matches = function(referenceName) {
196+
return regex.test(referenceName);
197+
};
198+
if (_.some(referencedBy[tag.name], matches)) {
199+
return;
200+
}
201+
169202
var description = _.get(tag, 'annotations.description');
170203
if (!description || !regex.test(description)) {
171204
delete matchingTags[tag.name];
@@ -178,8 +211,16 @@ angular.module("openshiftConsole")
178211
if (!_.isEmpty(matchingTags)) {
179212
imageStreamCopy = angular.copy(imageStream);
180213
imageStreamCopy.status.tags = _.filter(imageStreamCopy.status.tags, function(tag) {
214+
// If this tag follow another tag, include it if the other tag matches the search.
215+
var fromTag = references[tag.tag];
216+
if (fromTag) {
217+
return matchingTags[fromTag];
218+
}
219+
220+
// Otherwise check if this tag was a match.
181221
return matchingTags[tag.tag];
182222
});
223+
183224
filteredImageStreams.push(imageStreamCopy);
184225
}
185226
});
@@ -201,6 +242,7 @@ angular.module("openshiftConsole")
201242
getCategoryItem: getCategoryItem,
202243
categorizeImageStreams: categorizeImageStreams,
203244
categorizeTemplates: categorizeTemplates,
245+
referencesSameImageStream: referencesSameImageStream,
204246
filterImageStreams: filterImageStreams,
205247
filterTemplates: filterTemplates
206248
};

dist/scripts/scripts.js

+46-33
Original file line numberDiff line numberDiff line change
@@ -4123,35 +4123,48 @@ _.each(e, function(d) {
41234123
h(d, c) && (b[d.id] = b[d.id] || [], b[d.id].push(a), f = !0);
41244124
}), f || (b[""] = b[""] || [], b[""].push(a));
41254125
}), b;
4126-
}, k = a("displayName"), l = function(a, b) {
4126+
}, k = function(a) {
4127+
return a.from && "ImageStreamTag" === a.from.kind && a.from.name.indexOf(":") === -1 && !a.from.namespace;
4128+
}, l = a("displayName"), m = function(a, b) {
41274129
if (!b.length) return a;
41284130
var c = [];
41294131
return _.each(a, function(a) {
4130-
var d = _.get(a, "metadata.name", ""), e = k(a, !0), f = _.indexBy(a.spec.tags, "name");
4131-
_.each(b, function(b) {
4132-
b.test(d) || e && b.test(e) || _.each(a.spec.tags, function(a) {
4133-
var c = _.get(a, "annotations.tags", "");
4134-
if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete f[a.name];
4135-
if (!b.test(a.name)) {
4136-
var d = _.get(a, "annotations.description");
4137-
d && b.test(d) || delete f[a.name];
4132+
var d = _.get(a, "metadata.name", ""), e = l(a, !0), f = [], g = {}, h = {};
4133+
_.each(a.spec.tags, function(a) {
4134+
return k(a) ? (g[a.name] = a.from.name, h[a.from.name] = h[a.from.name] || [], void h[a.from.name].push(a.name)) :void f.push(a);
4135+
});
4136+
var i = _.indexBy(f, "name");
4137+
_.each(b, function(a) {
4138+
a.test(d) || e && a.test(e) || _.each(f, function(b) {
4139+
var c = _.get(b, "annotations.tags", "");
4140+
if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete i[b.name];
4141+
if (!a.test(b.name)) {
4142+
var d = function(b) {
4143+
return a.test(b);
4144+
};
4145+
if (!_.some(h[b.name], d)) {
4146+
var e = _.get(b, "annotations.description");
4147+
e && a.test(e) || delete i[b.name];
4148+
}
41384149
}
41394150
});
41404151
});
4141-
var g;
4142-
_.isEmpty(f) || (g = angular.copy(a), g.status.tags = _.filter(g.status.tags, function(a) {
4143-
return f[a.tag];
4144-
}), c.push(g));
4152+
var j;
4153+
_.isEmpty(i) || (j = angular.copy(a), j.status.tags = _.filter(j.status.tags, function(a) {
4154+
var b = g[a.tag];
4155+
return b ? i[b] :i[a.tag];
4156+
}), c.push(j));
41454157
}), c;
4146-
}, m = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], n = function(a, b) {
4147-
return c.filterForKeywords(a, m, b);
4158+
}, n = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], o = function(a, b) {
4159+
return c.filterForKeywords(a, n, b);
41484160
};
41494161
return {
41504162
getCategoryItem:f,
41514163
categorizeImageStreams:i,
41524164
categorizeTemplates:j,
4153-
filterImageStreams:l,
4154-
filterTemplates:n
4165+
referencesSameImageStream:k,
4166+
filterImageStreams:m,
4167+
filterTemplates:o
41554168
};
41564169
} ]), angular.module("openshiftConsole").factory("ModalsService", [ "$uibModal", function(a) {
41574170
return {
@@ -11489,7 +11502,7 @@ keyword:""
1148911502
}, b.$watch("filter.keyword", e), b.$watchGroup([ "openshiftImageStreams", "projectImageStreams" ], g), b.$watchGroup([ "openshiftTemplates", "projectTemplates" ], i);
1149011503
}
1149111504
};
11492-
} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", function(a) {
11505+
} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", "CatalogService", function(a, b) {
1149311506
return {
1149411507
restrict:"E",
1149511508
replace:!0,
@@ -11501,25 +11514,25 @@ isBuilder:"=?",
1150111514
keywords:"="
1150211515
},
1150311516
templateUrl:"views/catalog/_image.html",
11504-
link:function(b) {
11505-
var c = a("imageStreamTagTags"), d = {};
11506-
b.referencedBy = {};
11507-
var e = _.get(b, "imageStream.spec.tags", []), f = {};
11508-
_.each(e, function(a) {
11509-
f[a.name] = c(b.imageStream, a.name), a.from && "ImageStreamTag" === a.from.kind && a.from.name.indexOf(":") === -1 && !a.from.namespace && (d[a.name] = !0, b.referencedBy[a.from.name] = b.referencedBy[a.from.name] || [], b.referencedBy[a.from.name].push(a.name));
11517+
link:function(c) {
11518+
var d = a("imageStreamTagTags"), e = {};
11519+
c.referencedBy = {};
11520+
var f = _.get(c, "imageStream.spec.tags", []), g = {};
11521+
_.each(f, function(a) {
11522+
g[a.name] = d(c.imageStream, a.name), b.referencesSameImageStream(a) && (e[a.name] = !0, c.referencedBy[a.from.name] = c.referencedBy[a.from.name] || [], c.referencedBy[a.from.name].push(a.name));
1151011523
});
11511-
var g = function(a) {
11512-
var b = _.get(f, [ a ], []);
11524+
var h = function(a) {
11525+
var b = _.get(g, [ a ], []);
1151311526
return _.includes(b, "builder") && !_.includes(b, "hidden");
1151411527
};
11515-
b.$watch("imageStream.status.tags", function(a) {
11516-
b.tags = _.filter(a, function(a) {
11517-
return g(a.tag) && !d[a.tag];
11528+
c.$watch("imageStream.status.tags", function(a) {
11529+
c.tags = _.filter(a, function(a) {
11530+
return h(a.tag) && !e[a.tag];
1151811531
});
11519-
var c = _.get(b, "is.tag.tag");
11520-
c && _.some(b.tags, {
11521-
tag:c
11522-
}) || _.set(b, "is.tag", _.head(b.tags));
11532+
var b = _.get(c, "is.tag.tag");
11533+
b && _.some(c.tags, {
11534+
tag:b
11535+
}) || _.set(c, "is.tag", _.head(c.tags));
1152311536
});
1152411537
}
1152511538
};

0 commit comments

Comments
 (0)