Skip to content
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

Service Instance Details Pages #1906

Merged
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
5 changes: 4 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ <h1>JavaScript Required</h1>
<script src="scripts/services/resourceAlerts.js"></script>
<script src="scripts/services/listRowUtils.js"></script>
<script src="scripts/services/ownerReferences.js"></script>
<script src="scripts/services/serviceInstances.js"></script>
<script src="scripts/controllers/landingPage.js"></script>
<script src="scripts/services/events.js"></script>
<script src="scripts/controllers/projects.js"></script>
Expand All @@ -248,6 +249,8 @@ <h1>JavaScript Required</h1>
<script src="scripts/controllers/statefulSet.js"></script>
<script src="scripts/controllers/services.js"></script>
<script src="scripts/controllers/service.js"></script>
<script src="scripts/controllers/serviceInstances.js"></script>
<script src="scripts/controllers/serviceInstance.js"></script>
<script src="scripts/controllers/secrets.js"></script>
<script src="scripts/controllers/secret.js"></script>
<script src="scripts/controllers/createSecret.js"></script>
Expand Down Expand Up @@ -359,6 +362,7 @@ <h1>JavaScript Required</h1>
<script src="scripts/directives/fromFileDialog.js"></script>
<script src="scripts/directives/create/nextSteps.js"></script>
<script src="scripts/directives/imageNames.js"></script>
<script src="scripts/directives/serviceBinding.js"></script>

<!-- New Overview -->
<script src="scripts/directives/buildCounts.js"></script>
Expand All @@ -371,7 +375,6 @@ <h1>JavaScript Required</h1>
<script src="scripts/directives/overview/networking.js"></script>
<script src="scripts/directives/overview/pipelines.js"></script>
<script src="scripts/directives/overview/serviceBindings.js"></script>
<script src="scripts/directives/overview/serviceBinding.js"></script>

<script src="scripts/directives/istagSelect.js"></script>
<script src="scripts/directives/deployImage.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ angular
controller: 'ServiceController',
reloadOnSearch: false
})
.when('/project/:project/browse/service-instances', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that upstream it will either be called ServiceInstance or ServiceCatalogInstance. What you have now looks good, but we might change the name to align with the final name in the upstream service catalog.

(Nothing to change right now)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up to say the name upstream will be ServiceInstance, so what you have is good 👍

templateUrl: 'views/service-instances.html',
controller: 'ServiceInstancesController',
reloadOnSearch: false
})
.when('/project/:project/browse/service-instances/:instance', {
templateUrl: 'views/browse/service-instance.html',
controller: 'ServiceInstanceController',
reloadOnSearch: false
})
.when('/project/:project/browse/storage', {
templateUrl: 'views/storage.html',
controller: 'StorageController',
Expand Down
12 changes: 12 additions & 0 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
"/create-route",
"/edit/routes/"
]
},
{
label: "Provisioned Services",
href: "/browse/service-instances",
prefixes: [
"/browse/service-instances/"
],
canI: {
resource: 'serviceinstances',
group: 'servicecatalog.k8s.io',
verb: 'list'
}
}
]
}
Expand Down
107 changes: 107 additions & 0 deletions app/scripts/controllers/serviceInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

angular.module('openshiftConsole')
.controller('ServiceInstanceController', function ($scope,
$filter,
$routeParams,
DataService,
ProjectsService,
ServiceInstancesService) {
$scope.alerts = {};
$scope.projectName = $routeParams.project;
$scope.serviceInstance = null;
$scope.serviceClass = null;
$scope.serviceClasses = null;

$scope.breadcrumbs = [
{
title: "Provisioned Services",
link: "project/" + $routeParams.project + "/browse/service-instances"
}
];

$scope.deprovision = function() {
ServiceInstancesService.deprovision($scope.serviceInstance);
};

var watches = [];

var updateBreadcrumbs = function() {
if(!$scope.serviceInstance || !$scope.serviceClasses) {
return;
}

$scope.breadcrumbs.push({
title: $filter('serviceInstanceDisplayName')($scope.serviceInstance, $scope.serviceClasses)
});
};

var updateServiceClassMetadata = function() {
if(!$scope.serviceInstance || !$scope.serviceClasses) {
return;
}

var serviceClassName = _.get($scope.serviceInstance.spec, 'serviceClassName');
$scope.serviceClass = _.get($scope.serviceClasses, [serviceClassName]);
$scope.plan = _.find(_.get($scope.serviceClass, 'plans'), {name: $scope.serviceInstance.spec.planName });
};

var serviceResolved = function(service, action) {
$scope.loaded = true;
$scope.serviceInstance = service;

if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "This provisioned service has been deleted."
};
}

updateServiceClassMetadata();
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
$scope.projectContext = context;

DataService
.get({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, $routeParams.instance, context, { errorNotification: false })
.then(function(service) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call updateBreadcrumbs here and remove it from serviceResolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially worked here... since the "crumb" display title/name is both partially dependent on serviceinstances and serviceclasses located an additional fire underneath the associated serviceclasses service call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Then let's not set the breadcrumb until both load. Then we can call it safely from both callbacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the load check, instead now checking for serviceinstances and serviceclasses. Similar to the check within updateServiceClassMetadata.

serviceResolved(service);
updateBreadcrumbs();

watches.push(DataService.watchObject({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, $routeParams.instance, context, serviceResolved));

}, function(error) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The service details could not be loaded.",
details: $filter('getErrorDetails')(error)
};
});

DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, context, function(serviceClasses) {
$scope.serviceClasses = serviceClasses.by('metadata.name');
updateServiceClassMetadata();
updateBreadcrumbs();
});

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});

}));
});
98 changes: 98 additions & 0 deletions app/scripts/controllers/serviceInstances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'use strict';

angular.module('openshiftConsole')
.controller('ServiceInstancesController', function ($scope,
$filter,
$routeParams,
APIService,
BindingService,
Constants,
DataService,
LabelFilter,
Logger,
ProjectsService) {
$scope.alerts = {};
$scope.bindingsByInstanceRef = {};
$scope.emptyMessage = "Loading...";
$scope.labelSuggestions = {};
$scope.projectName = $routeParams.project;
$scope.serviceClasses = {};
$scope.serviceInstances = {};
$scope.unfilteredServiceInstances = {};

var watches = [];

var updateFilter = function() {
$scope.serviceInstances = LabelFilter.getLabelSelector().select($scope.unfilteredServiceInstances);
};

var sortServiceInstances = function() {
$scope.unfilteredServiceInstances = BindingService.sortServiceInstances($scope.unfilteredServiceInstances, $scope.serviceClasses);
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
$scope.projectContext = context;

watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstancecredentials'
}, context, function(bindings) {
var bindingsByName = bindings.by('metadata.name');
$scope.bindingsByInstanceRef = _.groupBy(bindingsByName, 'spec.instanceRef.name');
}));

watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, context, function(serviceInstances) {
$scope.emptyMessage = "No provisioned services to show";
$scope.unfilteredServiceInstances = serviceInstances.by('metadata.name');

sortServiceInstances();
updateFilter();
updateFilterWarning();

LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredServiceInstances, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);

Logger.log("provisioned services (subscribe)", $scope.unfilteredServiceInstances);
}));

DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, context, function(serviceClasses) {
$scope.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
});

function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.serviceInstances) && !_.isEmpty($scope.unfilteredServiceInstances)) {
$scope.alerts["all-instances-filtered"] = {
type: "warning",
details: "The active filters are hiding all provisioned services."
};
}
else {
delete $scope.alerts["all-instances-filtered"];
}
}

LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$evalAsync(function() {
$scope.serviceInstances = labelSelector.select($scope.unfilteredServiceInstances);
updateFilterWarning();
});
});

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});

}));
});
65 changes: 7 additions & 58 deletions app/scripts/directives/overview/serviceInstanceRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
angular.module('openshiftConsole').component('serviceInstanceRow', {
controller: [
'$filter',
'$uibModal',
'DataService',
'AuthorizationService',
'BindingService',
'ListRowUtils',
'NotificationsService',
'AuthorizationService',
'ServiceInstancesService',
ServiceInstanceRow
],
controllerAs: 'row',
Expand All @@ -22,16 +20,13 @@
});

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

var getErrorDetails = $filter('getErrorDetails');
var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');

var getDescription = function() {
Expand Down Expand Up @@ -95,68 +90,22 @@
if (AuthorizationService.canI({resource: 'serviceinstances', group: 'servicecatalog.k8s.io'}, 'delete')) {
return true;
}

return false;
};

row.closeOverlayPanel = function() {
_.set(row, 'overlay.panelVisible', false);
};

row.showOverlayPanel = function(panelName, state) {
_.set(row, 'overlay.panelVisible', true);
_.set(row, 'overlay.panelName', panelName);
_.set(row, 'overlay.state', state);
};

row.deprovision = function() {
var modalScope = {
alerts: {
deprovision: {
type: 'error',
message: 'Service \'' + row.apiObject.spec.serviceClassName + '\' will be deleted and no longer available.'
}
},
detailsMarkup: 'Delete Service?',
okButtonText: 'Delete',
okButtonClass: 'btn-danger',
cancelButtonText: 'Cancel'
};
// TODO: we probably have to handle bindings in here.
// either:
// - automatically remove the bindings
// - tell the user they must manually unbind before continue
$uibModal.open({
animation: true,
templateUrl: 'views/modals/confirm.html',
controller: 'ConfirmModalController',
resolve: {
modalConfig: function() {
return modalScope;
}
}
})
.result.then(function() {
NotificationsService.hideNotification("deprovision-service-error");
DataService.delete({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
},
row.apiObject.metadata.name,
{ namespace: row.apiObject.metadata.namespace },
{ propagationPolicy: null }) // TODO - remove once this is resolved https://github.com/kubernetes-incubator/service-catalog/issues/942
.then(function() {
NotificationsService.addNotification({
type: "success",
message: "Successfully deleted " + row.apiObject.metadata.name + "."
});
}, function(err) {
NotificationsService.addNotification({
id: "deprovision-service-error",
type: "error",
message: "An error occurred while deleting " + row.apiObject.metadata.name + ".",
details: getErrorDetails(err)
});
});
});
ServiceInstancesService.deprovision(row.apiObject);
};
}
})();
2 changes: 1 addition & 1 deletion app/scripts/directives/resourceServiceBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ResourceServiceBindings($filter, DataService, BindingService, CatalogSe
ctrl.bindableServiceInstances = [];
ctrl.serviceClasses = [];
ctrl.serviceInstances = [];
ctrl.showBindings = CatalogService.SERVICE_CATALOG_ENABLED && enableTechPreviewFeature('pod_presets');
ctrl.showBindings = CatalogService.SERVICE_CATALOG_ENABLED && (_.get(ctrl, 'apiObject.kind') === 'ServiceInstance' || enableTechPreviewFeature('pod_presets'));

var limitWatches = $filter('isIE')() || $filter('isEdge')();
var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds
Expand Down
Loading