diff --git a/app/scripts/controllers/attachPVC.js b/app/scripts/controllers/attachPVC.js index 978ee722da..d760dfda8a 100644 --- a/app/scripts/controllers/attachPVC.js +++ b/app/scripts/controllers/attachPVC.js @@ -118,56 +118,67 @@ angular.module('openshiftConsole') $scope.$watchGroup(['attach.resource', 'attach.allContainers'], updateMountPaths); $scope.$watch('attach.containers', updateMountPaths, true); + var checkVolumeMountPath = function(newVolumeMount, container) { + // if a new volumeMount matches an existing mountPath, + // fail if their names differ. This can happen when the + // "overwrite" option is specified. + // Returns a boolean true if no errors occurred. + var success = true; + _.each(container.volumeMounts, function(mount) { + 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 + '"'); + success = false; + return success; + } + }); + + return success; + }; + + var replaceExistingVolumeMount = function(newVolumeMount, container) { + // 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. + // Returns a boolean true if an existing mount was found and + // replaced with a newly-created volume mount. + var didReplace = false; + _.each(container.volumeMounts, function(mount, idx) { + if (mount.name === newVolumeMount.name) { + container.volumeMounts[idx] = newVolumeMount; + didReplace = true; + return false; + } + }); + + return didReplace; + }; + var setVolumeMount = function(podTemplate, name, mountPath, subPath, readOnly) { - var noError = true; + var success = true; _.each(podTemplate.spec.containers, function(container) { if (!isContainerSelected(container)) { return; } - var stopIteration = false; var newVolumeMount = StorageService.createVolumeMount(name, mountPath, subPath, readOnly); if (!container.volumeMounts) { container.volumeMounts = []; } - _.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 (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; - } - }); - - if (stopIteration) { + if (!checkVolumeMountPath(newVolumeMount, container)) { + success = false; 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 (mount.name === newVolumeMount.name) { - container.volumeMounts[idx] = newVolumeMount; - noError = true; - stopIteration = true; - return false; - } - }); - - if (stopIteration) { + if (replaceExistingVolumeMount(newVolumeMount, container)) { return false; } container.volumeMounts.push(newVolumeMount); }); - return noError; + return success; }; // load resources required to show the page (list of pvcs and deployment or deployment config) diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index b668769551..f4a2158ab8 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -8446,18 +8446,22 @@ 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 P = function(e, t) { +var n = !0; +return _.each(t.volumeMounts, function(a) { +if (a.mountPath === e.mountPath && a.name !== e.name) return C('The volume mount "' + a.mountPath + '" with name "' + a.name + '" already exists for container "' + t.name + '"'), n = !1; +}), n; +}, R = function(e, t) { +var n = !1; +return _.each(t.volumeMounts, function(a, r) { +if (a.name === e.name) return t.volumeMounts[r] = e, n = !0, !1; +}), n; +}, I = 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); +var i = m.createVolumeMount(t, n, a, r); +return e.volumeMounts || (e.volumeMounts = []), P(i, e) ? !R(i, e) && void e.volumeMounts.push(i) : (o = !1, !1); } }), o; }; @@ -8485,7 +8489,7 @@ 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; -if (i && !P(a, o, i, c, l)) return void (n.disableInputs = !1); +if (i && !I(a, o, i, c, l)) return void (n.disableInputs = !1); var p = m.createVolume(o, r); a.spec.volumes || (a.spec.volumes = []); var v = _.some(a.spec.volumes, {