Skip to content

Commit baef910

Browse files
Allow the user to select containers when adding a secret to an application
Fixes #2024
1 parent 0200cf1 commit baef910

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

app/scripts/directives/addSecretToApplication.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@
9393
});
9494
};
9595

96+
var isContainerSelected = function(container) {
97+
return ctrl.attachAllContainers || ctrl.attachContainers[container.name];
98+
};
99+
96100
ctrl.$postLink = function() {
97101
$scope.$watch(function() {
98102
return ctrl.application;
99103
}, function() {
100104
// Look at the existing mount paths so that we can warn if the new value is not unique.
101105
var podTemplate = _.get(ctrl.application, 'spec.template');
102106
ctrl.existingMountPaths = StorageService.getMountPaths(podTemplate);
107+
ctrl.attachAllContainers = true;
103108
});
104109
};
105110

@@ -133,8 +138,10 @@
133138

134139
// For each selected container, add the new volume mount.
135140
_.each(podTemplate.spec.containers, function(container) {
136-
container.volumeMounts = container.volumeMounts || [];
137-
container.volumeMounts.push(newVolumeMount);
141+
if (isContainerSelected(container)) {
142+
container.volumeMounts = container.volumeMounts || [];
143+
container.volumeMounts.push(newVolumeMount);
144+
}
138145
});
139146

140147
var newVolume = {

app/styles/_secrets.less

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454

5555
.volume-options {
5656
margin-left: 20px;
57+
58+
h4 {
59+
font-size: 13px;
60+
}
5761
}
5862
}
5963

app/views/directives/add-secret-to-application.html

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ <h3>Add to Application</h3>
6969
</div>
7070
</div>
7171
</div>
72+
<div ng-if="ctrl.addType === 'volume' && ctrl.application.spec.template.spec.containers.length > 1" class="volume-options">
73+
<h4>Containers</h4>
74+
<div ng-if="ctrl.attachAllContainers">
75+
The volume will be mounted into all containers. You can
76+
<a href="" ng-click="ctrl.attachAllContainers = false">select specific containers</a>
77+
instead.
78+
</div>
79+
<div ng-if="!ctrl.attachAllContainers" class="form-group">
80+
<label class="sr-only required">Containers</label>
81+
<select-containers
82+
ng-model="ctrl.attachContainers"
83+
pod-template="ctrl.application.spec.template"
84+
ng-required="true"
85+
help-text="Add the secret to the selected containers.">
86+
</select-containers>
87+
</div>
88+
</div>
7289
</div>
7390
<div class="button-group pull-right">
7491
<button

dist/scripts/scripts.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -10633,12 +10633,16 @@ var e = new RegExp("^[A-Za-z_]{1}[A-Za-z0-9_]*$");
1063310633
m.hasInvalidEnvVars = _.some(m.secret.data, function(t, n) {
1063410634
return !e.test(n);
1063510635
});
10636-
}, m.$postLink = function() {
10636+
};
10637+
var g = function(e) {
10638+
return m.attachAllContainers || m.attachContainers[e.name];
10639+
};
10640+
m.$postLink = function() {
1063710641
t.$watch(function() {
1063810642
return m.application;
1063910643
}, function() {
1064010644
var e = _.get(m.application, "spec.template");
10641-
m.existingMountPaths = i.getMountPaths(e);
10645+
m.existingMountPaths = i.getMountPaths(e), m.attachAllContainers = !0;
1064210646
});
1064310647
}, m.addToApplication = function() {
1064410648
var t = angular.copy(m.application), i = _.get(t, "spec.template");
@@ -10658,7 +10662,7 @@ mountPath: m.mountVolume,
1065810662
readOnly: !0
1065910663
};
1066010664
_.each(i.spec.containers, function(e) {
10661-
e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l);
10665+
g(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l));
1066210666
});
1066310667
var u = {
1066410668
name: c,
@@ -10668,10 +10672,10 @@ secretName: m.secret.metadata.name
1066810672
};
1066910673
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(u);
1067010674
}
10671-
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), g = {
10675+
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), h = {
1067210676
namespace: m.project.metadata.name
1067310677
};
10674-
a.update(n.kindToResource(t.kind), t.metadata.name, t, g).then(function() {
10678+
a.update(n.kindToResource(t.kind), t.metadata.name, t, h).then(function() {
1067510679
o.addNotification({
1067610680
type: "success",
1067710681
message: "Successfully added " + p + " " + m.secret.metadata.name + " to " + f + " " + t.metadata.name + ".",

dist/scripts/templates.js

+13
Original file line numberDiff line numberDiff line change
@@ -5597,6 +5597,19 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
55975597
"</div>\n" +
55985598
"</div>\n" +
55995599
"</div>\n" +
5600+
"<div ng-if=\"ctrl.addType === 'volume' && ctrl.application.spec.template.spec.containers.length > 1\" class=\"volume-options\">\n" +
5601+
"<h4>Containers</h4>\n" +
5602+
"<div ng-if=\"ctrl.attachAllContainers\">\n" +
5603+
"The volume will be mounted into all containers. You can\n" +
5604+
"<a href=\"\" ng-click=\"ctrl.attachAllContainers = false\">select specific containers</a>\n" +
5605+
"instead.\n" +
5606+
"</div>\n" +
5607+
"<div ng-if=\"!ctrl.attachAllContainers\" class=\"form-group\">\n" +
5608+
"<label class=\"sr-only required\">Containers</label>\n" +
5609+
"<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" +
5610+
"</select-containers>\n" +
5611+
"</div>\n" +
5612+
"</div>\n" +
56005613
"</div>\n" +
56015614
"<div class=\"button-group pull-right\">\n" +
56025615
"<button class=\"btn btn-default\" ng-class=\"{'dialog-btn': isDialog}\" ng-click=\"ctrl.onCancel()\">\n" +

dist/styles/main.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)