Skip to content

Commit 8a4bef2

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

File tree

7 files changed

+76
-15
lines changed

7 files changed

+76
-15
lines changed

app/scripts/directives/addSecretToApplication.js

+13-4
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

@@ -119,8 +124,10 @@
119124

120125
// For each container, add the new volume mount.
121126
_.each(podTemplate.spec.containers, function(container) {
122-
container.envFrom = container.envFrom || [];
123-
container.envFrom.push(newEnvFrom);
127+
if (isContainerSelected(container)) {
128+
container.envFrom = container.envFrom || [];
129+
container.envFrom.push(newEnvFrom);
130+
}
124131
});
125132
} else {
126133
var generateName = $filter('generateName');
@@ -133,8 +140,10 @@
133140

134141
// For each selected container, add the new volume mount.
135142
_.each(podTemplate.spec.containers, function(container) {
136-
container.volumeMounts = container.volumeMounts || [];
137-
container.volumeMounts.push(newVolumeMount);
143+
if (isContainerSelected(container)) {
144+
container.volumeMounts = container.volumeMounts || [];
145+
container.volumeMounts.push(newVolumeMount);
146+
}
138147
});
139148

140149
var newVolume = {

app/styles/_secrets.less

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
max-width: 600px;
44
}
55

6+
.container-options {
7+
margin-left: 20px;
8+
.select-container {
9+
max-height: 200px;
10+
overflow-y: auto;
11+
.checkbox:first-of-type {
12+
margin-top: 0;
13+
}
14+
}
15+
}
16+
617
.dialog-title {
718
border-bottom: 1px solid @color-pf-black-300;
819

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

+17
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ <h3>Add to Application</h3>
7070
</div>
7171
</div>
7272
</div>
73+
<legend ng-if-start="ctrl.application.spec.template.spec.containers.length > 1">Containers:</legend>
74+
<div ng-if-end class="form-group container-options">
75+
<div ng-if="ctrl.attachAllContainers">
76+
The secret will be added to all containers. You can
77+
<a href="" ng-click="ctrl.attachAllContainers = false">select specific containers</a>
78+
instead.
79+
</div>
80+
<div ng-if="!ctrl.attachAllContainers" class="form-group">
81+
<label class="sr-only required">Containers</label>
82+
<select-containers
83+
ng-model="ctrl.attachContainers"
84+
pod-template="ctrl.application.spec.template"
85+
ng-required="true"
86+
help-text="Add the secret to the selected containers.">
87+
</select-containers>
88+
</div>
89+
</div>
7390
<div class="button-group pull-right">
7491
<button
7592
class="btn btn-default"

app/views/directives/select-containers.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<ng-form name="forms.containerSelect">
2-
<div class="checkbox" ng-repeat="container in template.spec.containers">
3-
<label class="truncate">
4-
<input
2+
<div class="select-container">
3+
<div class="checkbox" ng-repeat="container in template.spec.containers">
4+
<label class="truncate">
5+
<input
56
type="checkbox"
67
ng-model="containers[container.name]"
78
ng-required="required && !containerSelected">
8-
<b>{{container.name}}</b>
9+
<b>{{container.name}}</b>
910
<span class="hidden-xs">
1011
from image
1112
<i ng-attr-title="{{container.image}}">{{container.image}}</i>
1213
</span>
13-
</label>
14+
</label>
15+
</div>
1416
</div>
1517
<div ng-if="helpText" class="help-block">
1618
{{helpText}}

dist/scripts/scripts.js

+10-6
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");
@@ -10649,7 +10653,7 @@ name: m.secret.metadata.name
1064910653
}
1065010654
};
1065110655
_.each(i.spec.containers, function(e) {
10652-
e.envFrom = e.envFrom || [], e.envFrom.push(s);
10656+
g(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
1065310657
});
1065410658
} else {
1065510659
var c = e("generateName")(m.secret.metadata.name + "-"), l = {
@@ -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

+15
Original file line numberDiff line numberDiff line change
@@ -5598,6 +5598,19 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
55985598
"</div>\n" +
55995599
"</div>\n" +
56005600
"</div>\n" +
5601+
"<legend ng-if-start=\"ctrl.application.spec.template.spec.containers.length > 1\">Containers:</legend>\n" +
5602+
"<div ng-if-end class=\"form-group container-options\">\n" +
5603+
"<div ng-if=\"ctrl.attachAllContainers\">\n" +
5604+
"The secret will be added to all containers. You can\n" +
5605+
"<a href=\"\" ng-click=\"ctrl.attachAllContainers = false\">select specific containers</a>\n" +
5606+
"instead.\n" +
5607+
"</div>\n" +
5608+
"<div ng-if=\"!ctrl.attachAllContainers\" class=\"form-group\">\n" +
5609+
"<label class=\"sr-only required\">Containers</label>\n" +
5610+
"<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" +
5611+
"</select-containers>\n" +
5612+
"</div>\n" +
5613+
"</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" +
56035616
"Cancel\n" +
@@ -8799,6 +8812,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
87998812

88008813
$templateCache.put('views/directives/select-containers.html',
88018814
"<ng-form name=\"forms.containerSelect\">\n" +
8815+
"<div class=\"select-container\">\n" +
88028816
"<div class=\"checkbox\" ng-repeat=\"container in template.spec.containers\">\n" +
88038817
"<label class=\"truncate\">\n" +
88048818
"<input type=\"checkbox\" ng-model=\"containers[container.name]\" ng-required=\"required && !containerSelected\">\n" +
@@ -8809,6 +8823,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
88098823
"</span>\n" +
88108824
"</label>\n" +
88118825
"</div>\n" +
8826+
"</div>\n" +
88128827
"<div ng-if=\"helpText\" class=\"help-block\">\n" +
88138828
"{{helpText}}\n" +
88148829
"</div>\n" +

dist/styles/main.css

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

0 commit comments

Comments
 (0)