Skip to content

Commit 748b6a6

Browse files
committed
Should not be able to add the same secret or config map to an application twice
1 parent 5e7f02a commit 748b6a6

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

app/scripts/directives/addConfigToApplication.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,35 @@
2626
var ctrl = this;
2727
var humanizeKind = $filter('humanizeKind');
2828

29+
var checkContainerForRef = function(container) {
30+
var addRefName = ctrl.apiObject.metadata.name;
31+
if (ctrl.apiObject.kind === "ConfigMap") {
32+
return _.find(container.envFrom, {configMapRef: {name: addRefName}});
33+
} else {
34+
return _.find(container.envFrom, {secretRef: {name: addRefName}});
35+
}
36+
};
37+
38+
var checkApplicationContainersRefs = function(applications) {
39+
var applicationsWithoutRef = [];
40+
41+
_.each(applications, function(application) {
42+
_.each(_.get(application, 'spec.template.spec.containers'), function(container) {
43+
if (!checkContainerForRef(container)) {
44+
applicationsWithoutRef.push(application);
45+
return false;
46+
}
47+
});
48+
});
49+
return applicationsWithoutRef;
50+
};
51+
2952
var getApplications = function() {
3053
var context = {
3154
namespace: ctrl.project.metadata.name
3255
};
3356
ApplicationsService.getApplications(context).then(function(applications) {
34-
ctrl.applications = applications;
57+
ctrl.applications = checkApplicationContainersRefs(applications);
3558
ctrl.updating = false;
3659
});
3760
};
@@ -91,7 +114,7 @@
91114

92115
// For each container, add the new volume mount.
93116
_.each(podTemplate.spec.containers, function(container) {
94-
if (isContainerSelected(container)) {
117+
if (isContainerSelected(container) && !checkContainerForRef(container)) {
95118
container.envFrom = container.envFrom || [];
96119
container.envFrom.push(newEnvFrom);
97120
}

dist/scripts/scripts.js

+30-12
Original file line numberDiff line numberDiff line change
@@ -10991,22 +10991,40 @@ templateUrl: "views/directives/action-chip.html"
1099110991
}), function() {
1099210992
angular.module("openshiftConsole").component("addConfigToApplication", {
1099310993
controller: [ "$filter", "$scope", "APIService", "ApplicationsService", "DataService", "Navigate", "NotificationsService", "StorageService", function(e, t, n, a, r, o, i, s) {
10994-
var c = this, l = e("humanizeKind"), u = function() {
10994+
var c = this, l = e("humanizeKind"), u = function(e) {
10995+
var t = c.apiObject.metadata.name;
10996+
return "ConfigMap" === c.apiObject.kind ? _.find(e.envFrom, {
10997+
configMapRef: {
10998+
name: t
10999+
}
11000+
}) : _.find(e.envFrom, {
11001+
secretRef: {
11002+
name: t
11003+
}
11004+
});
11005+
}, d = function(e) {
11006+
var t = [];
11007+
return _.each(e, function(e) {
11008+
_.each(_.get(e, "spec.template.spec.containers"), function(n) {
11009+
if (!u(n)) return t.push(e), !1;
11010+
});
11011+
}), t;
11012+
}, m = function() {
1099511013
var e = {
1099611014
namespace: c.project.metadata.name
1099711015
};
1099811016
a.getApplications(e).then(function(e) {
10999-
c.applications = e, c.updating = !1;
11017+
c.applications = d(e), c.updating = !1;
1100011018
});
1100111019
};
1100211020
c.$onInit = function() {
11003-
c.addType = "env", c.disableInputs = !1, u();
11021+
c.addType = "env", c.disableInputs = !1, m();
1100411022
var e = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
1100511023
c.hasInvalidEnvVars = _.some(c.apiObject.data, function(t, n) {
1100611024
return !e.test(n);
1100711025
});
1100811026
};
11009-
var d = function(e) {
11027+
var p = function(e) {
1101011028
return c.attachAllContainers || c.attachContainers[e.name];
1101111029
};
1101211030
c.$postLink = function() {
@@ -11035,16 +11053,16 @@ name: c.apiObject.metadata.name
1103511053
};
1103611054
}
1103711055
_.each(a.spec.containers, function(e) {
11038-
d(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
11056+
p(e) && !u(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
1103911057
});
1104011058
} else {
11041-
var l = e("generateName")(c.apiObject.metadata.name + "-"), u = {
11059+
var l = e("generateName")(c.apiObject.metadata.name + "-"), d = {
1104211060
name: l,
1104311061
mountPath: c.mountVolume,
1104411062
readOnly: !0
1104511063
};
1104611064
_.each(a.spec.containers, function(e) {
11047-
d(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(u));
11065+
p(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(d));
1104811066
});
1104911067
var m = {
1105011068
name: l
@@ -11063,23 +11081,23 @@ name: c.apiObject.metadata.name
1106311081
}
1106411082
a.spec.volumes = a.spec.volumes || [], a.spec.volumes.push(m);
1106511083
}
11066-
var p = e("humanizeKind"), f = p(c.apiObject.kind), g = p(t.kind), v = {
11084+
var f = e("humanizeKind"), g = f(c.apiObject.kind), v = f(t.kind), h = {
1106711085
namespace: c.project.metadata.name
1106811086
};
11069-
r.update(n.kindToResource(t.kind), t.metadata.name, t, v).then(function() {
11087+
r.update(n.kindToResource(t.kind), t.metadata.name, t, h).then(function() {
1107011088
i.addNotification({
1107111089
type: "success",
11072-
message: "Successfully added " + f + " " + c.apiObject.metadata.name + " to " + g + " " + t.metadata.name + ".",
11090+
message: "Successfully added " + g + " " + c.apiObject.metadata.name + " to " + v + " " + t.metadata.name + ".",
1107311091
links: [ {
1107411092
href: o.resourceURL(t),
11075-
label: "View " + p(t.kind, !0)
11093+
label: "View " + f(t.kind, !0)
1107611094
} ]
1107711095
}), angular.isFunction(c.onComplete) && c.onComplete();
1107811096
}, function(n) {
1107911097
var a = e("getErrorDetails");
1108011098
i.addNotification({
1108111099
type: "error",
11082-
message: "An error occurred adding " + f + " " + c.apiObject.metadata.name + " to " + g + " " + t.metadata.name + ". " + a(n)
11100+
message: "An error occurred adding " + g + " " + c.apiObject.metadata.name + " to " + v + " " + t.metadata.name + ". " + a(n)
1108311101
});
1108411102
}).finally(function() {
1108511103
c.disableInputs = !1;

0 commit comments

Comments
 (0)