Dedupe daemonsets in apiService, externalize dedupe config, update fixtures, update tests

parent 201f9efc
......@@ -220,6 +220,7 @@ angular.module('openshiftCommonServices')
.factory('APIService', function(API_CFG,
APIS_CFG,
API_PREFERRED_VERSIONS,
API_DEDUPLICATION,
AuthService,
Constants,
Logger,
......@@ -467,6 +468,7 @@ angular.module('openshiftCommonServices')
if (apiObject && apiObject.apiVersion) { version = apiObject.apiVersion; }
return "Invalid kind ("+kind+") or API version ("+version+")";
};
var unsupportedObjectKindOrVersion = function(apiObject) {
var kind = "<none>";
var version = "<none>";
......@@ -475,15 +477,11 @@ angular.module('openshiftCommonServices')
return "The API version "+version+" for kind " + kind + " is not supported by this server";
};
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
var dedupeGroups = [{group: 'authorization.openshift.io'}];
var dedupeKinds = [{group: 'extensions', kind: 'HorizontalPodAutoscaler'}];
var excludeKindFromAPIGroupList = function(groupName, resourceKind) {
return !!(
_.find(dedupeKinds, {group: groupName, kind: resourceKind}) ||
_.find(dedupeGroups, {group: groupName})
_.find(API_DEDUPLICATION.kinds, {group: groupName, kind: resourceKind}) ||
_.find(API_DEDUPLICATION.groups, {group: groupName})
);
};
......@@ -3803,6 +3801,18 @@ angular.module('openshiftCommonServices')
;'use strict';
angular.module('openshiftCommonServices')
.constant('API_DEDUPLICATION', {
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
groups: [{group: 'authorization.openshift.io'}],
kinds: [
{group: 'extensions', kind: 'HorizontalPodAutoscaler'},
{group: 'extensions', kind: 'DaemonSet'}
]
});
;'use strict';
angular.module('openshiftCommonServices')
.constant('API_PREFERRED_VERSIONS', {
appliedclusterresourcequotas: {group: 'quota.openshift.io', version: 'v1', resource: 'appliedclusterresourcequotas' },
builds: {group: 'build.openshift.io', version: 'v1', resource: 'builds' },
......
......@@ -1420,6 +1420,18 @@ angular.module('openshiftCommonUI')
;'use strict';
angular.module('openshiftCommonServices')
.constant('API_DEDUPLICATION', {
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
groups: [{group: 'authorization.openshift.io'}],
kinds: [
{group: 'extensions', kind: 'HorizontalPodAutoscaler'},
{group: 'extensions', kind: 'DaemonSet'}
]
});
;'use strict';
angular.module('openshiftCommonServices')
.constant('API_PREFERRED_VERSIONS', {
appliedclusterresourcequotas: {group: 'quota.openshift.io', version: 'v1', resource: 'appliedclusterresourcequotas' },
builds: {group: 'build.openshift.io', version: 'v1', resource: 'builds' },
......@@ -2271,9 +2283,10 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
};
angular.module('openshiftCommonServices')
.factory('APIService', ["API_CFG", "APIS_CFG", "API_PREFERRED_VERSIONS", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG,
.factory('APIService', ["API_CFG", "APIS_CFG", "API_PREFERRED_VERSIONS", "API_DEDUPLICATION", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG,
APIS_CFG,
API_PREFERRED_VERSIONS,
API_DEDUPLICATION,
AuthService,
Constants,
Logger,
......@@ -2521,6 +2534,7 @@ angular.module('openshiftCommonServices')
if (apiObject && apiObject.apiVersion) { version = apiObject.apiVersion; }
return "Invalid kind ("+kind+") or API version ("+version+")";
};
var unsupportedObjectKindOrVersion = function(apiObject) {
var kind = "<none>";
var version = "<none>";
......@@ -2529,15 +2543,11 @@ angular.module('openshiftCommonServices')
return "The API version "+version+" for kind " + kind + " is not supported by this server";
};
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
var dedupeGroups = [{group: 'authorization.openshift.io'}];
var dedupeKinds = [{group: 'extensions', kind: 'HorizontalPodAutoscaler'}];
var excludeKindFromAPIGroupList = function(groupName, resourceKind) {
return !!(
_.find(dedupeKinds, {group: groupName, kind: resourceKind}) ||
_.find(dedupeGroups, {group: groupName})
_.find(API_DEDUPLICATION.kinds, {group: groupName, kind: resourceKind}) ||
_.find(API_DEDUPLICATION.groups, {group: groupName})
);
};
......
......@@ -471,7 +471,18 @@ content ? (scope.truncatedContent = truncateFilter(content, scope.limit, scope.u
});
}
};
} ]), angular.module("openshiftCommonServices").constant("API_PREFERRED_VERSIONS", {
} ]), angular.module("openshiftCommonServices").constant("API_DEDUPLICATION", {
groups:[ {
group:"authorization.openshift.io"
} ],
kinds:[ {
group:"extensions",
kind:"HorizontalPodAutoscaler"
}, {
group:"extensions",
kind:"DaemonSet"
} ]
}), angular.module("openshiftCommonServices").constant("API_PREFERRED_VERSIONS", {
appliedclusterresourcequotas:{
group:"quota.openshift.io",
version:"v1",
......@@ -1058,7 +1069,7 @@ var segments = (this.resource || "").split("/");
return segments.shift(), segments;
}, ResourceGroupVersion.prototype.equals = function(resource, group, version) {
return this.resource !== resource ? !1 :1 === arguments.length ? !0 :this.group !== group ? !1 :2 === arguments.length ? !0 :this.version !== version ? !1 :!0;
}, angular.module("openshiftCommonServices").factory("APIService", [ "API_CFG", "APIS_CFG", "API_PREFERRED_VERSIONS", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG, APIS_CFG, API_PREFERRED_VERSIONS, AuthService, Constants, Logger, $q, $http, $filter, $window) {
}, angular.module("openshiftCommonServices").factory("APIService", [ "API_CFG", "APIS_CFG", "API_PREFERRED_VERSIONS", "API_DEDUPLICATION", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG, APIS_CFG, API_PREFERRED_VERSIONS, API_DEDUPLICATION, AuthService, Constants, Logger, $q, $http, $filter, $window) {
function normalizeResource(resource) {
if (!resource) return resource;
var i = resource.indexOf("/");
......@@ -1157,16 +1168,11 @@ return apiObject && apiObject.kind && (kind = apiObject.kind), apiObject && apiO
}, unsupportedObjectKindOrVersion = function(apiObject) {
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";
}, dedupeGroups = [ {
group:"authorization.openshift.io"
} ], dedupeKinds = [ {
group:"extensions",
kind:"HorizontalPodAutoscaler"
} ], excludeKindFromAPIGroupList = function(groupName, resourceKind) {
return !(!_.find(dedupeKinds, {
}, excludeKindFromAPIGroupList = function(groupName, resourceKind) {
return !(!_.find(API_DEDUPLICATION.kinds, {
group:groupName,
kind:resourceKind
}) && !_.find(dedupeGroups, {
}) && !_.find(API_DEDUPLICATION.groups, {
group:groupName
}));
}, calculateAvailableKinds = function(includeClusterScoped) {
......
'use strict';
angular.module('openshiftCommonServices')
.constant('API_DEDUPLICATION', {
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
groups: [{group: 'authorization.openshift.io'}],
kinds: [
{group: 'extensions', kind: 'HorizontalPodAutoscaler'},
{group: 'extensions', kind: 'DaemonSet'}
]
});
......@@ -42,6 +42,7 @@ angular.module('openshiftCommonServices')
.factory('APIService', function(API_CFG,
APIS_CFG,
API_PREFERRED_VERSIONS,
API_DEDUPLICATION,
AuthService,
Constants,
Logger,
......@@ -289,6 +290,7 @@ angular.module('openshiftCommonServices')
if (apiObject && apiObject.apiVersion) { version = apiObject.apiVersion; }
return "Invalid kind ("+kind+") or API version ("+version+")";
};
var unsupportedObjectKindOrVersion = function(apiObject) {
var kind = "<none>";
var version = "<none>";
......@@ -297,15 +299,11 @@ angular.module('openshiftCommonServices')
return "The API version "+version+" for kind " + kind + " is not supported by this server";
};
// Exclude duplicate kinds we know about that map to the same storage as another
// group/kind. This is unusual, so we are special casing these.
var dedupeGroups = [{group: 'authorization.openshift.io'}];
var dedupeKinds = [{group: 'extensions', kind: 'HorizontalPodAutoscaler'}];
var excludeKindFromAPIGroupList = function(groupName, resourceKind) {
return !!(
_.find(dedupeKinds, {group: groupName, kind: resourceKind}) ||
_.find(dedupeGroups, {group: groupName})
_.find(API_DEDUPLICATION.kinds, {group: groupName, kind: resourceKind}) ||
_.find(API_DEDUPLICATION.groups, {group: groupName})
);
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -69,7 +69,7 @@ describe("APIService", function() {
[{kind: 'PodTemplate', group: ''}, {"resource":"podtemplates","group":"","version":"v1"}],
[{kind: 'HorizontalPodAutoscaler', group: 'autoscaling'}, {"resource":"horizontalpodautoscalers","group":"autoscaling","version":"v1"}],
[{kind: 'DaemonSet', group: 'extensions'}, {"resource":"daemonsets","group":"extensions","version":"v1beta1"}],
[{kind: 'RoleBinding', group: 'rbac.authorization.k8s.io'}, {"resource":"rolebindings","group":"rbac.authorization.k8s.io","version":"v1beta1"}],
[{kind: 'RoleBinding', group: 'rbac.authorization.k8s.io'}, {"resource":"rolebindings","group":"rbac.authorization.k8s.io","version":"v1"}],
[{kind: 'PodPreset', group: 'settings.k8s.io'}, {"resource":"podpresets","group":"settings.k8s.io","version":"v1alpha1"}],
[{kind: 'Policy', group: 'authorization.openshift.io'}, {"resource":"policies","group":"authorization.openshift.io","version":"v1"}],
[{kind: 'Template', group: 'template.openshift.io'}, {"resource":"templates","group":"template.openshift.io","version":"v1"}],
......@@ -432,13 +432,20 @@ describe("APIService", function() {
// These kinds either no longer exist or have been moved (for example, now
// are listed under a different group). They still exist, but should be
// ignored in favor of the preferred alias.
it('should NOT return kind:HorizontalPodAutoscaler with group: extensions', function() {
it('should NOT return kind: HorizontalPodAutoscaler with group: extensions', function() {
var allKinds = APIService.availableKinds(true);
var toExclude = { group: 'extensions', kind: 'HorizontalPodAutoscaler' };
expect(_.find(allKinds, toExclude)).toEqual(undefined);
});
it('should NOT return kind: DaemonSet with group: extensions', function() {
var allKinds = APIService.availableKinds(true);
var toExclude = { group: 'extensions', kind: 'DaemonSet' };
expect(_.find(allKinds, toExclude)).toEqual(undefined);
});
it('should NOT return any resource with group: authorization.openshift.io', function() {
var allKinds = APIService.availableKinds(true);
var toExclude = { group: 'authorization.openshift.io' };
......
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