diff --git a/app/scripts/directives/addConfigToApplication.js b/app/scripts/directives/addConfigToApplication.js index 2d471fca3c..071bf4f35e 100644 --- a/app/scripts/directives/addConfigToApplication.js +++ b/app/scripts/directives/addConfigToApplication.js @@ -26,6 +26,20 @@ var ctrl = this; var humanizeKind = $filter('humanizeKind'); + var conatinerHasRef = function(container) { + var addRefName = ctrl.apiObject.metadata.name; + if (ctrl.apiObject.kind === "ConfigMap") { + return _.some(container.envFrom, {configMapRef: {name: addRefName}}); + } else { + return _.some(container.envFrom, {secretRef: {name: addRefName}}); + } + }; + + ctrl.checkApplicationContainersRefs = function(application) { + var containers = _.get(application, 'spec.template.spec.containers'); + ctrl.canAddRefToApplication = !_.every(containers, conatinerHasRef); + }; + var getApplications = function() { var context = { namespace: ctrl.project.metadata.name @@ -91,7 +105,7 @@ // For each container, add the new volume mount. _.each(podTemplate.spec.containers, function(container) { - if (isContainerSelected(container)) { + if (isContainerSelected(container) && !conatinerHasRef(container)) { container.envFrom = container.envFrom || []; container.envFrom.push(newEnvFrom); } diff --git a/app/styles/_add-config-to-application.less b/app/styles/_add-config-to-application.less index 98b81d3b66..8c3b61ccf2 100644 --- a/app/styles/_add-config-to-application.less +++ b/app/styles/_add-config-to-application.less @@ -48,8 +48,8 @@ } } - .env-warning { - margin-left: 20px; + .help-block { + margin-bottom: 10px; } .updating { diff --git a/app/views/directives/add-config-to-application.html b/app/views/directives/add-config-to-application.html index 90ab01f224..54298f3e1d 100644 --- a/app/views/directives/add-config-to-application.html +++ b/app/views/directives/add-config-to-application.html @@ -6,9 +6,9 @@

Add to Application

Add this {{ctrl.apiObject.kind | humanizeKind}} to application: -
+
- + {{$select.selected.metadata.name}} @@ -23,6 +23,11 @@

Add to Application

+
+ + The {{ctrl.apiObject.kind | humanizeKind}} has already been added to this application. + +
Add {{ctrl.apiObject.kind | humanizeKind}} as:
@@ -31,12 +36,8 @@

Add to Application

Environment variables -
- - Some of the keys for {{ctrl.apiObject.kind | humanizeKind}} - {{ctrl.apiObject.metadata.name}} are not - valid environment variable names and will not be - added. +
+ Some of the keys for {{ctrl.apiObject.kind | humanizeKind}} {{ctrl.apiObject.metadata.name}} are not valid environment variable names and will not be added.
@@ -56,7 +57,7 @@

Add to Application

ng-pattern="/^\/.*$/" osc-unique="ctrl.existingMountPaths" aria-describedby="mount-path-help" - ng-disabled="ctrl.addType !== 'volume' || ctrl.disableInputs" + ng-disabled="ctrl.addType !== 'volume' || ctrl.disableInputs || !ctrl.application" ng-model="ctrl.mountVolume" autocorrect="off" autocapitalize="off" @@ -80,21 +81,23 @@

Add to Application

- Containers: -
-
- The {{ctrl.apiObject.kind | humanizeKind}} will be added to all containers. You can - select specific containers - instead. -
-
- - - +
+ Containers: +
+
+ The {{ctrl.apiObject.kind | humanizeKind}} will be added to all containers. You can + select specific containers + instead. +
+
+ + + +
@@ -108,7 +111,7 @@

Add to Application

class="btn btn-primary" ng-class="{'dialog-btn': isDialog}" ng-click="ctrl.addToApplication()" - ng-disabled="ctrl.addType === 'volume' && addToApplicationForm.$invalid || !ctrl.application" + ng-disabled="addToApplicationForm.$invalid || (ctrl.addType === 'env' && !ctrl.canAddRefToApplication)" value=""> Save diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index 940cf80faf..c43757aa2f 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -10993,7 +10993,23 @@ 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 ? _.some(e.envFrom, { +configMapRef: { +name: t +} +}) : _.some(e.envFrom, { +secretRef: { +name: t +} +}); +}; +c.checkApplicationContainersRefs = function(e) { +var t = _.get(e, "spec.template.spec.containers"); +c.canAddRefToApplication = !_.every(t, u); +}; +var d = function() { var e = { namespace: c.project.metadata.name }; @@ -11002,13 +11018,13 @@ c.applications = e, c.updating = !1; }); }; c.$onInit = function() { -c.addType = "env", c.disableInputs = !1, u(); +c.addType = "env", c.disableInputs = !1, d(); 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 m = function(e) { return c.attachAllContainers || c.attachContainers[e.name]; }; c.$postLink = function() { @@ -11037,51 +11053,51 @@ name: c.apiObject.metadata.name }; } _.each(a.spec.containers, function(e) { -d(e) && (e.envFrom = e.envFrom || [], e.envFrom.push(s)); +m(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)); +m(e) && (e.volumeMounts = e.volumeMounts || [], e.volumeMounts.push(d)); }); -var m = { +var p = { name: l }; switch (c.apiObject.kind) { case "Secret": -m.secret = { +p.secret = { secretName: c.apiObject.metadata.name }; break; case "ConfigMap": -m.configMap = { +p.configMap = { name: c.apiObject.metadata.name }; } -a.spec.volumes = a.spec.volumes || [], a.spec.volumes.push(m); +a.spec.volumes = a.spec.volumes || [], a.spec.volumes.push(p); } -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; diff --git a/dist/scripts/templates.js b/dist/scripts/templates.js index 5e08d1db74..b12872c410 100644 --- a/dist/scripts/templates.js +++ b/dist/scripts/templates.js @@ -5677,9 +5677,9 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "
\n" + "Add this {{ctrl.apiObject.kind | humanizeKind}} to application:\n" + - "
\n" + + "
\n" + "
\n" + - "\n" + + "\n" + "\n" + "\n" + "{{$select.selected.metadata.name}}\n" + @@ -5692,6 +5692,11 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "
\n" + "
\n" + + "
\n" + + "\n" + + "The {{ctrl.apiObject.kind | humanizeKind}} has already been added to this application.\n" + + "\n" + + "
\n" + "Add {{ctrl.apiObject.kind | humanizeKind}} as:\n" + "
\n" + "
\n" + @@ -5700,10 +5705,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "Environment variables\n" + "\n" + - "
\n" + - "\n" + - "Some of the keys for {{ctrl.apiObject.kind | humanizeKind}}\n" + - "{{ctrl.apiObject.metadata.name}} are not valid environment variable names and will not be added.\n" + + "
\n" + + "Some of the keys for {{ctrl.apiObject.kind | humanizeKind}} {{ctrl.apiObject.metadata.name}} are not valid environment variable names and will not be added.\n" + "
\n" + "
\n" + "
\n" + @@ -5714,7 +5717,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "
\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "Mount Path for the volume. A file will be created in this directory for each key from the {{ctrl.apiObject.kind | humanizeKind}}. The file contents will be the value of the key.\n" + @@ -5732,6 +5735,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "
\n" + "
\n" + "
\n" + + "
\n" + " 1\">Containers:\n" + "
\n" + "
\n" + @@ -5745,11 +5749,12 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "\n" + "
\n" + "
\n" + + "
\n" + "
\n" + "\n" + - "\n" + "
\n" + diff --git a/dist/styles/main.css b/dist/styles/main.css index 1cc63e8bee..a5c0099e5a 100644 --- a/dist/styles/main.css +++ b/dist/styles/main.css @@ -5957,11 +5957,11 @@ notification-drawer-wrapper .expanded-notification.unread .drawer-pf-notificatio .add-config-to-application .container-options .select-container .checkbox:first-of-type{margin-top:0} .add-config-to-application .dialog-title{border-bottom:1px solid #d1d1d1} .add-config-to-application .dialog-title h3{margin:18px 0;padding-left:15px} +.add-config-to-application .dialog-body .add-choice,.add-config-to-application .help-block{margin-bottom:10px} .add-config-to-application .dialog-body{padding:20px} -.add-config-to-application .dialog-body .add-choice{margin-bottom:10px} .add-config-to-application .dialog-body .button-group .btn{margin-left:10px} .add-config-to-application .dialog-body .button-group .btn:first-of-type{margin-left:0} -.add-config-to-application .env-warning,.add-config-to-application .volume-options{margin-left:20px} .add-config-to-application .dialog-body legend{border-bottom:0;font-size:14px;font-weight:600;margin-bottom:10px} .add-config-to-application .dialog-body .radio{margin-top:0} -.add-config-to-application .updating{background-color:#fff;bottom:55px;left:0;padding-top:60px;position:absolute;right:0;top:55px;z-index:1000} \ No newline at end of file +.add-config-to-application .updating{background-color:#fff;bottom:55px;left:0;padding-top:60px;position:absolute;right:0;top:55px;z-index:1000} +.add-config-to-application .volume-options{margin-left:20px} \ No newline at end of file