Skip to content

Commit d6cd77c

Browse files
committed
switch to _.each
1 parent db00162 commit d6cd77c

File tree

5 files changed

+61
-43
lines changed

5 files changed

+61
-43
lines changed

app/scripts/controllers/attachPVC.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,48 +119,55 @@ angular.module('openshiftConsole')
119119
$scope.$watch('attach.containers', updateMountPaths, true);
120120

121121
var setVolumeMount = function(podTemplate, name, mountPath, subPath, readOnly) {
122-
for (var i = 0; i < podTemplate.spec.containers.length; i++) {
123-
var containers = podTemplate.spec.containers;
124-
125-
if (!isContainerSelected(containers[i])) {
126-
continue;
122+
var noError = true;
123+
_.each(podTemplate.spec.containers, function(container) {
124+
if (!isContainerSelected(container)) {
125+
return;
127126
}
128127

128+
var stopIteration = false;
129129
var newVolumeMount =
130130
StorageService.createVolumeMount(name, mountPath, subPath, readOnly);
131-
if (!containers[i].volumeMounts) {
132-
containers[i].volumeMounts = [];
131+
if (!container.volumeMounts) {
132+
container.volumeMounts = [];
133133
}
134134

135-
for (var idx = 0; idx < containers[i].volumeMounts.length; idx++) {
136-
var m = containers[i].volumeMounts[idx];
137-
135+
_.each(container.volumeMounts, function(mount) {
138136
// if a new volumeMount matches an existing mountPath,
139137
// fail if their names differ. This can happen when the
140138
// "overwrite" option is specified.
141-
if (m.mountPath === newVolumeMount.mountPath && m.name !== newVolumeMount.name) {
142-
displayError('The volume mount "' + m.mountPath + '" with name "' + m.name +'" already exists for container "' + containers[i].name + '"');
139+
if (mount.mountPath === newVolumeMount.mountPath && mount.name !== newVolumeMount.name) {
140+
displayError('The volume mount "' + mount.mountPath + '" with name "' + mount.name +'" already exists for container "' + container.name + '"');
141+
noError = false;
142+
stopIteration = true;
143143
return false;
144144
}
145-
}
145+
});
146146

147-
for (var mountIdx = 0; mountIdx < containers[i].volumeMounts.length; mountIdx++) {
148-
var existingMount = containers[i].volumeMounts[mountIdx];
147+
if (stopIteration) {
148+
return false;
149+
}
149150

151+
_.each(container.volumeMounts, function(mount, idx) {
150152
// if the volume mount we are trying to add already exists,
151153
// replace the existing mount with the newly created one.
152154
// This can happen when the "overwrite" option is specified.
153-
if (existingMount.name === newVolumeMount.name) {
154-
containers[i].volumeMounts[mountIdx] = newVolumeMount;
155-
return true;
155+
if (mount.name === newVolumeMount.name) {
156+
container.volumeMounts[idx] = newVolumeMount;
157+
noError = true;
158+
stopIteration = true;
159+
return false;
156160
}
157-
}
161+
});
158162

163+
if (stopIteration) {
164+
return false;
165+
}
159166

160-
containers[i].volumeMounts.push(newVolumeMount);
161-
}
167+
container.volumeMounts.push(newVolumeMount);
168+
});
162169

163-
return true;
170+
return noError;
164171
};
165172

166173
// load resources required to show the page (list of pvcs and deployment or deployment config)
@@ -235,13 +242,8 @@ angular.module('openshiftConsole')
235242

236243
// if the newly created volume already exists, only
237244
// fail if the "overwrite" option was not set
238-
var volumeExists = false;
239-
for (var i = 0; i < podTemplate.spec.volumes.length; i++) {
240-
if (podTemplate.spec.volumes[i].name === newVolume.name) {
241-
volumeExists = true;
242-
break;
243-
}
244-
}
245+
var volumeExists = _.some(podTemplate.spec.volumes, { name: newVolume.name });
246+
245247

246248
if (!$scope.attach.overwrite || ($scope.attach.overwrite && !volumeExists)) {
247249
podTemplate.spec.volumes.push(newVolume);

app/views/attach-pvc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ <h3>Volume</h3>
225225
<button type="submit"
226226
class="btn btn-primary btn-lg"
227227
ng-click="attachPVC()"
228-
ng-disabled="(attachPVCForm.$invalid) || disableInputs || !attachPVC">Add</button>
228+
ng-disabled="attachPVCForm.$invalid || disableInputs || !attachPVC">Add</button>
229229
<a class="btn btn-default btn-lg" role="button" ng-click="cancel()">Cancel</a>
230230
</div>
231231
</fieldset>

dist/scripts/scripts.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8462,6 +8462,21 @@ var e = _.get(n, "attach.resource.spec.template");
84628462
n.existingMountPaths = m.getMountPaths(e, k);
84638463
};
84648464
n.$watchGroup([ "attach.resource", "attach.allContainers" ], j), n.$watch("attach.containers", j, !0);
8465+
var P = function(e, t, n, a, r) {
8466+
var o = !0;
8467+
return _.each(e.spec.containers, function(e) {
8468+
if (k(e)) {
8469+
var i = !1, s = m.createVolumeMount(t, n, a, r);
8470+
if (e.volumeMounts || (e.volumeMounts = []), _.each(e.volumeMounts, function(t) {
8471+
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;
8472+
}), i) return !1;
8473+
if (_.each(e.volumeMounts, function(t, n) {
8474+
if (t.name === s.name) return e.volumeMounts[n] = s, o = !0, i = !0, !1;
8475+
}), i) return !1;
8476+
e.volumeMounts.push(s);
8477+
}
8478+
}), o;
8479+
};
84658480
s.get(h, t.name, d).then(function(e) {
84668481
n.attach.resource = e, n.breadcrumbs = i.getBreadcrumbs({
84678482
object: e,
@@ -8486,14 +8501,13 @@ n.clusterQuotas = e.by("metadata.name"), n.outOfClaims = c.isAnyStorageQuotaExce
84868501
if (n.disableInputs = !0, S(), n.attachPVCForm.$valid) {
84878502
n.attach.volumeName || (n.attach.volumeName = b("volume-"));
84888503
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;
8489-
i && angular.forEach(a.spec.containers, function(e) {
8490-
if (k(e)) {
8491-
var t = m.createVolumeMount(o, i, c, l);
8492-
e.volumeMounts || (e.volumeMounts = []), e.volumeMounts.push(t);
8493-
}
8494-
});
8504+
if (i && !P(a, o, i, c, l)) return void (n.disableInputs = !1);
84958505
var p = m.createVolume(o, r);
8496-
a.spec.volumes || (a.spec.volumes = []), a.spec.volumes.push(p), s.update(h, e.metadata.name, n.attach.resource, d).then(function() {
8506+
a.spec.volumes || (a.spec.volumes = []);
8507+
var v = _.some(a.spec.volumes, {
8508+
name: p.name
8509+
});
8510+
(!n.attach.overwrite || n.attach.overwrite && !v) && a.spec.volumes.push(p), s.update(h, e.metadata.name, n.attach.resource, d).then(function() {
84978511
var e;
84988512
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({
84998513
type: "success",

dist/scripts/templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
11221122
"<pause-rollouts-checkbox ng-if=\"attach.resource | managesRollouts\" deployment=\"attach.resource\">\n" +
11231123
"</pause-rollouts-checkbox>\n" +
11241124
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
1125-
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"attachPVC()\" ng-disabled=\"(attachPVCForm.$invalid) || disableInputs || !attachPVC\">Add</button>\n" +
1125+
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"attachPVC()\" ng-disabled=\"attachPVCForm.$invalid || disableInputs || !attachPVC\">Add</button>\n" +
11261126
"<a class=\"btn btn-default btn-lg\" role=\"button\" ng-click=\"cancel()\">Cancel</a>\n" +
11271127
"</div>\n" +
11281128
"</fieldset>\n" +

dist/scripts/vendor.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73031,13 +73031,15 @@ oscUniqueDisabled: "="
7303173031
},
7303273032
require: "ngModel",
7303373033
link: function(e, t, n, i) {
73034-
var r = [], o = !1, a = !0;
73034+
var r = [], o = !0;
7303573035
e.$watchCollection("oscUnique", function(e) {
7303673036
r = _.isArray(e) ? e : _.keys(e);
73037-
}), e.$watch("oscUniqueDisabled", function(e) {
73038-
(o = e) ? i.$setValidity("oscUnique", o) : i.$setValidity("oscUnique", a);
73039-
}), i.$parsers.unshift(function(e) {
73040-
return a = !_.includes(r, e), o ? (i.$setValidity("oscUnique", o), o) : (i.$setValidity("oscUnique", a), e);
73037+
});
73038+
var a = function() {
73039+
i.$setValidity("oscUnique", e.oscUniqueDisabled || o);
73040+
};
73041+
e.$watch("oscUniqueDisabled", a), i.$parsers.unshift(function(e) {
73042+
return o = !_.includes(r, e), a(), e;
7304173043
});
7304273044
}
7304373045
};

0 commit comments

Comments
 (0)