Skip to content

Commit

Permalink
Should not be able to add the same secret or config map to an applica…
Browse files Browse the repository at this point in the history
…tion twice
  • Loading branch information
jhadvig committed Oct 11, 2017
1 parent 5e7f02a commit 748b6a6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
27 changes: 25 additions & 2 deletions app/scripts/directives/addConfigToApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,35 @@
var ctrl = this;
var humanizeKind = $filter('humanizeKind');

var checkContainerForRef = function(container) {
var addRefName = ctrl.apiObject.metadata.name;
if (ctrl.apiObject.kind === "ConfigMap") {
return _.find(container.envFrom, {configMapRef: {name: addRefName}});
} else {
return _.find(container.envFrom, {secretRef: {name: addRefName}});
}
};

var checkApplicationContainersRefs = function(applications) {
var applicationsWithoutRef = [];

_.each(applications, function(application) {
_.each(_.get(application, 'spec.template.spec.containers'), function(container) {
if (!checkContainerForRef(container)) {
applicationsWithoutRef.push(application);
return false;
}
});
});
return applicationsWithoutRef;
};

var getApplications = function() {
var context = {
namespace: ctrl.project.metadata.name
};
ApplicationsService.getApplications(context).then(function(applications) {
ctrl.applications = applications;
ctrl.applications = checkApplicationContainersRefs(applications);
ctrl.updating = false;
});
};
Expand Down Expand Up @@ -91,7 +114,7 @@

// For each container, add the new volume mount.
_.each(podTemplate.spec.containers, function(container) {
if (isContainerSelected(container)) {
if (isContainerSelected(container) && !checkContainerForRef(container)) {
container.envFrom = container.envFrom || [];
container.envFrom.push(newEnvFrom);
}
Expand Down
42 changes: 30 additions & 12 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10991,22 +10991,40 @@ templateUrl: "views/directives/action-chip.html"
}), function() {
angular.module("openshiftConsole").component("addConfigToApplication", {
controller: [ "$filter", "$scope", "APIService", "ApplicationsService", "DataService", "Navigate", "NotificationsService", "StorageService", function(e, t, n, a, r, o, i, s) {
var c = this, l = e("humanizeKind"), u = function() {
var c = this, l = e("humanizeKind"), u = function(e) {
var t = c.apiObject.metadata.name;
return "ConfigMap" === c.apiObject.kind ? _.find(e.envFrom, {
configMapRef: {
name: t
}
}) : _.find(e.envFrom, {
secretRef: {
name: t
}
});
}, d = function(e) {
var t = [];
return _.each(e, function(e) {
_.each(_.get(e, "spec.template.spec.containers"), function(n) {
if (!u(n)) return t.push(e), !1;
});
}), t;
}, m = function() {
var e = {
namespace: c.project.metadata.name
};
a.getApplications(e).then(function(e) {
c.applications = e, c.updating = !1;
c.applications = d(e), c.updating = !1;
});
};
c.$onInit = function() {
c.addType = "env", c.disableInputs = !1, u();
c.addType = "env", c.disableInputs = !1, m();
var e = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
c.hasInvalidEnvVars = _.some(c.apiObject.data, function(t, n) {
return !e.test(n);
});
};
var d = function(e) {
var p = function(e) {
return c.attachAllContainers || c.attachContainers[e.name];
};
c.$postLink = function() {
Expand Down Expand Up @@ -11035,16 +11053,16 @@ name: c.apiObject.metadata.name
};
}
_.each(a.spec.containers, function(e) {
d(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
p(e) && !u(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s));
});
} else {
var l = e("generateName")(c.apiObject.metadata.name + "-"), u = {
var l = e("generateName")(c.apiObject.metadata.name + "-"), d = {
name: l,
mountPath: c.mountVolume,
readOnly: !0
};
_.each(a.spec.containers, function(e) {
d(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(u));
p(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(d));
});
var m = {
name: l
Expand All @@ -11063,23 +11081,23 @@ name: c.apiObject.metadata.name
}
a.spec.volumes = a.spec.volumes || [], a.spec.volumes.push(m);
}
var p = e("humanizeKind"), f = p(c.apiObject.kind), g = p(t.kind), v = {
var f = e("humanizeKind"), g = f(c.apiObject.kind), v = f(t.kind), h = {
namespace: c.project.metadata.name
};
r.update(n.kindToResource(t.kind), t.metadata.name, t, v).then(function() {
r.update(n.kindToResource(t.kind), t.metadata.name, t, h).then(function() {
i.addNotification({
type: "success",
message: "Successfully added " + f + " " + c.apiObject.metadata.name + " to " + g + " " + t.metadata.name + ".",
message: "Successfully added " + g + " " + c.apiObject.metadata.name + " to " + v + " " + t.metadata.name + ".",
links: [ {
href: o.resourceURL(t),
label: "View " + p(t.kind, !0)
label: "View " + f(t.kind, !0)
} ]
}), angular.isFunction(c.onComplete) && c.onComplete();
}, function(n) {
var a = e("getErrorDetails");
i.addNotification({
type: "error",
message: "An error occurred adding " + f + " " + c.apiObject.metadata.name + " to " + g + " " + t.metadata.name + ". " + a(n)
message: "An error occurred adding " + g + " " + c.apiObject.metadata.name + " to " + v + " " + t.metadata.name + ". " + a(n)
});
}).finally(function() {
c.disableInputs = !1;
Expand Down

0 comments on commit 748b6a6

Please sign in to comment.