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 4106a18

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

File tree

7 files changed

+1439
-588
lines changed

7 files changed

+1439
-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

+50-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,50 @@ describe("APIService", function(){
234235
});
235236
}));
236237
});
237-
*/
238+
239+
240+
describe('#availableKinds', function() {
241+
// at minimum, prove with tests that it is deduplicating by ignoring openshift!
242+
it('should return list of kinds that are scoped to a namespace by default', function() {
243+
var namespacedKinds = APIService.availableKinds();
244+
var expectedNames = [
245+
'Binding', 'ConfigMap', 'Endpoints', 'Event', 'LimitRange', 'PersistentVolumeClaim', 'Pod', 'PodTemplate',
246+
'ReplicationController', 'ResourceQuota', 'Secret', 'ServiceAccount', 'Service', 'StatefulSet', 'DeploymentConfig',
247+
'LocalSubjectAccessReview', 'LocalResourceAccessReview', 'LocalSubjectAccessReview', 'Policy', 'PolicyBinding',
248+
'ResourceAccessReview', 'RoleBindingRestriction', 'RoleBinding', 'Role', 'SelfSubjectRulesReview',
249+
'SubjectAccessReview', 'SubjectRulesReview', 'BuildConfig', 'Build', 'DaemonSet', 'Deployment',
250+
'HorizontalPodAutoscaler', 'Ingress', 'Job', 'NetworkPolicy', 'ReplicaSet', 'ReplicationControllerDummy',
251+
'ImageStreamImage', 'ImageStreamImport', 'ImageStreamMapping', 'ImageStream', 'ImageStreamTag', 'EgressNetworkPolicy',
252+
'PodDisruptionBudget', 'AppliedClusterResourceQuota', 'Route', 'PodSecurityPolicyReview',
253+
'PodSecurityPolicySelfSubjectReview', 'PodSecurityPolicySubjectReview', 'Template', 'TemplateInstance'
254+
];
255+
// from the fixtures included, we should have 51 namespaced kinds
256+
expect(namespacedKinds.length).toEqual(51);
257+
expect( _.map(namespacedKinds, 'kind') ).toEqual(expectedNames);
258+
});
259+
260+
it('should return list of all kinds, including those that are cluster scoped, when passed a truthy argument', function() {
261+
var allKinds = APIService.availableKinds(true);
262+
var expectedNames = [
263+
'Binding', 'ComponentStatus', 'ConfigMap', 'Endpoints', 'Event', 'LimitRange', 'Namespace', 'Node',
264+
'PersistentVolumeClaim', 'PersistentVolume', 'Pod', 'PodTemplate', 'ReplicationController', 'ResourceQuota', 'Secret',
265+
'SecurityContextConstraints', 'ServiceAccount', 'Service', 'StatefulSet', 'DeploymentConfig', 'TokenReview',
266+
'LocalSubjectAccessReview', 'SelfSubjectAccessReview', 'SubjectAccessReview', 'ClusterPolicy', 'ClusterPolicyBinding',
267+
'ClusterRoleBinding', 'ClusterRole', 'LocalResourceAccessReview', 'LocalSubjectAccessReview', 'Policy', 'PolicyBinding',
268+
'ResourceAccessReview', 'RoleBindingRestriction', 'RoleBinding', 'Role', 'SelfSubjectRulesReview', 'SubjectAccessReview',
269+
'SubjectRulesReview', 'BuildConfig', 'Build', 'CertificateSigningRequest', 'DaemonSet', 'Deployment',
270+
'HorizontalPodAutoscaler', 'Ingress', 'Job', 'NetworkPolicy', 'PodSecurityPolicy', 'ReplicaSet',
271+
'ReplicationControllerDummy', 'ThirdPartyResource', 'Image', 'ImageSignature', 'ImageStreamImage', 'ImageStreamImport',
272+
'ImageStreamMapping', 'ImageStream', 'ImageStreamTag', 'ClusterNetwork', 'EgressNetworkPolicy', 'HostSubnet',
273+
'NetNamespace', 'OAuthAccessToken', 'OAuthAuthorizeToken', 'OAuthClientAuthorization', 'OAuthClient',
274+
'PodDisruptionBudget', 'ProjectRequest', 'Project', 'AppliedClusterResourceQuota', 'ClusterResourceQuota', 'Route',
275+
'PodSecurityPolicyReview', 'PodSecurityPolicySelfSubjectReview', 'PodSecurityPolicySubjectReview', 'StorageClass',
276+
'BrokerTemplateInstance', 'Template', 'TemplateInstance', 'Group', 'Identity', 'UserIdentityMapping', 'User'
277+
];
278+
// from the fixtures included, we should have 84 total kinds
279+
expect(allKinds.length).toEqual(84);
280+
expect( _.map(allKinds, 'kind') ).toEqual(expectedNames);
281+
});
282+
});
238283

239284
});

0 commit comments

Comments
 (0)
Please sign in to comment.