Skip to content

Commit

Permalink
Check services for bindability before creating bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Jun 5, 2017
1 parent b70413b commit 86d6688
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 357 deletions.
11 changes: 10 additions & 1 deletion app/scripts/controllers/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
'OwnerReferencesService',
'PodsService',
'ProjectsService',
'BindingService',
'ResourceAlertsService',
'RoutesService',
OverviewController
Expand All @@ -48,6 +49,7 @@ function OverviewController($scope,
OwnerReferencesService,
PodsService,
ProjectsService,
BindingService,
ResourceAlertsService,
RoutesService) {
var overview = this;
Expand Down Expand Up @@ -1110,9 +1112,16 @@ function OverviewController($scope,
// extract & share
var sortServiceInstances = function() {
if(!state.serviceInstances && !state.serviceClasses) {
state.bindableServiceInstances = null;
return;
}
state.orderedServiceInstances = _.toArray(state.serviceInstances).sort(function(left, right) {

var serviceInstancesArray = _.toArray(state.serviceInstances);
state.bindableServiceInstances = _.filter(serviceInstancesArray, function(serviceInstance) {
return BindingService.isServiceBindable(serviceInstance, state.serviceClasses);
});

state.orderedServiceInstances = serviceInstancesArray.sort(function(left, right) {
var leftName = _.get(state.serviceClasses, [left.spec.serviceClassName, 'osbMetadata', 'displayName']) || left.spec.serviceClassName;
var rightName = _.get(state.serviceClasses, [left.spec.serviceClassName, 'osbMetadata', 'displayName']) || right.spec.serviceClassName;

Expand Down
9 changes: 6 additions & 3 deletions app/scripts/directives/bindService.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function BindService($scope,
.concat(replicaSets)
.concat(statefulSets);
ctrl.applications = _.sortByAll(apiObjects, ['metadata.name', 'kind']);
ctrl.bindType = ctrl.applications.length ? "application" : "secret-only";
}
};

Expand Down Expand Up @@ -132,7 +133,7 @@ function BindService($scope,

// TODO is it ever realistically possible for target to not be defined at this point
if (ctrl.target.kind === 'Instance') {
ctrl.shouldBindToApp = "true";
ctrl.bindType = "secret-only";
ctrl.appToBind = null;
ctrl.serviceToBind = ctrl.target.metadata.name;
// Load all the "application" types
Expand Down Expand Up @@ -167,6 +168,8 @@ function BindService($scope,
});
}
else {
ctrl.bindType = 'application';
ctrl.appToBind = ctrl.target;
DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'instances'
Expand Down Expand Up @@ -194,13 +197,13 @@ function BindService($scope,

ctrl.bindService = function() {
var svcToBind = ctrl.target.kind === 'Instance' ? ctrl.target : ctrl.serviceInstances[ctrl.serviceToBind];
var appToBind = ctrl.target.kind !== 'Instance' ? ctrl.target : ctrl.appToBind;
var application = ctrl.bindType === 'application' ? _.get(ctrl.appToBind, 'metadata.name') : undefined;

var context = {
namespace: _.get(svcToBind, 'metadata.namespace')
};

BindingService.bindService(context, _.get(svcToBind, 'metadata.name'), _.get(appToBind, 'metadata.name')).then(function(binding){
BindingService.bindService(context, _.get(svcToBind, 'metadata.name'), application).then(function(binding){
ctrl.binding = binding;
ctrl.error = null;

Expand Down
5 changes: 4 additions & 1 deletion app/scripts/directives/overview/serviceInstanceRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ angular.module('openshiftConsole').component('serviceInstanceRow', {
controller: [
'$filter',
'DataService',
'BindingService',
'ListRowUtils',
'$uibModal',
ServiceInstanceRow
Expand All @@ -17,7 +18,7 @@ angular.module('openshiftConsole').component('serviceInstanceRow', {
templateUrl: 'views/overview/_service-instance-row.html'
});

function ServiceInstanceRow($filter, DataService, rowMethods, $uibModal) {
function ServiceInstanceRow($filter, DataService, BindingService, rowMethods, $uibModal) {
var row = this;
_.extend(row, rowMethods.ui);

Expand Down Expand Up @@ -45,6 +46,8 @@ function ServiceInstanceRow($filter, DataService, rowMethods, $uibModal) {
return binding && _.get(row, ['state', 'secrets', binding.spec.secretName]);
};

row.isBindable = BindingService.isServiceBindable(row.apiObject, row.state.serviceClasses);

row.closeOverlayPanel = function() {
_.set(row, 'overlay.panelVisible', false);
};
Expand Down
13 changes: 0 additions & 13 deletions app/scripts/filters/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,17 +1310,4 @@ angular.module('openshiftConsole')
var alternateBackends = _.get(route, 'spec.alternateBackends', []);
return !_.isEmpty(alternateBackends);
};
})
// TODO: these two filters are defined in origin-web-catalog but are not available, need to figure out why or move to common
.filter('applicationHasDeployment', function ($filter) {
var annotation = $filter('annotation');
return function (replicaSet) {
return annotation(replicaSet, 'deployment.kubernetes.io/revision');
};
})
.filter('applicationHasDeploymentConfig', function($filter) {
var annotationFilter = $filter('annotation');
return function (deployment) {
return annotationFilter(deployment, 'deploymentConfig');
};
});
5 changes: 2 additions & 3 deletions app/views/directives/bind-service/bind-service-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
service-class-name="ctrl.serviceClassName"
form-name="ctrl.selectionForm"
applications="ctrl.applications"
app-to-bind="ctrl.appToBind"
should-bind-to-app="ctrl.shouldBindToApp"
group-by-kind="ctrl.groupByKind">
bind-type="ctrl.bindType"
app-to-bind="ctrl.appToBind">
</bind-service-form>
</div>
1 change: 1 addition & 0 deletions app/views/directives/bind-service/results.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<bind-results error="ctrl.error"
binding="ctrl.binding"
service-to-bind="ctrl.serviceToBind"
bind-type="{{ctrl.bindType}}"
application-to-bind="ctrl.appToBind.metadata.name"
generated-secret-name="ctrl.generatedSecretName"
show-pod-presets="'pod_presets' | enableTechPreviewFeature"
Expand Down
2 changes: 1 addition & 1 deletion app/views/overview/_list-row-actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</li>
<!-- FIXME: Can't enable canI checks on svc cat resources until we have aggregation
<li ng-if="(row.state.serviceInstances | hashSize) > 0 && {resource: 'bindings', group: 'servicecatalog.k8s.io'} | canI : 'create'" role="menuitem"> -->
<li ng-if="('pod_presets' | enableTechPreviewFeature) && (row.state.serviceInstances | hashSize) > 0" role="menuitem">
<li ng-if="('pod_presets' | enableTechPreviewFeature) && row.state.bindableServiceInstances.length" role="menuitem">
<a href="" ng-click="row.showOverlayPanel('bindService', {target: row.apiObject})">Create Binding</a>
</li>
<li ng-if="row.current && ('deploymentconfigs/log' | canI : 'get')" role="menuitem">
Expand Down
8 changes: 4 additions & 4 deletions app/views/overview/_service-instance-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h3>
<div class="list-pf-details">
<div ng-if="!row.expanded">
<div class="hidden-xs hidden-sm">
<span ng-if="!row.bindings.length">
<span ng-if="!row.bindings.length && row.isBindable">
<a href="" ng-click="row.showOverlayPanel('bindService', {target: row.apiObject})">Create Binding</a>
</span>
<span ng-if="row.bindings.length" class="component-label">Bindings</span>
Expand Down Expand Up @@ -44,7 +44,7 @@ <h3>
uib-dropdown-toggle
class="actions-dropdown-kebab"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
<ul class="dropdown-menu dropdown-menu-right" uib-dropdown-menu role="menu">
<li role="menuitem">
<li role="menuitem" ng-if="row.isBindable">
<a href="" ng-click="row.showOverlayPanel('bindService', {target: row.apiObject})">Create Binding</a>
</li>
<li role="menuitem">
Expand Down Expand Up @@ -84,7 +84,7 @@ <h3>
<p class="pre-wrap" ng-bind-html="row.description | linky"></p>
</div>
</div>
<div class="section-title">
<div class="section-title" ng-if="row.isBindable || row.bindings">
Bindings
</div>
<div
Expand All @@ -108,7 +108,7 @@ <h3>
</a>
</div>
</div>
<div class="row">
<div class="row" ng-if="row.isBindable">
<div class="col-sm-12">
<a href="" ng-click="row.showOverlayPanel('bindService', {target: row.apiObject})">Create Binding</a>
</div>
Expand Down
Loading

0 comments on commit 86d6688

Please sign in to comment.