From 1056510a87db015a80b67bdcec08d2c6d803beea Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Date: Mon, 25 Sep 2017 12:54:23 -0400 Subject: [PATCH] Delete bindings when deleting a service instance --- .../directives/overview/serviceInstanceRow.js | 2 +- app/scripts/services/serviceInstances.js | 136 ++++++++++++------ app/views/directives/_service-binding.html | 2 +- .../directives/resource-service-bindings.html | 8 +- app/views/modals/delete-resource.html | 4 + app/views/overview/_service-bindings.html | 4 +- dist/scripts/scripts.js | 101 ++++++++----- dist/scripts/templates.js | 17 ++- 8 files changed, 184 insertions(+), 90 deletions(-) diff --git a/app/scripts/directives/overview/serviceInstanceRow.js b/app/scripts/directives/overview/serviceInstanceRow.js index 477c0f94f8..61f837491f 100644 --- a/app/scripts/directives/overview/serviceInstanceRow.js +++ b/app/scripts/directives/overview/serviceInstanceRow.js @@ -101,7 +101,7 @@ }; row.deprovision = function() { - ServiceInstancesService.deprovision(row.apiObject); + ServiceInstancesService.deprovision(row.apiObject, row.deleteableBindings); }; } })(); diff --git a/app/scripts/services/serviceInstances.js b/app/scripts/services/serviceInstances.js index d95f57fd39..767315f970 100644 --- a/app/scripts/services/serviceInstances.js +++ b/app/scripts/services/serviceInstances.js @@ -2,65 +2,117 @@ angular.module("openshiftConsole") .factory("ServiceInstancesService", function($filter, + $q, $uibModal, + APIService, + BindingService, + CatalogService, DataService, + Logger, NotificationsService) { + var getBindingsIfNecessary = function(apiObject, bindings) { + if (angular.isDefined(bindings)) { + return $q.when(bindings); + } - function deprovision(apiObject) { - var getErrorDetails = $filter('getErrorDetails'); - var modalScope = { - alerts: { - deprovision: { - type: 'error', - message: 'Service \'' + apiObject.spec.serviceClassName + '\' will be deleted and no longer available.' + var context = {namespace: apiObject.metadata.namespace}; + var resource = APIService.getPreferredVersion('serviceinstancecredentials'); + + return DataService.list(resource, context).then(function(serviceBindings) { + bindings = serviceBindings.by('metadata.name'); + return BindingService.getBindingsForResource(bindings, apiObject); + }); + }; + + var deprovisionInstance = function(apiObject) { + var context = {namespace: apiObject.metadata.namespace}; + var resource = APIService.getPreferredVersion('serviceinstances'); + + NotificationsService.hideNotification("deprovision-service-error"); + + // TODO - remove once this is resolved https://github.com/kubernetes-incubator/service-catalog/issues/942 + var opts = { + propagationPolicy: null + }; + + return DataService.delete(resource, apiObject.metadata.name, context, opts).then(function() { + NotificationsService.addNotification({ + type: "success", + message: "Provisioned service '" + apiObject.metadata.name + "' was marked for deletion." + }); + }, function(err) { + NotificationsService.addNotification({ + id: "deprovision-service-error", + type: "error", + message: "An error occurred while deleting provisioned service " + apiObject.metadata.name + ".", + details: $filter('getErrorDetails')(err) + }); + Logger("An error occurred while deleting provisioned service " + apiObject.metadata.name + ".", err); + }); + }; + + var deprovisionBindings = function(apiObject, bindings) { + if (!CatalogService.SERVICE_CATALOG_ENABLED) { + return; + } + + var context = {namespace: apiObject.metadata.namespace}; + var resource = APIService.getPreferredVersion('serviceinstancecredentials'); + getBindingsIfNecessary(apiObject, bindings).then(function(serviceBindings) { + _.each(serviceBindings, function (binding) { + if (!binding.metadata.deletionTimestamp) { + return; } - }, - detailsMarkup: 'Delete Service?', + + DataService.delete(resource, binding.metadata.name, context) + .then(function () { + NotificationsService.addNotification({ + type: "success", + message: 'Binding ' + binding.metadata.name + "' was marked for deletion." + }); + }) + .catch(function (err) { + NotificationsService.addNotification({ + type: "error", + message: 'Binding ' + binding.metadata.name + "' could not be deleted.", + details: $filter('getErrorDetails')(err) + }); + Logger.error('Binding ' + binding.metadata.name + "' could not be deleted.", err); + }); + }); + }); + }; + + var deprovision = function (apiObject, bindings) { + var modalInstance; + + var modalScope = { + kind: apiObject.kind, + displayName: apiObject.metadata.name, okButtonText: 'Delete', okButtonClass: 'btn-danger', - cancelButtonText: 'Cancel' + cancelButtonText: 'Cancel', + delete: function() { + modalInstance.close('delete'); + } }; - // TODO: we probably have to handle bindings in here. - // either: - // - automatically remove the bindings - // - tell the user they must manually unbind before continue - return $uibModal.open({ + modalInstance = $uibModal.open({ animation: true, - templateUrl: 'views/modals/confirm.html', + templateUrl: 'views/modals/delete-resource.html', controller: 'ConfirmModalController', resolve: { modalConfig: function() { return modalScope; } } - }) - .result.then(function() { - NotificationsService.hideNotification("deprovision-service-error"); - - return DataService.delete({ - group: 'servicecatalog.k8s.io', - resource: 'serviceinstances' - }, - apiObject.metadata.name, - { namespace: 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 provisioned service " + apiObject.metadata.name + "." - }); - }, function(err) { - NotificationsService.addNotification({ - id: "deprovision-service-error", - type: "error", - message: "An error occurred while deleting provisioned service " + apiObject.metadata.name + ".", - details: getErrorDetails(err) - }); - }); }); - } + + return modalInstance.result.then(function() { + deprovisionBindings(apiObject, bindings); + deprovisionInstance(apiObject); + }); + }; return { deprovision: deprovision diff --git a/app/views/directives/_service-binding.html b/app/views/directives/_service-binding.html index 4ed8ee2312..b9ab1e89f9 100644 --- a/app/views/directives/_service-binding.html +++ b/app/views/directives/_service-binding.html @@ -36,7 +36,7 @@

Pending -
+
Bindings

service-classes="$ctrl.serviceClasses" service-instances="$ctrl.serviceInstances"> -
+
Create Binding
-
+
You must have a bindable service in your namespace in order to create bindings.
Browse Catalog
-
+
There are no service bindings.
diff --git a/app/views/modals/delete-resource.html b/app/views/modals/delete-resource.html index b1a1d1e723..8c2646a470 100644 --- a/app/views/modals/delete-resource.html +++ b/app/views/modals/delete-resource.html @@ -18,6 +18,10 @@

Are you sure you want to delete the {{typeDisplayName || (kind | humanizeKin This will delete the {{typeDisplayName || (kind | humanizeKind)}} and any running pods. + + {{displayName ? displayName : resourceName}} and its data will no longer be available to your applications. + + This will delete all resources associated with the project {{displayName ? displayName : resourceName}}. diff --git a/app/views/overview/_service-bindings.html b/app/views/overview/_service-bindings.html index 14ff4a4459..33bb292963 100644 --- a/app/views/overview/_service-bindings.html +++ b/app/views/overview/_service-bindings.html @@ -10,13 +10,13 @@ service-instances="$ctrl.serviceInstances" secrets="$ctrl.secrets"> -
+ -
+
You must have a bindable service in your namespace in order to create bindings.
Browse Catalog diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index b2717105b9..0ac07eb3ec 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -4278,51 +4278,82 @@ controller: !0 }); } }; -}), angular.module("openshiftConsole").factory("ServiceInstancesService", [ "$filter", "$uibModal", "DataService", "NotificationsService", function(e, t, n, a) { -return { -deprovision: function(r) { -var o = e("getErrorDetails"), i = { -alerts: { -deprovision: { +}), angular.module("openshiftConsole").factory("ServiceInstancesService", [ "$filter", "$q", "$uibModal", "APIService", "BindingService", "CatalogService", "DataService", "Logger", "NotificationsService", function(e, t, n, a, r, o, i, s, c) { +var l = function(e, n) { +if (angular.isDefined(n)) return t.when(n); +var o = { +namespace: e.metadata.namespace +}, s = a.getPreferredVersion("serviceinstancecredentials"); +return i.list(s, o).then(function(t) { +return n = t.by("metadata.name"), r.getBindingsForResource(n, e); +}); +}, u = function(t) { +var n = { +namespace: t.metadata.namespace +}, r = a.getPreferredVersion("serviceinstances"); +c.hideNotification("deprovision-service-error"); +var o = { +propagationPolicy: null +}; +return i.delete(r, t.metadata.name, n, o).then(function() { +c.addNotification({ +type: "success", +message: "Provisioned service '" + t.metadata.name + "' was marked for deletion." +}); +}, function(n) { +c.addNotification({ +id: "deprovision-service-error", +type: "error", +message: "An error occurred while deleting provisioned service " + t.metadata.name + ".", +details: e("getErrorDetails")(n) +}), s("An error occurred while deleting provisioned service " + t.metadata.name + ".", n); +}); +}, d = function(t, n) { +if (o.SERVICE_CATALOG_ENABLED) { +var r = { +namespace: t.metadata.namespace +}, u = a.getPreferredVersion("serviceinstancecredentials"); +l(t, n).then(function(t) { +_.each(t, function(t) { +t.metadata.deletionTimestamp && i.delete(u, t.metadata.name, r).then(function() { +c.addNotification({ +type: "success", +message: "Binding " + t.metadata.name + "' was marked for deletion." +}); +}).catch(function(n) { +c.addNotification({ type: "error", -message: "Service '" + r.spec.serviceClassName + "' will be deleted and no longer available." +message: "Binding " + t.metadata.name + "' could not be deleted.", +details: e("getErrorDetails")(n) +}), s.error("Binding " + t.metadata.name + "' could not be deleted.", n); +}); +}); +}); } -}, -detailsMarkup: "Delete Service?", +}; +return { +deprovision: function(e, t) { +var a, r = { +kind: e.kind, +displayName: e.metadata.name, okButtonText: "Delete", okButtonClass: "btn-danger", -cancelButtonText: "Cancel" +cancelButtonText: "Cancel", +delete: function() { +a.close("delete"); +} }; -return t.open({ +return (a = n.open({ animation: !0, -templateUrl: "views/modals/confirm.html", +templateUrl: "views/modals/delete-resource.html", controller: "ConfirmModalController", resolve: { modalConfig: function() { -return i; +return r; } } -}).result.then(function() { -return a.hideNotification("deprovision-service-error"), n.delete({ -group: "servicecatalog.k8s.io", -resource: "serviceinstances" -}, r.metadata.name, { -namespace: r.metadata.namespace -}, { -propagationPolicy: null -}).then(function() { -a.addNotification({ -type: "success", -message: "Successfully deleted provisioned service " + r.metadata.name + "." -}); -}, function(e) { -a.addNotification({ -id: "deprovision-service-error", -type: "error", -message: "An error occurred while deleting provisioned service " + r.metadata.name + ".", -details: o(e) -}); -}); +})).result.then(function() { +d(e, t), u(e); }); } }; @@ -13566,7 +13597,7 @@ _.set(o, "overlay.panelVisible", !1); }, o.showOverlayPanel = function(e, t) { _.set(o, "overlay.panelVisible", !0), _.set(o, "overlay.panelName", e), _.set(o, "overlay.state", t); }, o.deprovision = function() { -r.deprovision(o.apiObject); +r.deprovision(o.apiObject, o.deleteableBindings); }; } ], controllerAs: "row", diff --git a/dist/scripts/templates.js b/dist/scripts/templates.js index d1c2ccc24f..1370ea6de7 100644 --- a/dist/scripts/templates.js +++ b/dist/scripts/templates.js @@ -5637,7 +5637,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "Pending\n" + "
\n" + "
\n" + - "
\n" + + "
\n" + "\n" + "\n" + "\n" + @@ -8971,19 +8971,21 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "

Bindings

\n" + "\n" + "\n" + - "
\n" + + "\n" + - "
\n" + + "
\n" + "You must have a bindable service in your namespace in order to create bindings.\n" + "
\n" + "Browse Catalog\n" + "
\n" + "
\n" + - "
\n" + + "
\n" + "There are no service bindings.\n" + "
\n" + "
\n" + @@ -10805,6 +10807,9 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "This will delete the {{typeDisplayName || (kind | humanizeKind)}} and any running pods.\n" + "\n" + + "\n" + + "{{displayName ? displayName : resourceName}} and its data will no longer be available to your applications.\n" + + "\n" + "\n" + "This will delete all resources associated with the project {{displayName ? displayName : resourceName}}.\n" + "\n" + @@ -12262,13 +12267,13 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "
{{$ctrl.sectionTitle}}
\n" + "\n" + "\n" + - "
\n" + + "\n" + - "
\n" + + "
\n" + "You must have a bindable service in your namespace in order to create bindings.\n" + "
\n" + "Browse Catalog\n" +