Commit 8c94a437 by benjaminapetersen

Add logic to dedupe kinds by ignoring "openshift" namespace in APIService.calculateAvailableKinds()

parent bd077870
......@@ -471,8 +471,10 @@ angular.module('openshiftCommonServices')
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
// Legacy openshift and k8s kinds
_.each(API_CFG, function(api) {
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
return key !== 'openshift';
}), function(api) {
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
......
......@@ -1817,8 +1817,10 @@ angular.module('openshiftCommonServices')
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
// Legacy openshift and k8s kinds
_.each(API_CFG, function(api) {
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
return key !== 'openshift';
}), function(api) {
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
......
......@@ -741,7 +741,9 @@ var kind = "<none>", version = "<none>";
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";
}, calculateAvailableKinds = function(includeClusterScoped) {
var kinds = [], rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
return _.each(API_CFG, function(api) {
return _.each(_.pick(API_CFG, function(value, key) {
return "openshift" !== key;
}), function(api) {
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) return;
......
......@@ -268,8 +268,10 @@ angular.module('openshiftCommonServices')
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
// Legacy openshift and k8s kinds
_.each(API_CFG, function(api) {
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
return key !== 'openshift';
}), function(api) {
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
......
{
"node": true,
"browser": true,
"esversion": 6,
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": false,
"noarg": true,
"quotmark": false,
"regexp": true,
"smarttabs": true,
"strict": true,
"sub" : true,
"undef": true,
"unused": true,
"expr" : true,
"globals": {
"ace": false,
"after": false,
"afterEach": false,
"afterAll": false,
"angular": false,
"by": false,
"before": false,
"beforeAll": false,
"beforeEach": false,
"browser": false,
"describe": false,
"element" : false,
"expect": false,
"inject": false,
"it": false,
"xit": false,
"jasmine": false,
"spyOn": false,
"hawtioPluginLoader": false,
"HawtioCore": false,
"Logger" : false,
"LabelSelector": false,
"moment": false,
"Messenger" : false,
"protractor" : false,
"URI": false,
"ZeroClipboard": false,
"$": false,
"_" : false
}
}
describe("APIService", function(){
describe("APIService", function() {
var APIService;
beforeEach(function(){
inject(function(_APIService_){
inject(function(_APIService_) {
APIService = _APIService_;
});
});
describe("#toResourceGroupVersion", function(){
describe("#toResourceGroupVersion", function() {
var tc = [
// string args
......@@ -62,7 +62,8 @@ describe("APIService", function(){
}));
});
/*
describe("#parseGroupVersion", function(){
var tc = [
// invalid cases
......@@ -234,6 +235,78 @@ describe("APIService", function(){
});
}));
});
*/
describe('#availableKinds', function() {
var bothSample = ['Binding','ConfigMap','DeploymentConfig','Event','LimitRange','Pod','ReplicaSet','Role','Service', 'Template'];
var onlyClusterSample = ['ClusterResourceQuota','Namespace','OAuthAccessToken','PersistentVolume','ProjectRequest','User'];
it('should return list of kinds that are scoped to a namespace by default', function() {
var namespacedKinds = _.map(APIService.availableKinds(), 'kind');
expect( _.difference(bothSample, namespacedKinds).length ).toEqual(0);
});
it('should not return list cluster scoped kinds by default', function() {
var namespacedKinds = _.map(APIService.availableKinds(), 'kind');
expect( _.difference(onlyClusterSample, namespacedKinds).length ).toEqual(onlyClusterSample.length);
});
it('should return list of all kinds, including those that are cluster scoped, when passed a truthy argument', function() {
var allKinds = _.map(APIService.availableKinds(true), 'kind');
expect( _.difference(bothSample, allKinds).length ).toEqual(0);
expect( _.difference(onlyClusterSample, allKinds).length ).toEqual(0);
});
// kinds from the old /oapi should not be iterated at all.
it('should not list kinds from the old /oapi namespace (that do not have a group)', function() {
var allKinds = APIService.availableKinds(true);
var shouldNotBeFound = [];
// This is a sampling of items from /oapi that should no longer be listed
var oapiShouldNotExistSample = [
{kind: 'ClusterPolicy'},
{kind: 'ClusterRole'},
{kind: 'Image'},
{kind: 'Template'},
{kind: 'Project'},
{kind: 'User'}
];
_.each(oapiShouldNotExistSample, function(kindToFind) {
var found = _.find(allKinds, function(kind) {
return (kind.kind === kindToFind.kind) && !_.includes(_.keys(kind), 'group');
});
if(found) {
shouldNotBeFound.push(found);
}
});
expect(shouldNotBeFound.length).toEqual(0);
});
// unlike the /oapi endpoint, the /api endpoint should still be listed
it('should list items from the k8s /api namespace (that do not have a group)', function() {
var allKinds = APIService.availableKinds(true);
var shouldBeFound = [];
// this is a sampling of items from /api that should still be listed,
// even though they do not yet have a group associated.
var k8sAPIStillExistsSample = [
{kind: 'Binding'},
{kind: 'ConfigMap'},
{kind: 'Namespace'},
{kind: 'PersistentVolume'},
{kind: 'Service'},
{kind: 'ServiceAccount'},
{kind: 'Pod'}
];
_.each(k8sAPIStillExistsSample, function(kindToFind) {
var found = _.find(allKinds, function(kind) {
return (kind.kind === kindToFind.kind) && !_.includes(_.keys(kind), 'group');
});
if(found) {
shouldBeFound.push(found);
}
});
expect(shouldBeFound.length).toEqual(k8sAPIStillExistsSample.length);
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment