Skip to content

Commit dabc632

Browse files
Merge pull request #2263 from openshift/revert-2176-jvallejo/add-set-volume-overwrite-option
Automatic merge from submit-queue. Revert "add "overwrite" option to attachPVC view" Reverts #2176 The change has introduced some bugs. Reverting for now. I've reopened the original issue.
2 parents 9930f0c + 9e08964 commit dabc632

File tree

4 files changed

+20
-119
lines changed

4 files changed

+20
-119
lines changed

app/scripts/controllers/attachPVC.js

+11-69
Original file line numberDiff line numberDiff line change
@@ -118,63 +118,6 @@ angular.module('openshiftConsole')
118118
$scope.$watchGroup(['attach.resource', 'attach.allContainers'], updateMountPaths);
119119
$scope.$watch('attach.containers', updateMountPaths, true);
120120

121-
var checkVolumeMountPath = function(newVolumeMount, container) {
122-
var duplicateMount = _.find(container.volumeMounts, function(mount) {
123-
return mount.mountPath === newVolumeMount && mount.name !== newVolumeMount.name;
124-
});
125-
126-
// if a new volumeMount matches an existing mountPath,
127-
// fail if their names differ. This can happen when the
128-
// "overwrite" option is specified.
129-
if (duplicateMount) {
130-
displayError('The volume mount "' + duplicateMount.mountPath + '" with name "' + duplicateMount.name +'" already exists for container "' + container.name + '"');
131-
return false;
132-
}
133-
134-
return true;
135-
};
136-
137-
var replaceExistingVolumeMount = function(newVolumeMount, container) {
138-
// if the volume mount we are trying to add already exists,
139-
// replace the existing mount with the newly created one.
140-
// This can happen when the "overwrite" option is specified.
141-
var index = _.findIndex(container.volumeMounts, { name: newVolumeMount.name });
142-
if (index === -1) {
143-
return false;
144-
}
145-
146-
container.volumeMounts[index] = newVolumeMount;
147-
return true;
148-
};
149-
150-
var setVolumeMount = function(podTemplate, name, mountPath, subPath, readOnly) {
151-
var success = true;
152-
_.each(podTemplate.spec.containers, function(container) {
153-
if (!isContainerSelected(container)) {
154-
return;
155-
}
156-
157-
var newVolumeMount =
158-
StorageService.createVolumeMount(name, mountPath, subPath, readOnly);
159-
if (!container.volumeMounts) {
160-
container.volumeMounts = [];
161-
}
162-
163-
if (!checkVolumeMountPath(newVolumeMount, container)) {
164-
success = false;
165-
return false;
166-
}
167-
168-
if (replaceExistingVolumeMount(newVolumeMount, container)) {
169-
return false;
170-
}
171-
172-
container.volumeMounts.push(newVolumeMount);
173-
});
174-
175-
return success;
176-
};
177-
178121
// load resources required to show the page (list of pvcs and deployment or deployment config)
179122
var load = function() {
180123
DataService.get(resourceGroupVersion, $routeParams.name, context).then(
@@ -232,25 +175,24 @@ angular.module('openshiftConsole')
232175
var readOnly = $scope.attach.readOnly;
233176
if (mountPath) {
234177
// for each container in the pod spec, add the new volume mount
235-
if(!setVolumeMount(podTemplate, name, mountPath, subPath, readOnly)) {
236-
$scope.disableInputs = false;
237-
return;
238-
}
178+
angular.forEach(podTemplate.spec.containers, function(container) {
179+
if (isContainerSelected(container)) {
180+
var newVolumeMount =
181+
StorageService.createVolumeMount(name, mountPath, subPath, readOnly);
182+
if (!container.volumeMounts) {
183+
container.volumeMounts = [];
184+
}
185+
container.volumeMounts.push(newVolumeMount);
186+
}
187+
});
239188
}
240189

241190
// add the new volume to the pod template
242191
var newVolume = StorageService.createVolume(name, persistentVolumeClaim);
243192
if (!podTemplate.spec.volumes) {
244193
podTemplate.spec.volumes = [];
245194
}
246-
247-
// if the newly created volume already exists, only
248-
// fail if the "overwrite" option was not set
249-
var volumeExists = _.some(podTemplate.spec.volumes, { name: newVolume.name });
250-
251-
if (!volumeExists) {
252-
podTemplate.spec.volumes.push(newVolume);
253-
}
195+
podTemplate.spec.volumes.push(newVolume);
254196

255197
DataService.update(resourceGroupVersion, resource.metadata.name, $scope.attach.resource, context).then(
256198
function() {

app/views/attach-pvc.html

-14
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ <h3>Volume</h3>
8383
ng-model="attach.mountPath"
8484
ng-pattern="/^\/.*$/"
8585
osc-unique="existingMountPaths"
86-
osc-unique-disabled="attach.overwrite"
8786
placeholder="example: /data"
8887
autocorrect="off"
8988
autocapitalize="none"
@@ -144,7 +143,6 @@ <h3>Volume</h3>
144143
name="volumeName"
145144
ng-model="attach.volumeName"
146145
osc-unique="existingVolumeNames"
147-
osc-unique-disabled="attach.overwrite"
148146
ng-pattern="/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/"
149147
maxlength="63"
150148
placeholder="(generated if empty)"
@@ -173,18 +171,6 @@ <h3>Volume</h3>
173171
</div>
174172
</div>
175173

176-
<div class="form-group">
177-
<div class="checkbox">
178-
<label>
179-
<input type="checkbox" ng-model="attach.overwrite" aria-describedby="overwrite-help">
180-
Overwrite
181-
</label>
182-
<div id="overwrite-help" class="help-block">
183-
Overwrite a volume mount if it already exists.
184-
</div>
185-
</div>
186-
</div>
187-
188174
<div class="form-group">
189175
<div class="checkbox">
190176
<label>

dist/scripts/scripts.js

+7-23
Original file line numberDiff line numberDiff line change
@@ -8492,25 +8492,6 @@ var e = _.get(n, "attach.resource.spec.template");
84928492
n.existingMountPaths = m.getMountPaths(e, k);
84938493
};
84948494
n.$watchGroup([ "attach.resource", "attach.allContainers" ], j), n.$watch("attach.containers", j, !0);
8495-
var P = function(e, t) {
8496-
var n = _.find(t.volumeMounts, function(t) {
8497-
return t.mountPath === e && t.name !== e.name;
8498-
});
8499-
return !n || (C('The volume mount "' + n.mountPath + '" with name "' + n.name + '" already exists for container "' + t.name + '"'), !1);
8500-
}, R = function(e, t) {
8501-
var n = _.findIndex(t.volumeMounts, {
8502-
name: e.name
8503-
});
8504-
return -1 !== n && (t.volumeMounts[n] = e, !0);
8505-
}, I = function(e, t, n, a, r) {
8506-
var o = !0;
8507-
return _.each(e.spec.containers, function(e) {
8508-
if (k(e)) {
8509-
var i = m.createVolumeMount(t, n, a, r);
8510-
return e.volumeMounts || (e.volumeMounts = []), P(i, e) ? !R(i, e) && void e.volumeMounts.push(i) : (o = !1, !1);
8511-
}
8512-
}), o;
8513-
};
85148495
s.get(v, t.name, d).then(function(e) {
85158496
n.attach.resource = e, n.breadcrumbs = i.getBreadcrumbs({
85168497
object: e,
@@ -8535,11 +8516,14 @@ n.clusterQuotas = e.by("metadata.name"), n.outOfClaims = c.isAnyStorageQuotaExce
85358516
if (n.disableInputs = !0, S(), n.attachPVCForm.$valid) {
85368517
n.attach.volumeName || (n.attach.volumeName = b("volume-"));
85378518
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;
8538-
if (i && !I(a, o, i, c, l)) return void (n.disableInputs = !1);
8519+
i && angular.forEach(a.spec.containers, function(e) {
8520+
if (k(e)) {
8521+
var t = m.createVolumeMount(o, i, c, l);
8522+
e.volumeMounts || (e.volumeMounts = []), e.volumeMounts.push(t);
8523+
}
8524+
});
85398525
var p = m.createVolume(o, r);
8540-
a.spec.volumes || (a.spec.volumes = []), _.some(a.spec.volumes, {
8541-
name: p.name
8542-
}) || a.spec.volumes.push(p), s.update(v, e.metadata.name, n.attach.resource, d).then(function() {
8526+
a.spec.volumes || (a.spec.volumes = []), a.spec.volumes.push(p), s.update(v, e.metadata.name, n.attach.resource, d).then(function() {
85438527
var e;
85448528
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({
85458529
type: "success",

dist/scripts/templates.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
990990
"</div>\n" +
991991
"<div class=\"form-group mar-top-xl\">\n" +
992992
"<label for=\"mount-path\">Mount Path</label>\n" +
993-
"<input id=\"mount-path\" class=\"form-control\" type=\"text\" name=\"mountPath\" ng-model=\"attach.mountPath\" ng-pattern=\"/^\\/.*$/\" osc-unique=\"existingMountPaths\" osc-unique-disabled=\"attach.overwrite\" placeholder=\"example: /data\" autocorrect=\"off\" autocapitalize=\"none\" spellcheck=\"false\" aria-describedby=\"mount-path-help\">\n" +
993+
"<input id=\"mount-path\" class=\"form-control\" type=\"text\" name=\"mountPath\" ng-model=\"attach.mountPath\" ng-pattern=\"/^\\/.*$/\" osc-unique=\"existingMountPaths\" placeholder=\"example: /data\" autocorrect=\"off\" autocapitalize=\"none\" spellcheck=\"false\" aria-describedby=\"mount-path-help\">\n" +
994994
"<div>\n" +
995995
"<span id=\"mount-path-help\" class=\"help-block\">Mount path for the volume inside the container. If not specified, the volume will not be mounted automatically.</span>\n" +
996996
"</div>\n" +
@@ -1020,7 +1020,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
10201020
"<div class=\"form-group\">\n" +
10211021
"<label for=\"volume-name\">Volume Name</label>\n" +
10221022
"\n" +
1023-
"<input id=\"volume-path\" class=\"form-control\" type=\"text\" name=\"volumeName\" ng-model=\"attach.volumeName\" osc-unique=\"existingVolumeNames\" osc-unique-disabled=\"attach.overwrite\" ng-pattern=\"/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/\" maxlength=\"63\" placeholder=\"(generated if empty)\" autocorrect=\"off\" autocapitalize=\"none\" spellcheck=\"false\" aria-describedby=\"volume-name-help\">\n" +
1023+
"<input id=\"volume-path\" class=\"form-control\" type=\"text\" name=\"volumeName\" ng-model=\"attach.volumeName\" osc-unique=\"existingVolumeNames\" ng-pattern=\"/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/\" maxlength=\"63\" placeholder=\"(generated if empty)\" autocorrect=\"off\" autocapitalize=\"none\" spellcheck=\"false\" aria-describedby=\"volume-name-help\">\n" +
10241024
"<div>\n" +
10251025
"<span id=\"volume-name-help\" class=\"help-block\">Unique name used to identify this volume. If not specified, a volume name is generated.</span>\n" +
10261026
"</div>\n" +
@@ -1043,17 +1043,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
10431043
"<div class=\"form-group\">\n" +
10441044
"<div class=\"checkbox\">\n" +
10451045
"<label>\n" +
1046-
"<input type=\"checkbox\" ng-model=\"attach.overwrite\" aria-describedby=\"overwrite-help\">\n" +
1047-
"Overwrite\n" +
1048-
"</label>\n" +
1049-
"<div id=\"overwrite-help\" class=\"help-block\">\n" +
1050-
"Overwrite a volume mount if it already exists.\n" +
1051-
"</div>\n" +
1052-
"</div>\n" +
1053-
"</div>\n" +
1054-
"<div class=\"form-group\">\n" +
1055-
"<div class=\"checkbox\">\n" +
1056-
"<label>\n" +
10571046
"<input type=\"checkbox\" ng-model=\"attach.readOnly\" aria-describedby=\"read-only-help\">\n" +
10581047
"Read only\n" +
10591048
"</label>\n" +

0 commit comments

Comments
 (0)