Skip to content

Add apiService.getPreferredVersion, and constant apiPreferredVersions #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion dist/origin-web-common-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
angular.module('openshiftCommonServices')
.factory('APIService', function(API_CFG,
APIS_CFG,
API_PREFERRED_VERSIONS,
AuthService,
Constants,
Logger,
Expand Down Expand Up @@ -532,6 +533,17 @@ angular.module('openshiftCommonServices')
return includeClusterScoped ? allKinds : namespacedKinds;
};

// Provides us a way to ensure we consistently use the
// correct {resource, group} for API calls. Version
// will typically fallback to the preferredVersion of the API
var getPreferredVersion = function(resource) {
var preferred = API_PREFERRED_VERSIONS[resource];
if(!preferred) {
Logger.log("No preferred version for ", resource);
}
return preferred;
};

return {
toResourceGroupVersion: toResourceGroupVersion,

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

invalidObjectKindOrVersion: invalidObjectKindOrVersion,
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
availableKinds: availableKinds
availableKinds: availableKinds,
getPreferredVersion: getPreferredVersion
};
});
;'use strict';
Expand Down
6 changes: 6 additions & 0 deletions dist/origin-web-common-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,12 @@ angular.module('openshiftCommonUI')
});
;'use strict';

angular.module('openshiftCommonUI')
.filter('preferredVersion', function(APIService) {
return APIService.getPreferredVersion;
});
;'use strict';

angular.module('openshiftCommonUI')
.filter('prettifyJSON', function(parseJSONFilter) {
return function(json) {
Expand Down
56 changes: 54 additions & 2 deletions dist/origin-web-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,39 @@ angular.module('openshiftCommonUI')
}]);
;'use strict';

angular.module('openshiftCommonServices')
.constant('API_PREFERRED_VERSIONS', {
autoscaling: {group: 'autoscaling', resource: 'horizontalpodautoscalers' },
appliedclusterresourcequotas: {group: 'quota.openshift.io', resource: 'appliedclusterresourcequotas' },
bindings: {group: 'servicecatalog.k8s.io', resource: 'bindings' },
builds: {group: 'build.openshift.io', resource: 'builds' },
buildconfigs: {group: 'build.openshift.io', resource: 'buildconfigs' },
configmaps: 'configmaps',
deployments: {group: 'apps', resource: 'deployments' },
deploymentconfigs: {group: 'apps.openshift.io', resource: 'deploymentconfigs' },
imagestreams: {group: 'image.openshift.io', resource: 'imagestreams' },
imagestreamtags: {group: 'image.openshift.io', resource: 'imagestreamtags' },
instances: {group: 'servicecatalog.k8s.io', resource: 'instances' },
limitranges: 'limitranges',
pods: 'pods',
projects: {group: 'project.openshift.io', resource: 'projects'},
projectrequests: {group: 'project.openshift.io', resource: 'projectrequests'},
persistentvolumeclaims: 'persistentvolumeclaims',
replicasets: {group: 'extensions', resource: 'replicasets' },
replicationcontrollers: 'replicationcontrollers',
resourcequotas: 'resourcequotas',
rolebindings: 'rolebindings',
routes: {group: 'route.openshift.io', resource: 'routes' },
secrets: 'secrets',
selfsubjectrulesreviews: {group: 'authorization.k8s.io', resource: 'selfsubjectrulesreviews'},
services: 'services',
serviceaccounts: 'serviceaccounts',
serviceclasses: {group: 'servicecatalog.k8s.io', resource: 'serviceclasses' },
statefulsets: {group: 'apps', resource: 'statefulsets' },
templates: {group: 'template.openshift.io', resource: 'templates'}
});
;'use strict';

angular.module('openshiftCommonUI')
.filter("alertStatus", function() {
return function (type) {
Expand Down Expand Up @@ -1738,6 +1771,12 @@ angular.module('openshiftCommonUI')
});
;'use strict';

angular.module('openshiftCommonUI')
.filter('preferredVersion', ["APIService", function(APIService) {
return APIService.getPreferredVersion;
}]);
;'use strict';

angular.module('openshiftCommonUI')
.filter('prettifyJSON', ["parseJSONFilter", function(parseJSONFilter) {
return function(json) {
Expand Down Expand Up @@ -2117,8 +2156,9 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
};

angular.module('openshiftCommonServices')
.factory('APIService', ["API_CFG", "APIS_CFG", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG,
.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,
Expand Down Expand Up @@ -2417,6 +2457,17 @@ angular.module('openshiftCommonServices')
return includeClusterScoped ? allKinds : namespacedKinds;
};

// Provides us a way to ensure we consistently use the
// correct {resource, group} for API calls. Version
// will typically fallback to the preferredVersion of the API
var getPreferredVersion = function(resource) {
var preferred = API_PREFERRED_VERSIONS[resource];
if(!preferred) {
Logger.log("No preferred version for ", resource);
}
return preferred;
};

return {
toResourceGroupVersion: toResourceGroupVersion,

Expand All @@ -2434,7 +2485,8 @@ angular.module('openshiftCommonServices')

invalidObjectKindOrVersion: invalidObjectKindOrVersion,
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
availableKinds: availableKinds
availableKinds: availableKinds,
getPreferredVersion: getPreferredVersion
};
}]);
;'use strict';
Expand Down
97 changes: 93 additions & 4 deletions dist/origin-web-common.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,90 @@ content ? (scope.truncatedContent = truncateFilter(content, scope.limit, scope.u
});
}
};
} ]), angular.module("openshiftCommonUI").filter("alertStatus", function() {
} ]), angular.module("openshiftCommonServices").constant("API_PREFERRED_VERSIONS", {
autoscaling:{
group:"autoscaling",
resource:"horizontalpodautoscalers"
},
appliedclusterresourcequotas:{
group:"quota.openshift.io",
resource:"appliedclusterresourcequotas"
},
bindings:{
group:"servicecatalog.k8s.io",
resource:"bindings"
},
builds:{
group:"build.openshift.io",
resource:"builds"
},
buildconfigs:{
group:"build.openshift.io",
resource:"buildconfigs"
},
configmaps:"configmaps",
deployments:{
group:"apps",
resource:"deployments"
},
deploymentconfigs:{
group:"apps.openshift.io",
resource:"deploymentconfigs"
},
imagestreams:{
group:"image.openshift.io",
resource:"imagestreams"
},
imagestreamtags:{
group:"image.openshift.io",
resource:"imagestreamtags"
},
instances:{
group:"servicecatalog.k8s.io",
resource:"instances"
},
limitranges:"limitranges",
pods:"pods",
projects:{
group:"project.openshift.io",
resource:"projects"
},
projectrequests:{
group:"project.openshift.io",
resource:"projectrequests"
},
persistentvolumeclaims:"persistentvolumeclaims",
replicasets:{
group:"extensions",
resource:"replicasets"
},
replicationcontrollers:"replicationcontrollers",
resourcequotas:"resourcequotas",
rolebindings:"rolebindings",
routes:{
group:"route.openshift.io",
resource:"routes"
},
secrets:"secrets",
selfsubjectrulesreviews:{
group:"authorization.k8s.io",
resource:"selfsubjectrulesreviews"
},
services:"services",
serviceaccounts:"serviceaccounts",
serviceclasses:{
group:"servicecatalog.k8s.io",
resource:"serviceclasses"
},
statefulsets:{
group:"apps",
resource:"statefulsets"
},
templates:{
group:"template.openshift.io",
resource:"templates"
}
}), angular.module("openshiftCommonUI").filter("alertStatus", function() {
return function(type) {
var status;
switch (type.toLowerCase()) {
Expand Down Expand Up @@ -646,7 +729,9 @@ return "object" == typeof jsonObj ? jsonObj :null;
return null;
}
};
}), angular.module("openshiftCommonUI").filter("prettifyJSON", [ "parseJSONFilter", function(parseJSONFilter) {
}), angular.module("openshiftCommonUI").filter("preferredVersion", [ "APIService", function(APIService) {
return APIService.getPreferredVersion;
} ]), angular.module("openshiftCommonUI").filter("prettifyJSON", [ "parseJSONFilter", function(parseJSONFilter) {
return function(json) {
var jsonObj = parseJSONFilter(json);
return jsonObj ? JSON.stringify(jsonObj, null, 4) :json;
Expand Down Expand Up @@ -816,7 +901,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", "AuthService", "Constants", "Logger", "$q", "$http", "$filter", "$window", function(API_CFG, APIS_CFG, AuthService, Constants, Logger, $q, $http, $filter, $window) {
}, 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) {
function normalizeResource(resource) {
if (!resource) return resource;
var i = resource.indexOf("/");
Expand Down Expand Up @@ -947,6 +1032,9 @@ return value.group + "/" + value.kind;
});
}, namespacedKinds = calculateAvailableKinds(!1), allKinds = calculateAvailableKinds(!0), availableKinds = function(includeClusterScoped) {
return includeClusterScoped ? allKinds :namespacedKinds;
}, getPreferredVersion = function(resource) {
var preferred = API_PREFERRED_VERSIONS[resource];
return preferred || Logger.log("No preferred version for ", resource), preferred;
};
return {
toResourceGroupVersion:toResourceGroupVersion,
Expand All @@ -958,7 +1046,8 @@ kindToResourceGroupVersion:kindToResourceGroupVersion,
apiInfo:apiInfo,
invalidObjectKindOrVersion:invalidObjectKindOrVersion,
unsupportedObjectKindOrVersion:unsupportedObjectKindOrVersion,
availableKinds:availableKinds
availableKinds:availableKinds,
getPreferredVersion:getPreferredVersion
};
} ]), angular.module("openshiftCommonServices").service("ApplicationsService", [ "$q", "DataService", function($q, DataService) {
var listStandaloneReplicationControllers = function(context) {
Expand Down
33 changes: 33 additions & 0 deletions src/constants/apiPreferredVersions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

angular.module('openshiftCommonServices')
.constant('API_PREFERRED_VERSIONS', {
autoscaling: {group: 'autoscaling', resource: 'horizontalpodautoscalers' },
appliedclusterresourcequotas: {group: 'quota.openshift.io', resource: 'appliedclusterresourcequotas' },
bindings: {group: 'servicecatalog.k8s.io', resource: 'bindings' },
builds: {group: 'build.openshift.io', resource: 'builds' },
buildconfigs: {group: 'build.openshift.io', resource: 'buildconfigs' },
configmaps: 'configmaps',
deployments: {group: 'apps', resource: 'deployments' },
deploymentconfigs: {group: 'apps.openshift.io', resource: 'deploymentconfigs' },
imagestreams: {group: 'image.openshift.io', resource: 'imagestreams' },
imagestreamtags: {group: 'image.openshift.io', resource: 'imagestreamtags' },
instances: {group: 'servicecatalog.k8s.io', resource: 'instances' },
limitranges: 'limitranges',
pods: 'pods',
projects: {group: 'project.openshift.io', resource: 'projects'},
projectrequests: {group: 'project.openshift.io', resource: 'projectrequests'},
persistentvolumeclaims: 'persistentvolumeclaims',
replicasets: {group: 'extensions', resource: 'replicasets' },
replicationcontrollers: 'replicationcontrollers',
resourcequotas: 'resourcequotas',
rolebindings: 'rolebindings',
routes: {group: 'route.openshift.io', resource: 'routes' },
secrets: 'secrets',
selfsubjectrulesreviews: {group: 'authorization.k8s.io', resource: 'selfsubjectrulesreviews'},
services: 'services',
serviceaccounts: 'serviceaccounts',
serviceclasses: {group: 'servicecatalog.k8s.io', resource: 'serviceclasses' },
statefulsets: {group: 'apps', resource: 'statefulsets' },
templates: {group: 'template.openshift.io', resource: 'templates'}
});
6 changes: 6 additions & 0 deletions src/filters/preferredVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

angular.module('openshiftCommonUI')
.filter('preferredVersion', function(APIService) {
return APIService.getPreferredVersion;
});
15 changes: 14 additions & 1 deletion src/services/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ResourceGroupVersion.prototype.equals = function(resource, group, version) {
angular.module('openshiftCommonServices')
.factory('APIService', function(API_CFG,
APIS_CFG,
API_PREFERRED_VERSIONS,
AuthService,
Constants,
Logger,
Expand Down Expand Up @@ -339,6 +340,17 @@ angular.module('openshiftCommonServices')
return includeClusterScoped ? allKinds : namespacedKinds;
};

// Provides us a way to ensure we consistently use the
// correct {resource, group} for API calls. Version
// will typically fallback to the preferredVersion of the API
var getPreferredVersion = function(resource) {
var preferred = API_PREFERRED_VERSIONS[resource];
if(!preferred) {
Logger.log("No preferred version for ", resource);
}
return preferred;
};

return {
toResourceGroupVersion: toResourceGroupVersion,

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

invalidObjectKindOrVersion: invalidObjectKindOrVersion,
unsupportedObjectKindOrVersion: unsupportedObjectKindOrVersion,
availableKinds: availableKinds
availableKinds: availableKinds,
getPreferredVersion: getPreferredVersion
};
});