Skip to content

Commit

Permalink
Allow the user to select containers when adding a secret to an applic…
Browse files Browse the repository at this point in the history
…ation

Fixes #2024
  • Loading branch information
jeff-phillips-18 committed Sep 12, 2017
1 parent 0200cf1 commit baef910
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
11 changes: 9 additions & 2 deletions app/scripts/directives/addSecretToApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@
});
};

var isContainerSelected = function(container) {
return ctrl.attachAllContainers || ctrl.attachContainers[container.name];
};

ctrl.$postLink = function() {
$scope.$watch(function() {
return ctrl.application;
}, function() {
// Look at the existing mount paths so that we can warn if the new value is not unique.
var podTemplate = _.get(ctrl.application, 'spec.template');
ctrl.existingMountPaths = StorageService.getMountPaths(podTemplate);
ctrl.attachAllContainers = true;
});
};

Expand Down Expand Up @@ -133,8 +138,10 @@

// For each selected container, add the new volume mount.
_.each(podTemplate.spec.containers, function(container) {
container.volumeMounts = container.volumeMounts || [];
container.volumeMounts.push(newVolumeMount);
if (isContainerSelected(container)) {
container.volumeMounts = container.volumeMounts || [];
container.volumeMounts.push(newVolumeMount);
}
});

var newVolume = {
Expand Down
4 changes: 4 additions & 0 deletions app/styles/_secrets.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

.volume-options {
margin-left: 20px;

h4 {
font-size: 13px;
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions app/views/directives/add-secret-to-application.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ <h3>Add to Application</h3>
</div>
</div>
</div>
<div ng-if="ctrl.addType === 'volume' && ctrl.application.spec.template.spec.containers.length > 1" class="volume-options">
<h4>Containers</h4>
<div ng-if="ctrl.attachAllContainers">
The volume will be mounted into all containers. You can
<a href="" ng-click="ctrl.attachAllContainers = false">select specific containers</a>
instead.
</div>
<div ng-if="!ctrl.attachAllContainers" class="form-group">
<label class="sr-only required">Containers</label>
<select-containers
ng-model="ctrl.attachContainers"
pod-template="ctrl.application.spec.template"
ng-required="true"
help-text="Add the secret to the selected containers.">
</select-containers>
</div>
</div>
</div>
<div class="button-group pull-right">
<button
Expand Down
14 changes: 9 additions & 5 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10633,12 +10633,16 @@ var e = new RegExp("^[A-Za-z_]{1}[A-Za-z0-9_]*$");
m.hasInvalidEnvVars = _.some(m.secret.data, function(t, n) {
return !e.test(n);
});
}, m.$postLink = function() {
};
var g = function(e) {
return m.attachAllContainers || m.attachContainers[e.name];
};
m.$postLink = function() {
t.$watch(function() {
return m.application;
}, function() {
var e = _.get(m.application, "spec.template");
m.existingMountPaths = i.getMountPaths(e);
m.existingMountPaths = i.getMountPaths(e), m.attachAllContainers = !0;
});
}, m.addToApplication = function() {
var t = angular.copy(m.application), i = _.get(t, "spec.template");
Expand All @@ -10658,7 +10662,7 @@ mountPath: m.mountVolume,
readOnly: !0
};
_.each(i.spec.containers, function(e) {
e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l);
g(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l));
});
var u = {
name: c,
Expand All @@ -10668,10 +10672,10 @@ secretName: m.secret.metadata.name
};
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(u);
}
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), g = {
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), h = {
namespace: m.project.metadata.name
};
a.update(n.kindToResource(t.kind), t.metadata.name, t, g).then(function() {
a.update(n.kindToResource(t.kind), t.metadata.name, t, h).then(function() {
o.addNotification({
type: "success",
message: "Successfully added " + p + " " + m.secret.metadata.name + " to " + f + " " + t.metadata.name + ".",
Expand Down
13 changes: 13 additions & 0 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5597,6 +5597,19 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</div>\n" +
"</div>\n" +
"</div>\n" +
"<div ng-if=\"ctrl.addType === 'volume' && ctrl.application.spec.template.spec.containers.length > 1\" class=\"volume-options\">\n" +
"<h4>Containers</h4>\n" +
"<div ng-if=\"ctrl.attachAllContainers\">\n" +
"The volume will be mounted into all containers. You can\n" +
"<a href=\"\" ng-click=\"ctrl.attachAllContainers = false\">select specific containers</a>\n" +
"instead.\n" +
"</div>\n" +
"<div ng-if=\"!ctrl.attachAllContainers\" class=\"form-group\">\n" +
"<label class=\"sr-only required\">Containers</label>\n" +
"<select-containers ng-model=\"ctrl.attachContainers\" pod-template=\"ctrl.application.spec.template\" ng-required=\"true\" help-text=\"Add the secret to the selected containers.\">\n" +
"</select-containers>\n" +
"</div>\n" +
"</div>\n" +
"</div>\n" +
"<div class=\"button-group pull-right\">\n" +
"<button class=\"btn btn-default\" ng-class=\"{'dialog-btn': isDialog}\" ng-click=\"ctrl.onCancel()\">\n" +
Expand Down
1 change: 1 addition & 0 deletions dist/styles/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit baef910

Please sign in to comment.