Skip to content

Commit bb26188

Browse files
jeff-phillips-18f0x11
authored andcommitted
Allow the user to select containers when adding a secret to an application
Fixes openshift#2024
1 parent cbb19ef commit bb26188

File tree

6 files changed

+74
-9
lines changed

6 files changed

+74
-9
lines changed

app/scripts/directives/addSecretToApplication.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,18 @@
8787
getApplications();
8888
};
8989

90+
var isContainerSelected = function(container) {
91+
return ctrl.attachAllContainers || ctrl.attachContainers[container.name];
92+
};
93+
9094
ctrl.$postLink = function() {
9195
$scope.$watch(function() {
9296
return ctrl.application;
9397
}, function() {
9498
// Look at the existing mount paths so that we can warn if the new value is not unique.
9599
var podTemplate = _.get(ctrl.application, 'spec.template');
96100
ctrl.existingMountPaths = StorageService.getMountPaths(podTemplate);
101+
ctrl.attachAllContainers = true;
97102
});
98103
};
99104

@@ -113,8 +118,10 @@
113118

114119
// For each container, add the new volume mount.
115120
_.each(podTemplate.spec.containers, function(container) {
116-
container.envFrom = container.envFrom || [];
117-
container.envFrom.push(newEnvFrom);
121+
if (isContainerSelected(container)) {
122+
container.envFrom = container.envFrom || [];
123+
container.envFrom.push(newEnvFrom);
124+
}
118125
});
119126
} else {
120127
var generateName = $filter('generateName');
@@ -127,8 +134,10 @@
127134

128135
// For each selected container, add the new volume mount.
129136
_.each(podTemplate.spec.containers, function(container) {
130-
container.volumeMounts = container.volumeMounts || [];
131-
container.volumeMounts.push(newVolumeMount);
137+
if (isContainerSelected(container)) {
138+
container.volumeMounts = container.volumeMounts || [];
139+
container.volumeMounts.push(newVolumeMount);
140+
}
132141
});
133142

134143
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
@@ -64,6 +64,23 @@ <h3>Add to Application</h3>
6464
</div>
6565
</div>
6666
</div>
67+
<legend ng-if-start="ctrl.application.spec.template.spec.containers.length > 1">Containers:</legend>
68+
<div ng-if-end class="form-group container-options">
69+
<div ng-if="ctrl.attachAllContainers">
70+
The secret will be added to all containers. You can
71+
<a href="" ng-click="ctrl.attachAllContainers = false">select specific containers</a>
72+
instead.
73+
</div>
74+
<div ng-if="!ctrl.attachAllContainers" class="form-group">
75+
<label class="sr-only required">Containers</label>
76+
<select-containers
77+
ng-model="ctrl.attachContainers"
78+
pod-template="ctrl.application.spec.template"
79+
ng-required="true"
80+
help-text="Add the secret to the selected containers.">
81+
</select-containers>
82+
</div>
83+
</div>
6784
<div class="button-group pull-right">
6885
<button
6986
class="btn btn-default"

dist/scripts/scripts.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -21395,12 +21395,24 @@ d = _.toArray(e.by("metadata.name")), p();
2139521395
};
2139621396
m.$onInit = function() {
2139721397
m.addType = "env", m.disableInputs = !1, f();
21398+
<<<<<<< a8e13079948a1153dd52ad0ff49228eb68945806
2139821399
}, m.$postLink = function() {
21400+
=======
21401+
var e = new RegExp("^[A-Za-z_]{1}[A-Za-z0-9_]*$");
21402+
m.hasInvalidEnvVars = _.some(m.secret.data, function(t, n) {
21403+
return !e.test(n);
21404+
});
21405+
};
21406+
var g = function(e) {
21407+
return m.attachAllContainers || m.attachContainers[e.name];
21408+
};
21409+
m.$postLink = function() {
21410+
>>>>>>> Allow the user to select containers when adding a secret to an application
2139921411
t.$watch(function() {
2140021412
return m.application;
2140121413
}, function() {
2140221414
var e = _.get(m.application, "spec.template");
21403-
m.existingMountPaths = i.getMountPaths(e);
21415+
m.existingMountPaths = i.getMountPaths(e), m.attachAllContainers = !0;
2140421416
});
2140521417
}, m.addToApplication = function() {
2140621418
var t = angular.copy(m.application), i = _.get(t, "spec.template");
@@ -21411,7 +21423,7 @@ name: m.secret.metadata.name
2141121423
}
2141221424
};
2141321425
_.each(i.spec.containers, function(e) {
21414-
e.envFrom = e.envFrom || [], e.envFrom.push(s);
21426+
g(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
2141521427
});
2141621428
} else {
2141721429
var c = e("generateName")(m.secret.metadata.name + "-"), l = {
@@ -21420,7 +21432,7 @@ mountPath: m.mountVolume,
2142021432
readOnly: !0
2142121433
};
2142221434
_.each(i.spec.containers, function(e) {
21423-
e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l);
21435+
g(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(l));
2142421436
});
2142521437
var u = {
2142621438
name: c,
@@ -21430,10 +21442,10 @@ secretName: m.secret.metadata.name
2143021442
};
2143121443
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(u);
2143221444
}
21433-
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), g = {
21445+
var d = e("humanizeKind"), p = d(m.secret.kind), f = d(t.kind), h = {
2143421446
namespace: m.project.metadata.name
2143521447
};
21436-
a.update(n.kindToResource(t.kind), t.metadata.name, t, g).then(function() {
21448+
a.update(n.kindToResource(t.kind), t.metadata.name, t, h).then(function() {
2143721449
o.addNotification({
2143821450
type: "success",
2143921451
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
@@ -6518,6 +6518,19 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
65186518
"</div>\n" +
65196519
"</div>\n" +
65206520
"</div>\n" +
6521+
"<legend ng-if-start=\"ctrl.application.spec.template.spec.containers.length > 1\">Containers:</legend>\n" +
6522+
"<div ng-if-end class=\"form-group container-options\">\n" +
6523+
"<div ng-if=\"ctrl.attachAllContainers\">\n" +
6524+
"The secret will be added to all containers. You can\n" +
6525+
"<a href=\"\" ng-click=\"ctrl.attachAllContainers = false\">select specific containers</a>\n" +
6526+
"instead.\n" +
6527+
"</div>\n" +
6528+
"<div ng-if=\"!ctrl.attachAllContainers\" class=\"form-group\">\n" +
6529+
"<label class=\"sr-only required\">Containers</label>\n" +
6530+
"<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" +
6531+
"</select-containers>\n" +
6532+
"</div>\n" +
6533+
"</div>\n" +
65216534
"<div class=\"button-group pull-right\">\n" +
65226535
<<<<<<< 579cbe4ce2e640c919f9687b5c885f661897db96
65236536
"<button class=\"btn btn-default\" ng-class=\"{'dialog-btn': isDialog}\" ng-click=\"ctrl.onCancel()\" translate>\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)