Skip to content

Commit 38fd844

Browse files
Add bindings list to resource pages
Add resourceServiceBindings component. Use common utility functions for bindings Add utility SERVICE_CATALOG_ENABLED to CatalogService
1 parent bba7c7f commit 38fd844

23 files changed

+938
-613
lines changed

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ <h1>JavaScript Required</h1>
326326
<script src="scripts/directives/oscSourceSecrets.js"></script>
327327
<script src="scripts/directives/replicas.js"></script>
328328
<script src="scripts/directives/resources.js"></script>
329+
<script src="scripts/directives/resourceServiceBindings.js"></script>
329330
<script src="scripts/directives/nav.js"></script>
330331
<script src="scripts/directives/alerts.js"></script>
331332
<script src="scripts/directives/parseError.js"></script>

app/scripts/controllers/overview.js

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
88
'APIService',
99
'AppsService',
1010
'BuildsService',
11+
'CatalogService',
1112
'Constants',
1213
'DataService',
1314
'DeploymentsService',
@@ -19,7 +20,6 @@ angular.module('openshiftConsole').controller('OverviewController', [
1920
'Logger',
2021
'MetricsService',
2122
'Navigate',
22-
'NotificationsService',
2323
'OwnerReferencesService',
2424
'PodsService',
2525
'ProjectsService',
@@ -36,6 +36,7 @@ function OverviewController($scope,
3636
APIService,
3737
AppsService,
3838
BuildsService,
39+
CatalogService,
3940
Constants,
4041
DataService,
4142
DeploymentsService,
@@ -47,7 +48,6 @@ function OverviewController($scope,
4748
Logger,
4849
MetricsService,
4950
Navigate,
50-
NotificationsService,
5151
OwnerReferencesService,
5252
PodsService,
5353
ProjectsService,
@@ -58,14 +58,6 @@ function OverviewController($scope,
5858
var limitWatches = $filter('isIE')() || $filter('isEdge')();
5959
var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds
6060

61-
// Enable service catalog features if the new experience is enabled and the
62-
// servicecatalog.k8s.io resources are available.
63-
var SERVICE_CATALOG_ENABLED =
64-
_.get(Constants, 'ENABLE_TECH_PREVIEW_FEATURE.service_catalog_landing_page') &&
65-
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'serviceclasses' }) &&
66-
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'instances' }) &&
67-
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'bindings' });
68-
6961
$scope.projectName = $routeParams.project;
7062

7163
// Filters used by this controller.
@@ -1089,12 +1081,6 @@ function OverviewController($scope,
10891081

10901082
overview.startBuild = BuildsService.startBuild;
10911083

1092-
var refreshSecrets = _.debounce(function(context) {
1093-
DataService.list("secrets", context, null, { errorNotification: false }).then(function(secretData) {
1094-
state.secrets = secretData.by("metadata.name");
1095-
});
1096-
}, 300);
1097-
10981084
var groupBindings = function() {
10991085
// Build two maps:
11001086
// - Bindings by the UID of the target object
@@ -1123,13 +1109,7 @@ function OverviewController($scope,
11231109
}
11241110

11251111
// Build a map of pod preset selectors by binding name.
1126-
var podPresetSelectors = {};
1127-
_.each(state.bindings, function(binding) {
1128-
var podPresetSelector = _.get(binding, 'spec.alphaPodPresetTemplate.selector');
1129-
if (podPresetSelector) {
1130-
podPresetSelectors[binding.metadata.name] = new LabelSelector(podPresetSelector);
1131-
}
1132-
});
1112+
var podPresetSelectors = BindingService.getPodPresetSelectorsForBindings(state.bindings);
11331113

11341114
_.each(objectsByKind, function(collection) {
11351115
_.each(collection, function(apiObject) {
@@ -1169,26 +1149,9 @@ function OverviewController($scope,
11691149
}, {});
11701150
};
11711151

1172-
// TODO: code duplicated from directives/bindService.js
1173-
// extract & share
11741152
var sortServiceInstances = function() {
1175-
if(!state.serviceInstances && !state.serviceClasses) {
1176-
state.bindableServiceInstances = null;
1177-
return;
1178-
}
1179-
1180-
state.bindableServiceInstances = _.filter(state.serviceInstances, function(serviceInstance) {
1181-
return BindingService.isServiceBindable(serviceInstance, state.serviceClasses);
1182-
});
1183-
1184-
state.orderedServiceInstances = _.sortBy(state.serviceInstances,
1185-
function(item) {
1186-
return _.get(state.serviceClasses, [item.spec.serviceClassName, 'externalMetadata', 'displayName']) || item.spec.serviceClassName;
1187-
},
1188-
function(item) {
1189-
return _.get(item, 'metadata.name', '');
1190-
}
1191-
);
1153+
state.bindableServiceInstances = BindingService.filterBindableServiceInstances(state.serviceInstances, state.serviceClasses);
1154+
state.orderedServiceInstances = BindingService.sortServiceInstances(state.serviceInstances, state.serviceClasses);
11921155
};
11931156

11941157
var watches = [];
@@ -1351,7 +1314,7 @@ function OverviewController($scope,
13511314

13521315
var canI = $filter('canI');
13531316
// The canI check on watch should be temporary until we have a different solution for handling secret parameters
1354-
if (SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
1317+
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
13551318
watches.push(DataService.watch({
13561319
group: 'servicecatalog.k8s.io',
13571320
resource: 'instances'
@@ -1367,15 +1330,14 @@ function OverviewController($scope,
13671330
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
13681331
}
13691332

1370-
if (SERVICE_CATALOG_ENABLED && canI({resource: 'bindings', group: 'servicecatalog.k8s.io'}, 'watch')) {
1333+
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'bindings', group: 'servicecatalog.k8s.io'}, 'watch')) {
13711334
watches.push(DataService.watch({
13721335
group: 'servicecatalog.k8s.io',
13731336
resource: 'bindings'
13741337
}, context, function(bindings) {
13751338
state.bindings = bindings.by('metadata.name');
13761339
overview.bindingsByInstanceRef = _.groupBy(state.bindings, 'spec.instanceRef.name');
13771340
groupBindings();
1378-
refreshSecrets(context);
13791341
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
13801342
}
13811343

@@ -1385,7 +1347,7 @@ function OverviewController($scope,
13851347
state.limitRanges = response.by("metadata.name");
13861348
});
13871349

1388-
if (SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
1350+
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
13891351
// TODO: update to behave like ImageStreamResolver
13901352
// - we may not even need to list these... perhaps just fetch the ones we need when needed
13911353
// If we can't watch instances don't bother getting service classes either

app/scripts/directives/bindService.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@
4545
var sortServiceInstances = function() {
4646
// wait till both service instances and service classes are available so that the sort is stable and items dont jump around
4747
if (ctrl.serviceClasses && ctrl.serviceInstances) {
48-
ctrl.orderedServiceInstances = _.sortBy(ctrl.serviceInstances,
49-
function(item) {
50-
return _.get(ctrl.serviceClasses, [item.spec.serviceClassName, 'externalMetadata', 'displayName']) || item.spec.serviceClassName;
51-
},
52-
function(item) {
53-
return _.get(item, 'metadata.name', '');
54-
}
55-
);
48+
ctrl.serviceInstances = BindingService.filterBindableServiceInstances(ctrl.serviceInstances, ctrl.serviceClasses);
49+
ctrl.orderedServiceInstances = BindingService.sortServiceInstances(ctrl.serviceInstances, ctrl.serviceClasses);
50+
51+
if (!ctrl.serviceToBind) {
52+
preselectService();
53+
}
5654
}
5755
};
5856

@@ -137,9 +135,6 @@
137135
resource: 'instances'
138136
}, context).then(function(instances) {
139137
ctrl.serviceInstances = instances.by('metadata.name');
140-
if (!ctrl.serviceToBind) {
141-
preselectService();
142-
}
143138
sortServiceInstances();
144139
});
145140
};

app/scripts/directives/deleteLink.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ angular.module("openshiftConsole")
6767
};
6868

6969
var showAlert = function(alert) {
70-
if (scope.stayOnCurrentPage) {
70+
if (scope.stayOnCurrentPage && scope.alerts) {
7171
scope.alerts[alert.name] = alert.data;
7272
} else {
7373
NotificationsService.addNotification(alert.data);
@@ -177,11 +177,14 @@ angular.module("openshiftConsole")
177177
})
178178
.catch(function(err) {
179179
// called if failure to delete
180-
scope.alerts[resourceName] = {
181-
type: "error",
182-
message: _.capitalize(formattedResource) + "\'" + " could not be deleted.",
183-
details: $filter('getErrorDetails')(err)
184-
};
180+
showAlert({
181+
name: resourceName,
182+
data: {
183+
type: "error",
184+
message: _.capitalize(formattedResource) + "\'" + " could not be deleted.",
185+
details: $filter('getErrorDetails')(err)
186+
}
187+
});
185188
Logger.error(formattedResource + " could not be deleted.", err);
186189
});
187190
});

app/scripts/directives/overview/listRow.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'$uibModal',
88
'APIService',
99
'BuildsService',
10+
'CatalogService',
1011
'DeploymentsService',
1112
'ListRowUtils',
1213
'Navigate',
@@ -29,6 +30,7 @@
2930
$uibModal,
3031
APIService,
3132
BuildsService,
33+
CatalogService,
3234
DeploymentsService,
3335
ListRowUtils,
3436
Navigate,
@@ -94,6 +96,8 @@
9496
return _.get(row.state.hpaByResource, [kind, name], NO_HPA);
9597
};
9698

99+
row.showBindings = CatalogService.SERVICE_CATALOG_ENABLED && enableTechPreviewFeature('pod_presets');
100+
97101
row.$doCheck = function() {
98102
// Update notifications.
99103
row.notifications = ListRowUtils.getNotifications(row.apiObject, row.state);

app/scripts/directives/overview/serviceBinding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
],
88
controllerAs: '$ctrl',
99
bindings: {
10+
namespace: '<',
1011
binding: '<',
1112
serviceClasses: '<',
12-
serviceInstances: '<',
13-
secrets: '<'
13+
serviceInstances: '<'
1414
},
1515
templateUrl: 'views/overview/_service-binding.html'
1616
});

app/scripts/directives/overview/serviceBindings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
angular.module('openshiftConsole').component('overviewServiceBindings', {
44
controllerAs: '$ctrl',
55
bindings: {
6+
namespace: '<',
67
bindings: '<',
78
bindableServiceInstances: '<',
89
serviceClasses: '<',
910
serviceInstances: '<',
10-
secrets: '<',
1111
createBinding: '&'
1212
},
1313
templateUrl: 'views/overview/_service-bindings.html'
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
'use strict';
2+
3+
angular.module('openshiftConsole').component('resourceServiceBindings', {
4+
controller: [
5+
'$filter',
6+
'DataService',
7+
'BindingService',
8+
'CatalogService',
9+
ResourceServiceBindings
10+
],
11+
controllerAs: '$ctrl',
12+
bindings: {
13+
project: '<',
14+
projectContext: '<',
15+
apiObject: '<',
16+
createBinding: '&'
17+
},
18+
templateUrl: 'views/directives/resource-service-bindings.html'
19+
});
20+
21+
22+
function ResourceServiceBindings($filter, DataService, BindingService, CatalogService) {
23+
var ctrl = this;
24+
var enableTechPreviewFeature = $filter('enableTechPreviewFeature');
25+
26+
ctrl.bindings = [];
27+
ctrl.bindableServiceInstances = [];
28+
ctrl.serviceClasses = [];
29+
ctrl.serviceInstances = [];
30+
ctrl.showBindings = CatalogService.SERVICE_CATALOG_ENABLED && enableTechPreviewFeature('pod_presets');
31+
32+
var limitWatches = $filter('isIE')() || $filter('isEdge')();
33+
var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds
34+
var watches = [];
35+
var canI = $filter('canI');
36+
37+
var updateBindings = function() {
38+
if (!ctrl.apiObject || !ctrl.bindings) {
39+
return;
40+
}
41+
42+
// Get only those bindings applicable to the resource
43+
ctrl.bindings = BindingService.getBindingsForResource(ctrl.bindings, ctrl.apiObject);
44+
};
45+
46+
var sortServiceInstances = function() {
47+
ctrl.bindableServiceInstances = BindingService.filterBindableServiceInstances(ctrl.serviceInstances, ctrl.serviceClasses);
48+
ctrl.orderedServiceInstances = BindingService.sortServiceInstances(ctrl.serviceInstances, ctrl.serviceClasses);
49+
};
50+
51+
ctrl.createBinding = function() {
52+
ctrl.overlayPanelVisible = true;
53+
ctrl.overlayPanelName = 'bindService';
54+
};
55+
56+
ctrl.closeOverlayPanel = function() {
57+
ctrl.overlayPanelVisible = false;
58+
};
59+
60+
var updateData = function() {
61+
DataService.unwatchAll(watches);
62+
watches = [];
63+
64+
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'bindings', group: 'servicecatalog.k8s.io'}, 'watch')) {
65+
watches.push(DataService.watch({
66+
group: 'servicecatalog.k8s.io',
67+
resource: 'bindings'
68+
}, ctrl.projectContext, function(bindings) {
69+
ctrl.bindings = bindings.by('metadata.name');
70+
updateBindings();
71+
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
72+
}
73+
74+
// The canI check on watch should be temporary until we have a different solution for handling secret parameters
75+
if (CatalogService.SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
76+
watches.push(DataService.watch({
77+
group: 'servicecatalog.k8s.io',
78+
resource: 'instances'
79+
}, ctrl.projectContext, function(serviceInstances) {
80+
ctrl.serviceInstances = serviceInstances.by('metadata.name');
81+
sortServiceInstances();
82+
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
83+
84+
// If we can't watch instances don't bother getting service classes either
85+
DataService.list({
86+
group: 'servicecatalog.k8s.io',
87+
resource: 'serviceclasses'
88+
}, ctrl.projectContext, function(serviceClasses) {
89+
ctrl.serviceClasses = serviceClasses.by('metadata.name');
90+
sortServiceInstances();
91+
});
92+
}
93+
};
94+
95+
ctrl.$onChanges = function(onChangesObj) {
96+
if (onChangesObj.projectContext && ctrl.showBindings) {
97+
updateData();
98+
}
99+
};
100+
101+
ctrl.$onDestroy = function() {
102+
DataService.unwatchAll(watches);
103+
};
104+
}

app/scripts/services/catalog.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
angular.module("openshiftConsole")
44
.factory("CatalogService", function($filter,
5+
APIService,
56
Constants,
67
KeywordService) {
78
var getTags = $filter('tags');
89

10+
// Enable service catalog features if the new experience is enabled and the
11+
// servicecatalog.k8s.io resources are available.
12+
var SERVICE_CATALOG_ENABLED =
13+
_.get(Constants, 'ENABLE_TECH_PREVIEW_FEATURE.service_catalog_landing_page') &&
14+
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'serviceclasses' }) &&
15+
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'instances' }) &&
16+
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'bindings' });
17+
918
var categoryItemByID = {};
1019
_.each(Constants.CATALOG_CATEGORIES, function(category) {
1120
_.each(category.items, function(categoryItem) {
@@ -239,6 +248,7 @@ angular.module("openshiftConsole")
239248
};
240249

241250
return {
251+
SERVICE_CATALOG_ENABLED: SERVICE_CATALOG_ENABLED,
242252
getCategoryItem: getCategoryItem,
243253
categorizeImageStreams: categorizeImageStreams,
244254
categorizeTemplates: categorizeTemplates,

0 commit comments

Comments
 (0)