Skip to content

Commit ffa8187

Browse files
Add apiService.getPreferredVersion, and constant apiPreferredVersions
1 parent 4bcf671 commit ffa8187

7 files changed

+230
-7
lines changed

dist/origin-web-common-services.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
234234
angular.module('openshiftCommonServices')
235235
.factory('APIService', function(API_CFG,
236236
APIS_CFG,
237+
API_PREFERRED_VERSIONS,
237238
AuthService,
238239
Constants,
239240
Logger,
@@ -532,6 +533,17 @@ angular.module('openshiftCommonServices')
532533
return includeClusterScoped ? allKinds : namespacedKinds;
533534
};
534535

536+
// Provides us a way to ensure we consistently use the
537+
// correct {resource, group} for API calls. Version
538+
// will typically fallback to the preferredVersion of the API
539+
var getPreferredVersion = function(resource) {
540+
var preferred = API_PREFERRED_VERSIONS[resource];
541+
if(!preferred) {
542+
Logger.log("No preferred version for ", resource);
543+
}
544+
return preferred;
545+
};
546+
535547
return {
536548
toResourceGroupVersion: toResourceGroupVersion,
537549

@@ -549,7 +561,8 @@ angular.module('openshiftCommonServices')
549561

550562
invalidObjectKindOrVersion: invalidObjectKindOrVersion,
551563
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
552-
availableKinds: availableKinds
564+
availableKinds: availableKinds,
565+
getPreferredVersion: getPreferredVersion
553566
};
554567
});
555568
;'use strict';

dist/origin-web-common-ui.js

+9
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,15 @@ angular.module('openshiftCommonUI')
14681468
});
14691469
;'use strict';
14701470

1471+
angular
1472+
.module('openshiftCommonUI')
1473+
.filter('getPreferredVersion', function(APIService) {
1474+
return function(resource) {
1475+
return APIService.getPreferredVersion(resource);
1476+
};
1477+
});
1478+
;'use strict';
1479+
14711480
angular.module('openshiftCommonUI')
14721481
.filter('highlightKeywords', function(KeywordService) {
14731482
// Returns HTML wrapping the matching words in a `mark` tag.

dist/origin-web-common.js

+57-2
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,39 @@ angular.module('openshiftCommonUI')
14161416
}]);
14171417
;'use strict';
14181418

1419+
angular.module('openshiftCommonServices')
1420+
.constant('API_PREFERRED_VERSIONS', {
1421+
autoscaling: {group: 'autoscaling', resource: 'horizontalpodautoscalers' },
1422+
appliedclusterresourcequotas: {group: 'quota.openshift.io', resource: 'appliedclusterresourcequotas' },
1423+
bindings: {group: 'servicecatalog.k8s.io', resource: 'bindings' },
1424+
builds: {group: 'build.openshift.io', resource: 'builds' },
1425+
buildconfigs: {group: 'build.openshift.io', resource: 'buildconfigs' },
1426+
configmaps: 'configmaps',
1427+
deployments: {group: 'apps', resource: 'deployments' },
1428+
deploymentconfigs: {group: 'apps.openshift.io', resource: 'deploymentconfigs' },
1429+
imagestreams: {group: 'image.openshift.io', resource: 'imagestreams' },
1430+
imagestreamtags: {group: 'image.openshift.io', resource: 'imagestreamtags' },
1431+
instances: {group: 'servicecatalog.k8s.io', resource: 'instances' },
1432+
limitranges: 'limitranges',
1433+
pods: 'pods',
1434+
projects: {group: 'project.openshift.io', resource: 'projects'},
1435+
projectrequests: {group: 'project.openshift.io', resource: 'projectrequests'},
1436+
persistentvolumeclaims: 'persistentvolumeclaims',
1437+
replicasets: {group: 'extensions', resource: 'replicasets' },
1438+
replicationcontrollers: 'replicationcontrollers',
1439+
resourcequotas: 'resourcequotas',
1440+
rolebindings: 'rolebindings',
1441+
routes: {group: 'route.openshift.io', resource: 'routes' },
1442+
secrets: 'secrets',
1443+
selfsubjectrulesreviews: {group: 'authorization.k8s.io', resource: 'selfsubjectrulesreviews'},
1444+
services: 'services',
1445+
serviceaccounts: 'serviceaccounts',
1446+
serviceclasses: {group: 'servicecatalog.k8s.io', resource: 'serviceclasses' },
1447+
statefulsets: {group: 'apps', resource: 'statefulsets' },
1448+
templates: {group: 'template.openshift.io', resource: 'templates'}
1449+
});
1450+
;'use strict';
1451+
14191452
angular.module('openshiftCommonUI')
14201453
.filter("alertStatus", function() {
14211454
return function (type) {
@@ -1639,6 +1672,15 @@ angular.module('openshiftCommonUI')
16391672
}]);
16401673
;'use strict';
16411674

1675+
angular
1676+
.module('openshiftCommonUI')
1677+
.filter('getPreferredVersion', ["APIService", function(APIService) {
1678+
return function(resource) {
1679+
return APIService.getPreferredVersion(resource);
1680+
};
1681+
}]);
1682+
;'use strict';
1683+
16421684
angular.module('openshiftCommonUI')
16431685
.filter('highlightKeywords', ["KeywordService", function(KeywordService) {
16441686
// Returns HTML wrapping the matching words in a `mark` tag.
@@ -2112,8 +2154,9 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
21122154
};
21132155

21142156
angular.module('openshiftCommonServices')
2115-
.factory('APIService', ["API_CFG", "APIS_CFG", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG,
2157+
.factory('APIService', ["API_CFG", "APIS_CFG", "API_PREFERRED_VERSIONS", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG,
21162158
APIS_CFG,
2159+
API_PREFERRED_VERSIONS,
21172160
AuthService,
21182161
Constants,
21192162
Logger,
@@ -2412,6 +2455,17 @@ angular.module('openshiftCommonServices')
24122455
return includeClusterScoped ? allKinds : namespacedKinds;
24132456
};
24142457

2458+
// Provides us a way to ensure we consistently use the
2459+
// correct {resource, group} for API calls. Version
2460+
// will typically fallback to the preferredVersion of the API
2461+
var getPreferredVersion = function(resource) {
2462+
var preferred = API_PREFERRED_VERSIONS[resource];
2463+
if(!preferred) {
2464+
Logger.log("No preferred version for ", resource);
2465+
}
2466+
return preferred;
2467+
};
2468+
24152469
return {
24162470
toResourceGroupVersion: toResourceGroupVersion,
24172471

@@ -2429,7 +2483,8 @@ angular.module('openshiftCommonServices')
24292483

24302484
invalidObjectKindOrVersion: invalidObjectKindOrVersion,
24312485
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
2432-
availableKinds: availableKinds
2486+
availableKinds: availableKinds,
2487+
getPreferredVersion: getPreferredVersion
24332488
};
24342489
}]);
24352490
;'use strict';

dist/origin-web-common.min.js

+94-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,90 @@ content ? (scope.truncatedContent = truncateFilter(content, scope.limit, scope.u
485485
});
486486
}
487487
};
488-
} ]), angular.module("openshiftCommonUI").filter("alertStatus", function() {
488+
} ]), angular.module("openshiftCommonServices").constant("API_PREFERRED_VERSIONS", {
489+
autoscaling:{
490+
group:"autoscaling",
491+
resource:"horizontalpodautoscalers"
492+
},
493+
appliedclusterresourcequotas:{
494+
group:"quota.openshift.io",
495+
resource:"appliedclusterresourcequotas"
496+
},
497+
bindings:{
498+
group:"servicecatalog.k8s.io",
499+
resource:"bindings"
500+
},
501+
builds:{
502+
group:"build.openshift.io",
503+
resource:"builds"
504+
},
505+
buildconfigs:{
506+
group:"build.openshift.io",
507+
resource:"buildconfigs"
508+
},
509+
configmaps:"configmaps",
510+
deployments:{
511+
group:"apps",
512+
resource:"deployments"
513+
},
514+
deploymentconfigs:{
515+
group:"apps.openshift.io",
516+
resource:"deploymentconfigs"
517+
},
518+
imagestreams:{
519+
group:"image.openshift.io",
520+
resource:"imagestreams"
521+
},
522+
imagestreamtags:{
523+
group:"image.openshift.io",
524+
resource:"imagestreamtags"
525+
},
526+
instances:{
527+
group:"servicecatalog.k8s.io",
528+
resource:"instances"
529+
},
530+
limitranges:"limitranges",
531+
pods:"pods",
532+
projects:{
533+
group:"project.openshift.io",
534+
resource:"projects"
535+
},
536+
projectrequests:{
537+
group:"project.openshift.io",
538+
resource:"projectrequests"
539+
},
540+
persistentvolumeclaims:"persistentvolumeclaims",
541+
replicasets:{
542+
group:"extensions",
543+
resource:"replicasets"
544+
},
545+
replicationcontrollers:"replicationcontrollers",
546+
resourcequotas:"resourcequotas",
547+
rolebindings:"rolebindings",
548+
routes:{
549+
group:"route.openshift.io",
550+
resource:"routes"
551+
},
552+
secrets:"secrets",
553+
selfsubjectrulesreviews:{
554+
group:"authorization.k8s.io",
555+
resource:"selfsubjectrulesreviews"
556+
},
557+
services:"services",
558+
serviceaccounts:"serviceaccounts",
559+
serviceclasses:{
560+
group:"servicecatalog.k8s.io",
561+
resource:"serviceclasses"
562+
},
563+
statefulsets:{
564+
group:"apps",
565+
resource:"statefulsets"
566+
},
567+
templates:{
568+
group:"template.openshift.io",
569+
resource:"templates"
570+
}
571+
}), angular.module("openshiftCommonUI").filter("alertStatus", function() {
489572
return function(type) {
490573
var status;
491574
switch (type.toLowerCase()) {
@@ -622,6 +705,10 @@ if (!(a.metadata && a.metadata.creationTimestamp && b.metadata && b.metadata.cre
622705
return a.metadata.creationTimestamp < b.metadata.creationTimestamp ? reverse ? 1 :-1 :a.metadata.creationTimestamp > b.metadata.creationTimestamp ? reverse ? -1 :1 :0;
623706
}), items;
624707
};
708+
} ]), angular.module("openshiftCommonUI").filter("getPreferredVersion", [ "APIService", function(APIService) {
709+
return function(resource) {
710+
return APIService.getPreferredVersion(resource);
711+
};
625712
} ]), angular.module("openshiftCommonUI").filter("highlightKeywords", [ "KeywordService", function(KeywordService) {
626713
return function(str, keywords, caseSensitive) {
627714
if (!str) return str;
@@ -816,7 +903,7 @@ var segments = (this.resource || "").split("/");
816903
return segments.shift(), segments;
817904
}, ResourceGroupVersion.prototype.equals = function(resource, group, version) {
818905
return this.resource !== resource ? !1 :1 === arguments.length ? !0 :this.group !== group ? !1 :2 === arguments.length ? !0 :this.version !== version ? !1 :!0;
819-
}, angular.module("openshiftCommonServices").factory("APIService", [ "API_CFG", "APIS_CFG", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG, APIS_CFG, AuthService, Constants, Logger, $q, $http, $filter, $window) {
906+
}, 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) {
820907
function normalizeResource(resource) {
821908
if (!resource) return resource;
822909
var i = resource.indexOf("/");
@@ -947,6 +1034,9 @@ return value.group + "/" + value.kind;
9471034
});
9481035
}, namespacedKinds = calculateAvailableKinds(!1), allKinds = calculateAvailableKinds(!0), availableKinds = function(includeClusterScoped) {
9491036
return includeClusterScoped ? allKinds :namespacedKinds;
1037+
}, getPreferredVersion = function(resource) {
1038+
var preferred = API_PREFERRED_VERSIONS[resource];
1039+
return preferred || Logger.log("No preferred version for ", resource), preferred;
9501040
};
9511041
return {
9521042
toResourceGroupVersion:toResourceGroupVersion,
@@ -958,7 +1048,8 @@ kindToResourceGroupVersion:kindToResourceGroupVersion,
9581048
apiInfo:apiInfo,
9591049
invalidObjectKindOrVersion:invalidObjectKindOrVersion,
9601050
unsupportedObjectKindOrVersion:unsupportedObjectKindOrVersion,
961-
availableKinds:availableKinds
1051+
availableKinds:availableKinds,
1052+
getPreferredVersion:getPreferredVersion
9621053
};
9631054
} ]), angular.module("openshiftCommonServices").service("ApplicationsService", [ "$filter", "$q", "DataService", function($filter, $q, DataService) {
9641055
var getApplications = function(context) {

src/constants/apiPreferredVersions.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
angular.module('openshiftCommonServices')
4+
.constant('API_PREFERRED_VERSIONS', {
5+
autoscaling: {group: 'autoscaling', resource: 'horizontalpodautoscalers' },
6+
appliedclusterresourcequotas: {group: 'quota.openshift.io', resource: 'appliedclusterresourcequotas' },
7+
bindings: {group: 'servicecatalog.k8s.io', resource: 'bindings' },
8+
builds: {group: 'build.openshift.io', resource: 'builds' },
9+
buildconfigs: {group: 'build.openshift.io', resource: 'buildconfigs' },
10+
configmaps: 'configmaps',
11+
deployments: {group: 'apps', resource: 'deployments' },
12+
deploymentconfigs: {group: 'apps.openshift.io', resource: 'deploymentconfigs' },
13+
imagestreams: {group: 'image.openshift.io', resource: 'imagestreams' },
14+
imagestreamtags: {group: 'image.openshift.io', resource: 'imagestreamtags' },
15+
instances: {group: 'servicecatalog.k8s.io', resource: 'instances' },
16+
limitranges: 'limitranges',
17+
pods: 'pods',
18+
projects: {group: 'project.openshift.io', resource: 'projects'},
19+
projectrequests: {group: 'project.openshift.io', resource: 'projectrequests'},
20+
persistentvolumeclaims: 'persistentvolumeclaims',
21+
replicasets: {group: 'extensions', resource: 'replicasets' },
22+
replicationcontrollers: 'replicationcontrollers',
23+
resourcequotas: 'resourcequotas',
24+
rolebindings: 'rolebindings',
25+
routes: {group: 'route.openshift.io', resource: 'routes' },
26+
secrets: 'secrets',
27+
selfsubjectrulesreviews: {group: 'authorization.k8s.io', resource: 'selfsubjectrulesreviews'},
28+
services: 'services',
29+
serviceaccounts: 'serviceaccounts',
30+
serviceclasses: {group: 'servicecatalog.k8s.io', resource: 'serviceclasses' },
31+
statefulsets: {group: 'apps', resource: 'statefulsets' },
32+
templates: {group: 'template.openshift.io', resource: 'templates'}
33+
});

src/filters/getPreferredVersion.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
angular
4+
.module('openshiftCommonUI')
5+
.filter('getPreferredVersion', function(APIService) {
6+
return function(resource) {
7+
return APIService.getPreferredVersion(resource);
8+
};
9+
});

src/services/apiService.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
4141
angular.module('openshiftCommonServices')
4242
.factory('APIService', function(API_CFG,
4343
APIS_CFG,
44+
API_PREFERRED_VERSIONS,
4445
AuthService,
4546
Constants,
4647
Logger,
@@ -339,6 +340,17 @@ angular.module('openshiftCommonServices')
339340
return includeClusterScoped ? allKinds : namespacedKinds;
340341
};
341342

343+
// Provides us a way to ensure we consistently use the
344+
// correct {resource, group} for API calls. Version
345+
// will typically fallback to the preferredVersion of the API
346+
var getPreferredVersion = function(resource) {
347+
var preferred = API_PREFERRED_VERSIONS[resource];
348+
if(!preferred) {
349+
Logger.log("No preferred version for ", resource);
350+
}
351+
return preferred;
352+
};
353+
342354
return {
343355
toResourceGroupVersion: toResourceGroupVersion,
344356

@@ -356,6 +368,7 @@ angular.module('openshiftCommonServices')
356368

357369
invalidObjectKindOrVersion: invalidObjectKindOrVersion,
358370
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
359-
availableKinds: availableKinds
371+
availableKinds: availableKinds,
372+
getPreferredVersion: getPreferredVersion
360373
};
361374
});

0 commit comments

Comments
 (0)