Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 458ba7f

Browse files
committedApr 26, 2017
Add logic to dedupe kinds by ignoring "openshift" namespace in APIService.calculateAvailableKinds()
1 parent 079315d commit 458ba7f

File tree

7 files changed

+1436
-588
lines changed

7 files changed

+1436
-588
lines changed
 

‎dist/origin-web-common-services.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,10 @@ angular.module('openshiftCommonServices')
471471
var kinds = [];
472472
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
473473

474-
// Legacy openshift and k8s kinds
475-
_.each(API_CFG, function(api) {
474+
// ignore the legacy openshift kinds, these have been migrated to api groups
475+
_.each(_.pick(API_CFG, function(value, key) {
476+
return key !== 'openshift';
477+
}), function(api) {
476478
_.each(api.resources.v1, function(resource) {
477479
if (resource.namespaced || includeClusterScoped) {
478480
// Exclude subresources and any rejected kinds

‎dist/origin-web-common.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1764,8 +1764,10 @@ angular.module('openshiftCommonServices')
17641764
var kinds = [];
17651765
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
17661766

1767-
// Legacy openshift and k8s kinds
1768-
_.each(API_CFG, function(api) {
1767+
// ignore the legacy openshift kinds, these have been migrated to api groups
1768+
_.each(_.pick(API_CFG, function(value, key) {
1769+
return key !== 'openshift';
1770+
}), function(api) {
17691771
_.each(api.resources.v1, function(resource) {
17701772
if (resource.namespaced || includeClusterScoped) {
17711773
// Exclude subresources and any rejected kinds

‎dist/origin-web-common.min.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,9 @@ var kind = "<none>", version = "<none>";
725725
return apiObject && apiObject.kind && (kind = apiObject.kind), apiObject && apiObject.apiVersion && (version = apiObject.apiVersion), "The API version " + version + " for kind " + kind + " is not supported by this server";
726726
}, calculateAvailableKinds = function(includeClusterScoped) {
727727
var kinds = [], rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
728-
return _.each(API_CFG, function(api) {
728+
return _.each(_.pick(API_CFG, function(value, key) {
729+
return "openshift" !== key;
730+
}), function(api) {
729731
_.each(api.resources.v1, function(resource) {
730732
if (resource.namespaced || includeClusterScoped) {
731733
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) return;

‎src/services/apiService.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ angular.module('openshiftCommonServices')
268268
var kinds = [];
269269
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
270270

271-
// Legacy openshift and k8s kinds
272-
_.each(API_CFG, function(api) {
271+
// ignore the legacy openshift kinds, these have been migrated to api groups
272+
_.each(_.pick(API_CFG, function(value, key) {
273+
return key !== 'openshift';
274+
}), function(api) {
273275
_.each(api.resources.v1, function(resource) {
274276
if (resource.namespaced || includeClusterScoped) {
275277
// Exclude subresources and any rejected kinds

‎test/.jshintrc

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"esversion": 6,
5+
"bitwise": true,
6+
"camelcase": false,
7+
"curly": true,
8+
"eqeqeq": true,
9+
"immed": true,
10+
"indent": 2,
11+
"latedef": true,
12+
"newcap": false,
13+
"noarg": true,
14+
"quotmark": false,
15+
"regexp": true,
16+
"smarttabs": true,
17+
"strict": true,
18+
"sub" : true,
19+
"undef": true,
20+
"unused": true,
21+
"expr" : true,
22+
"globals": {
23+
"ace": false,
24+
"after": false,
25+
"afterEach": false,
26+
"afterAll": false,
27+
"angular": false,
28+
"by": false,
29+
"before": false,
30+
"beforeAll": false,
31+
"beforeEach": false,
32+
"browser": false,
33+
"describe": false,
34+
"element" : false,
35+
"expect": false,
36+
"inject": false,
37+
"it": false,
38+
"xit": false,
39+
"jasmine": false,
40+
"spyOn": false,
41+
"hawtioPluginLoader": false,
42+
"HawtioCore": false,
43+
"Logger" : false,
44+
"LabelSelector": false,
45+
"moment": false,
46+
"Messenger" : false,
47+
"protractor" : false,
48+
"URI": false,
49+
"ZeroClipboard": false,
50+
"$": false,
51+
"_" : false
52+
53+
}
54+
}

‎test/spec/fixtures/api-discovery.js

+1,320-576
Large diffs are not rendered by default.

‎test/spec/services/apiServiceSpec.js

+47-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
describe("APIService", function(){
1+
describe("APIService", function() {
22
var APIService;
33

44
beforeEach(function(){
5-
inject(function(_APIService_){
5+
inject(function(_APIService_) {
66
APIService = _APIService_;
77
});
88
});
99

10-
describe("#toResourceGroupVersion", function(){
10+
describe("#toResourceGroupVersion", function() {
1111

1212
var tc = [
1313
// string args
@@ -62,7 +62,8 @@ describe("APIService", function(){
6262
}));
6363

6464
});
65-
/*
65+
66+
6667
describe("#parseGroupVersion", function(){
6768
var tc = [
6869
// invalid cases
@@ -234,6 +235,47 @@ describe("APIService", function(){
234235
});
235236
}));
236237
});
237-
*/
238+
239+
240+
describe('#availableKinds', function() {
241+
var bothSample = ['Binding','ConfigMap','DeploymentConfig','Event','LimitRange','Pod','ReplicaSet','Role','Service', 'Template'];
242+
var onlyClusterSample = ['ClusterResourceQuota','Namespace','OAuthAccessToken','PersistentVolume','ProjectRequest','User'];
243+
244+
// at minimum, prove with tests that it is deduplicating by ignoring openshift!
245+
it('should return list of kinds that are scoped to a namespace by default', function() {
246+
var namespacedKinds = _.map(APIService.availableKinds(), 'kind');
247+
// from the fixtures included, we should have 51 namespaced kinds
248+
expect(namespacedKinds.length).toEqual(51);
249+
expect( _.difference(bothSample, namespacedKinds).length ).toEqual(0);
250+
});
251+
252+
it('should return list of all kinds, including those that are cluster scoped, when passed a truthy argument', function() {
253+
var allKinds = _.map(APIService.availableKinds(true), 'kind');
254+
// from the fixtures included, we should have 84 total kinds
255+
expect(allKinds.length).toEqual(84);
256+
expect( _.difference(bothSample, allKinds).length ).toEqual(0);
257+
expect( _.difference(onlyClusterSample, allKinds).length ).toEqual(0);
258+
});
259+
260+
it('should not duplicate kinds that exist in both an api group & the openshift namespace', function() {
261+
var allKinds = _.map(APIService.availableKinds(true), 'kind');
262+
var counts = _.reduce(allKinds, function(result, kind) {
263+
if(!result[kind]) {
264+
result[kind] = 0;
265+
}
266+
result[kind]++;
267+
return result;
268+
}, {});
269+
// TODO: need a review, not sure why these are still duplicated
270+
var whitelist = ['LocalSubjectAccessReview', 'SubjectAccessReview'];
271+
272+
_.each(counts, function(kindCount, key) {
273+
if(!_.includes(whitelist, key)) {
274+
expect(kindCount).toEqual(1);
275+
}
276+
});
277+
});
278+
279+
});
238280

239281
});

0 commit comments

Comments
 (0)
Please sign in to comment.