From d6cd77c7c860b64c9489a4526e1f3b7b0ab4846f Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 27 Sep 2017 16:52:26 -0400 Subject: [PATCH] switch to _.each --- app/scripts/controllers/attachPVC.js | 60 ++++++++++++++-------------- app/views/attach-pvc.html | 2 +- dist/scripts/scripts.js | 28 +++++++++---- dist/scripts/templates.js | 2 +- dist/scripts/vendor.js | 12 +++--- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/app/scripts/controllers/attachPVC.js b/app/scripts/controllers/attachPVC.js index b0e5cfd300..978ee722da 100644 --- a/app/scripts/controllers/attachPVC.js +++ b/app/scripts/controllers/attachPVC.js @@ -119,48 +119,55 @@ angular.module('openshiftConsole') $scope.$watch('attach.containers', updateMountPaths, true); var setVolumeMount = function(podTemplate, name, mountPath, subPath, readOnly) { - for (var i = 0; i < podTemplate.spec.containers.length; i++) { - var containers = podTemplate.spec.containers; - - if (!isContainerSelected(containers[i])) { - continue; + var noError = true; + _.each(podTemplate.spec.containers, function(container) { + if (!isContainerSelected(container)) { + return; } + var stopIteration = false; var newVolumeMount = StorageService.createVolumeMount(name, mountPath, subPath, readOnly); - if (!containers[i].volumeMounts) { - containers[i].volumeMounts = []; + if (!container.volumeMounts) { + container.volumeMounts = []; } - for (var idx = 0; idx < containers[i].volumeMounts.length; idx++) { - var m = containers[i].volumeMounts[idx]; - + _.each(container.volumeMounts, function(mount) { // if a new volumeMount matches an existing mountPath, // fail if their names differ. This can happen when the // "overwrite" option is specified. - if (m.mountPath === newVolumeMount.mountPath && m.name !== newVolumeMount.name) { - displayError('The volume mount "' + m.mountPath + '" with name "' + m.name +'" already exists for container "' + containers[i].name + '"'); + if (mount.mountPath === newVolumeMount.mountPath && mount.name !== newVolumeMount.name) { + displayError('The volume mount "' + mount.mountPath + '" with name "' + mount.name +'" already exists for container "' + container.name + '"'); + noError = false; + stopIteration = true; return false; } - } + }); - for (var mountIdx = 0; mountIdx < containers[i].volumeMounts.length; mountIdx++) { - var existingMount = containers[i].volumeMounts[mountIdx]; + if (stopIteration) { + return false; + } + _.each(container.volumeMounts, function(mount, idx) { // if the volume mount we are trying to add already exists, // replace the existing mount with the newly created one. // This can happen when the "overwrite" option is specified. - if (existingMount.name === newVolumeMount.name) { - containers[i].volumeMounts[mountIdx] = newVolumeMount; - return true; + if (mount.name === newVolumeMount.name) { + container.volumeMounts[idx] = newVolumeMount; + noError = true; + stopIteration = true; + return false; } - } + }); + if (stopIteration) { + return false; + } - containers[i].volumeMounts.push(newVolumeMount); - } + container.volumeMounts.push(newVolumeMount); + }); - return true; + return noError; }; // load resources required to show the page (list of pvcs and deployment or deployment config) @@ -235,13 +242,8 @@ angular.module('openshiftConsole') // if the newly created volume already exists, only // fail if the "overwrite" option was not set - var volumeExists = false; - for (var i = 0; i < podTemplate.spec.volumes.length; i++) { - if (podTemplate.spec.volumes[i].name === newVolume.name) { - volumeExists = true; - break; - } - } + var volumeExists = _.some(podTemplate.spec.volumes, { name: newVolume.name }); + if (!$scope.attach.overwrite || ($scope.attach.overwrite && !volumeExists)) { podTemplate.spec.volumes.push(newVolume); diff --git a/app/views/attach-pvc.html b/app/views/attach-pvc.html index 17144aeadc..26cca90ef1 100644 --- a/app/views/attach-pvc.html +++ b/app/views/attach-pvc.html @@ -225,7 +225,7 @@

Volume

+ ng-disabled="attachPVCForm.$invalid || disableInputs || !attachPVC">Add Cancel diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index 52f3632af1..886438cc70 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -8462,6 +8462,21 @@ var e = _.get(n, "attach.resource.spec.template"); n.existingMountPaths = m.getMountPaths(e, k); }; n.$watchGroup([ "attach.resource", "attach.allContainers" ], j), n.$watch("attach.containers", j, !0); +var P = function(e, t, n, a, r) { +var o = !0; +return _.each(e.spec.containers, function(e) { +if (k(e)) { +var i = !1, s = m.createVolumeMount(t, n, a, r); +if (e.volumeMounts || (e.volumeMounts = []), _.each(e.volumeMounts, function(t) { +if (t.mountPath === s.mountPath && t.name !== s.name) return C('The volume mount "' + t.mountPath + '" with name "' + t.name + '" already exists for container "' + e.name + '"'), o = !1, i = !0, !1; +}), i) return !1; +if (_.each(e.volumeMounts, function(t, n) { +if (t.name === s.name) return e.volumeMounts[n] = s, o = !0, i = !0, !1; +}), i) return !1; +e.volumeMounts.push(s); +} +}), o; +}; s.get(h, t.name, d).then(function(e) { n.attach.resource = e, n.breadcrumbs = i.getBreadcrumbs({ object: e, @@ -8486,14 +8501,13 @@ n.clusterQuotas = e.by("metadata.name"), n.outOfClaims = c.isAnyStorageQuotaExce if (n.disableInputs = !0, S(), n.attachPVCForm.$valid) { n.attach.volumeName || (n.attach.volumeName = b("volume-")); var e = n.attach.resource, a = _.get(e, "spec.template"), r = n.attach.persistentVolumeClaim, o = n.attach.volumeName, i = n.attach.mountPath, c = n.attach.subPath, l = n.attach.readOnly; -i && angular.forEach(a.spec.containers, function(e) { -if (k(e)) { -var t = m.createVolumeMount(o, i, c, l); -e.volumeMounts || (e.volumeMounts = []), e.volumeMounts.push(t); -} -}); +if (i && !P(a, o, i, c, l)) return void (n.disableInputs = !1); var p = m.createVolume(o, r); -a.spec.volumes || (a.spec.volumes = []), a.spec.volumes.push(p), s.update(h, e.metadata.name, n.attach.resource, d).then(function() { +a.spec.volumes || (a.spec.volumes = []); +var v = _.some(a.spec.volumes, { +name: p.name +}); +(!n.attach.overwrite || n.attach.overwrite && !v) && a.spec.volumes.push(p), s.update(h, e.metadata.name, n.attach.resource, d).then(function() { var e; i || (e = "No mount path was provided. The volume reference was added to the configuration, but it will not be mounted into running pods."), u.addNotification({ type: "success", diff --git a/dist/scripts/templates.js b/dist/scripts/templates.js index 577a5fc2d9..4be181f424 100644 --- a/dist/scripts/templates.js +++ b/dist/scripts/templates.js @@ -1122,7 +1122,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "\n" + "
\n" + - "\n" + + "\n" + "Cancel\n" + "
\n" + "\n" + diff --git a/dist/scripts/vendor.js b/dist/scripts/vendor.js index 7c5b71416f..1b3a0b2d5a 100644 --- a/dist/scripts/vendor.js +++ b/dist/scripts/vendor.js @@ -73031,13 +73031,15 @@ oscUniqueDisabled: "=" }, require: "ngModel", link: function(e, t, n, i) { -var r = [], o = !1, a = !0; +var r = [], o = !0; e.$watchCollection("oscUnique", function(e) { r = _.isArray(e) ? e : _.keys(e); -}), e.$watch("oscUniqueDisabled", function(e) { -(o = e) ? i.$setValidity("oscUnique", o) : i.$setValidity("oscUnique", a); -}), i.$parsers.unshift(function(e) { -return a = !_.includes(r, e), o ? (i.$setValidity("oscUnique", o), o) : (i.$setValidity("oscUnique", a), e); +}); +var a = function() { +i.$setValidity("oscUnique", e.oscUniqueDisabled || o); +}; +e.$watch("oscUniqueDisabled", a), i.$parsers.unshift(function(e) { +return o = !_.includes(r, e), a(), e; }); } };