From eb19bc279310f84d0f2b719afc7abe1981e056e8 Mon Sep 17 00:00:00 2001 From: benjaminapetersen Date: Mon, 25 Sep 2017 13:33:17 -0400 Subject: [PATCH] Update CreatePersistentVolumeClaimController to use getPreferredVersion --- .../createPersistentVolumeClaim.js | 39 ++++++++-------- dist/scripts/scripts.js | 44 +++++++++---------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/app/scripts/controllers/createPersistentVolumeClaim.js b/app/scripts/controllers/createPersistentVolumeClaim.js index 1f3246d6cc..e0a916a800 100644 --- a/app/scripts/controllers/createPersistentVolumeClaim.js +++ b/app/scripts/controllers/createPersistentVolumeClaim.js @@ -13,6 +13,7 @@ angular.module('openshiftConsole') $routeParams, $scope, $window, + APIService, ApplicationGenerator, AuthorizationService, DataService, @@ -34,6 +35,22 @@ angular.module('openshiftConsole') } ]; + var pvcTemplate = { + kind: "PersistentVolumeClaim", + apiVersion: "v1", + metadata: { + name: undefined, + labels: {}, + annotations: {} + }, + spec: { + resources: { + requests:{} + } + } + }; + var createPVCVersion = APIService.objectToResourceGroupVersion(pvcTemplate); + var hideErrorNotifications = function() { NotificationsService.hideNotification("create-pvc-error"); }; @@ -48,8 +65,7 @@ angular.module('openshiftConsole') .get($routeParams.project) .then(_.spread(function(project, context) { $scope.project = project; - - if (!AuthorizationService.canI('persistentvolumeclaims', 'create', $routeParams.project)) { + if (!AuthorizationService.canI(createPVCVersion, 'create', $routeParams.project)) { Navigate.toErrorPage('You do not have authority to create persistent volume claims in project ' + $routeParams.project + '.', 'access_denied'); return; } @@ -59,7 +75,7 @@ angular.module('openshiftConsole') if ($scope.createPersistentVolumeClaimForm.$valid) { $scope.disableInputs = true; var claim = generatePersistentVolumeClaim(); - DataService.create('persistentvolumeclaims', null, claim, context) + DataService.create(createPVCVersion, null, claim, context) .then(function(claim) { // Success NotificationsService.addNotification({ type: "success", @@ -81,21 +97,8 @@ angular.module('openshiftConsole') }; function generatePersistentVolumeClaim() { - var pvc = { - kind: "PersistentVolumeClaim", - apiVersion: "v1", - metadata: { - name: $scope.claim.name, - labels: {}, - annotations: {} - }, - spec: { - resources: { - requests:{} - } - } - }; - + var pvc = angular.copy(pvcTemplate); + pvc.metadata.name = $scope.claim.name; pvc.spec.accessModes = [$scope.claim.accessModes || "ReadWriteOnce"] ; var unit = $scope.claim.unit || "Mi"; pvc.spec.resources.requests.storage = $scope.claim.amount + unit; diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index a7f067f8a8..7be8a59231 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -8709,27 +8709,18 @@ kubernetes: n.VERSION.kubernetes }; } ]), angular.module("openshiftConsole").controller("CommandLineController", [ "$scope", "DataService", "AuthService", "Constants", function(e, t, n, a) { n.withUser(), e.cliDownloadURL = a.CLI, e.cliDownloadURLPresent = e.cliDownloadURL && !_.isEmpty(e.cliDownloadURL), e.loginBaseURL = t.openshiftAPIBaseUrl(), a.DISABLE_COPY_LOGIN_COMMAND || (e.sessionToken = n.UserStore().getToken()); -} ]), angular.module("openshiftConsole").controller("CreatePersistentVolumeClaimController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(e, t, n, a, r, o, i, s, c, l, u) { +} ]), angular.module("openshiftConsole").controller("CreatePersistentVolumeClaimController", [ "$filter", "$routeParams", "$scope", "$window", "APIService", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(e, t, n, a, r, o, i, s, c, l, u, d) { n.projectName = t.project, n.accessModes = "ReadWriteOnce", n.claim = {}, n.breadcrumbs = [ { title: "Storage", link: "project/" + n.projectName + "/browse/storage" }, { title: "Create Storage" } ]; -var d = function() { -c.hideNotification("create-pvc-error"); -}; -n.$on("$destroy", d); -var p = function() { -a.history.back(); -}; -n.cancel = p, l.get(t.project).then(_.spread(function(a, r) { -function l() { -var e = { +var p = { kind: "PersistentVolumeClaim", apiVersion: "v1", metadata: { -name: n.claim.name, +name: void 0, labels: {}, annotations: {} }, @@ -8738,26 +8729,35 @@ resources: { requests: {} } } +}, m = r.objectToResourceGroupVersion(p), f = function() { +l.hideNotification("create-pvc-error"); }; -e.spec.accessModes = [ n.claim.accessModes || "ReadWriteOnce" ]; +n.$on("$destroy", f); +var g = function() { +a.history.back(); +}; +n.cancel = g, u.get(t.project).then(_.spread(function(a, r) { +function o() { +var e = angular.copy(p); +e.metadata.name = n.claim.name, e.spec.accessModes = [ n.claim.accessModes || "ReadWriteOnce" ]; var t = n.claim.unit || "Mi"; if (e.spec.resources.requests.storage = n.claim.amount + t, n.claim.selectedLabels) { -var a = u.mapEntries(u.compactEntries(n.claim.selectedLabels)); +var a = d.mapEntries(d.compactEntries(n.claim.selectedLabels)); _.isEmpty(a) || _.set(e, "spec.selector.matchLabels", a); } return n.claim.storageClass && "No Storage Class" !== n.claim.storageClass.metadata.name && (e.metadata.annotations["volume.beta.kubernetes.io/storage-class"] = n.claim.storageClass.metadata.name), e; } -n.project = a, o.canI("persistentvolumeclaims", "create", t.project) ? n.createPersistentVolumeClaim = function() { -if (d(), n.createPersistentVolumeClaimForm.$valid) { +n.project = a, i.canI(m, "create", t.project) ? n.createPersistentVolumeClaim = function() { +if (f(), n.createPersistentVolumeClaimForm.$valid) { n.disableInputs = !0; -var t = l(); -i.create("persistentvolumeclaims", null, t, r).then(function(e) { -c.addNotification({ +var t = o(); +s.create(m, null, t, r).then(function(e) { +l.addNotification({ type: "success", message: "Persistent volume claim " + e.metadata.name + " successfully created." -}), p(); +}), g(); }, function(t) { -n.disableInputs = !1, c.addNotification({ +n.disableInputs = !1, l.addNotification({ id: "create-pvc-error", type: "error", message: "An error occurred requesting storage.", @@ -8765,7 +8765,7 @@ details: e("getErrorDetails")(t) }); }); } -} : s.toErrorPage("You do not have authority to create persistent volume claims in project " + t.project + ".", "access_denied"); +} : c.toErrorPage("You do not have authority to create persistent volume claims in project " + t.project + ".", "access_denied"); })); } ]), angular.module("openshiftConsole").directive("buildClose", [ "$window", function(e) { var t = function(e) {