Skip to content

Commit 4871bef

Browse files
committed
Create new config maps and secrets when adding config files
Let users create a new config map or secret directly from the "add config files" page.
1 parent f892e0a commit 4871bef

File tree

6 files changed

+118
-99
lines changed

6 files changed

+118
-99
lines changed

app/scripts/controllers/addConfigVolume.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
angular.module('openshiftConsole')
1111
.controller('AddConfigVolumeController',
1212
function($filter,
13+
$location,
1314
$routeParams,
1415
$scope,
1516
$window,
@@ -59,6 +60,9 @@ angular.module('openshiftConsole')
5960
includeProject: true
6061
});
6162

63+
// Return URL for creating secrets.
64+
$scope.returnURL = $location.url();
65+
6266
var humanizeKind = $filter('humanizeKind');
6367
$scope.groupByKind = function(object) {
6468
return humanizeKind(object.kind);

app/scripts/controllers/createSecret.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('CreateSecretController', function ($filter, $routeParams, $scope, $window, AlertMessageService, ApplicationGenerator, DataService, Navigate, ProjectsService) {
11+
.controller('CreateSecretController', function ($filter, $location, $routeParams, $scope, $window, AlertMessageService, ApplicationGenerator, DataService, Navigate, ProjectsService) {
1212
$scope.alerts = {};
1313
$scope.projectName = $routeParams.project;
1414

@@ -26,6 +26,15 @@ angular.module('openshiftConsole')
2626
}
2727
];
2828

29+
var navigateBack = function() {
30+
if ($routeParams.then) {
31+
$location.url($routeParams.then);
32+
return;
33+
}
34+
35+
Navigate.toResourceList('secrets', $scope.projectName);
36+
};
37+
2938
ProjectsService
3039
.get($routeParams.project)
3140
.then(_.spread(function(project, context) {
@@ -37,10 +46,9 @@ angular.module('openshiftConsole')
3746
_.each(creationAlerts, function(alert) {
3847
AlertMessageService.addAlert(alert);
3948
});
40-
Navigate.toResourceList('secrets', $scope.projectName);
41-
};
42-
$scope.cancel = function() {
43-
Navigate.toResourceList('secrets', $scope.projectName);
49+
navigateBack();
4450
};
51+
52+
$scope.cancel = navigateBack;
4553
}));
4654
});

app/scripts/filters/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,4 +657,7 @@ angular.module('openshiftConsole')
657657
// Wrap matches in a `mark` element to use the Bootstrap / Patternfly highlight styles.
658658
return escapedStr.replace(regex, '<mark>$&</mark>');
659659
};
660+
})
661+
.filter('encodeURIComponent', function() {
662+
return window.encodeURIComponent;
660663
});

app/views/add-config-volume.html

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ <h2>The {{kind | humanizeKind}} could not be loaded.</h2>
2222
</div>
2323

2424
<div ng-if="targetObject && configMaps && secrets">
25-
<div ng-if="!configMaps.length && !secrets.length" class="empty-state-message empty-state-full-page">
26-
<h2 class="text-center">No config maps or secrets.</h2>
27-
28-
<p class="gutter-top">
29-
There are no config maps or secrets in project {{project | displayName}} to use
30-
as a volume for this {{kind | humanizeKind}}.
31-
</p>
32-
33-
<p ng-if="targetObject"><a ng-href="{{targetObject | navigateResourceURL}}">Back to {{kind | humanizeKind}} {{name}}</a></p>
34-
</div>
35-
36-
<div ng-if="configMaps.length || secrets.length" class="mar-top-xl">
25+
<div class="mar-top-xl">
3726
<h1>Add Config Files</h1>
3827
<div class="help-block">
3928
Add values from a config map or secret as volume. This will make the data available as files for {{kind | humanizeKind}} {{name}}.
@@ -55,6 +44,15 @@ <h1>Add Config Files</h1>
5544
<span ng-bind-html="source.metadata.name | highlight : $select.search"></span>
5645
</ui-select-choices>
5746
</ui-select>
47+
<div ng-if="('configmaps' | canI : 'create') || ('secrets' | canI : 'create')" class="mar-top-md">
48+
<span ng-if="'configmaps' | canI : 'create'">
49+
<a ng-href="project/{{project.metadata.name}}/create-config-map">Create config map</a>
50+
</span>
51+
<span ng-if="'secrets' | canI : 'create'">
52+
<span ng-if="'configmaps' | canI : 'create'" class="action-divider" aria-hidden="true">|</span>
53+
<a ng-href="project/{{project.metadata.name}}/create-secret?then={{returnURL | encodeURIComponent}}">Create Secret</a>
54+
</span>
55+
</div>
5856
<div class="help-block">
5957
Pick the config source. Its data will be mounted as a volume in the container.
6058
</div>

dist/scripts/scripts.js

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6237,23 +6237,25 @@ details:"Reason: " + b("getErrorDetails")(a)
62376237
};
62386238
});
62396239
}));
6240-
} ]), angular.module("openshiftConsole").controller("CreateSecretController", [ "$filter", "$routeParams", "$scope", "$window", "AlertMessageService", "ApplicationGenerator", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
6241-
c.alerts = {}, c.projectName = b.project, c.breadcrumbs = [ {
6242-
title:c.projectName,
6243-
link:"project/" + c.projectName
6240+
} ]), angular.module("openshiftConsole").controller("CreateSecretController", [ "$filter", "$location", "$routeParams", "$scope", "$window", "AlertMessageService", "ApplicationGenerator", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i, j) {
6241+
d.alerts = {}, d.projectName = c.project, d.breadcrumbs = [ {
6242+
title:d.projectName,
6243+
link:"project/" + d.projectName
62446244
}, {
62456245
title:"Secrets",
6246-
link:"project/" + c.projectName + "/browse/secrets"
6246+
link:"project/" + d.projectName + "/browse/secrets"
62476247
}, {
62486248
title:"Create Secret"
6249-
} ], i.get(b.project).then(_.spread(function(b, d) {
6250-
c.project = b, c.context = d, c.breadcrumbs[0].title = a("displayName")(b), c.postCreateAction = function(a, b) {
6251-
_.each(b, function(a) {
6252-
e.addAlert(a);
6253-
}), h.toResourceList("secrets", c.projectName);
6254-
}, c.cancel = function() {
6255-
h.toResourceList("secrets", c.projectName);
6249+
} ];
6250+
var k = function() {
6251+
return c.then ? void b.url(c.then) :void i.toResourceList("secrets", d.projectName);
62566252
};
6253+
j.get(c.project).then(_.spread(function(b, c) {
6254+
d.project = b, d.context = c, d.breadcrumbs[0].title = a("displayName")(b), d.postCreateAction = function(a, b) {
6255+
_.each(b, function(a) {
6256+
f.addAlert(a);
6257+
}), k();
6258+
}, d.cancel = k;
62576259
}));
62586260
} ]), angular.module("openshiftConsole").controller("ConfigMapsController", [ "$scope", "$routeParams", "AlertMessageService", "DataService", "LabelFilter", "ProjectsService", function(a, b, c, d, e, f) {
62596261
a.projectName = b.project, a.alerts = a.alerts || {}, a.loaded = !1, a.labelSuggestions = {}, c.getAlerts().forEach(function(b) {
@@ -8208,115 +8210,115 @@ n("An error occurred attaching the persistent volume claim to the " + a("humaniz
82088210
}
82098211
};
82108212
}));
8211-
} ]), angular.module("openshiftConsole").controller("AddConfigVolumeController", [ "$filter", "$routeParams", "$scope", "$window", "APIService", "BreadcrumbsService", "DataService", "Navigate", "ProjectsService", "StorageService", function(a, b, c, d, e, f, g, h, i, j) {
8212-
if (!b.kind || !b.name) return void h.toErrorPage("Kind or name parameter missing.");
8213-
var k = [ "Deployment", "DeploymentConfig", "ReplicaSet", "ReplicationController" ];
8214-
if (!_.includes(k, b.kind)) return void h.toErrorPage("Volumes are not supported for kind " + b.kind + ".");
8215-
var l = {
8216-
resource:e.kindToResource(b.kind),
8217-
group:b.group
8213+
} ]), angular.module("openshiftConsole").controller("AddConfigVolumeController", [ "$filter", "$location", "$routeParams", "$scope", "$window", "APIService", "BreadcrumbsService", "DataService", "Navigate", "ProjectsService", "StorageService", function(a, b, c, d, e, f, g, h, i, j, k) {
8214+
if (!c.kind || !c.name) return void i.toErrorPage("Kind or name parameter missing.");
8215+
var l = [ "Deployment", "DeploymentConfig", "ReplicaSet", "ReplicationController" ];
8216+
if (!_.includes(l, c.kind)) return void i.toErrorPage("Volumes are not supported for kind " + c.kind + ".");
8217+
var m = {
8218+
resource:f.kindToResource(c.kind),
8219+
group:c.group
82188220
};
8219-
c.alerts = {}, c.projectName = b.project, c.kind = b.kind, c.name = b.name, c.attach = {
8221+
d.alerts = {}, d.projectName = c.project, d.kind = c.kind, d.name = c.name, d.attach = {
82208222
allContainers:!0,
82218223
pickKeys:!1
8222-
}, c.forms = {}, c.breadcrumbs = f.getBreadcrumbs({
8223-
name:b.name,
8224-
kind:b.kind,
8225-
namespace:b.project,
8224+
}, d.forms = {}, d.breadcrumbs = g.getBreadcrumbs({
8225+
name:c.name,
8226+
kind:c.kind,
8227+
namespace:c.project,
82268228
subpage:"Add Config Files",
82278229
includeProject:!0
8228-
});
8229-
var m = a("humanizeKind");
8230-
c.groupByKind = function(a) {
8231-
return m(a.kind);
8230+
}), d.returnURL = b.url();
8231+
var n = a("humanizeKind");
8232+
d.groupByKind = function(a) {
8233+
return n(a.kind);
82328234
};
8233-
var n = function() {
8234-
_.set(c, "attach.items", [ {} ]);
8235-
};
8236-
c.$watch("attach.source", n);
82378235
var o = function() {
8238-
c.forms.addConfigVolumeForm.$setDirty();
8239-
};
8240-
c.addItem = function() {
8241-
c.attach.items.push({}), o();
8242-
}, c.removeItem = function(a) {
8243-
c.attach.items.splice(a, 1), o();
8244-
}, i.get(b.project).then(_.spread(function(e, h) {
8245-
c.project = e;
8246-
var i = a("orderByDisplayName"), k = a("getErrorDetails"), m = a("generateName"), n = function(a, b) {
8247-
c.alerts["attach-persistent-volume-claim"] = {
8236+
_.set(d, "attach.items", [ {} ]);
8237+
};
8238+
d.$watch("attach.source", o);
8239+
var p = function() {
8240+
d.forms.addConfigVolumeForm.$setDirty();
8241+
};
8242+
d.addItem = function() {
8243+
d.attach.items.push({}), p();
8244+
}, d.removeItem = function(a) {
8245+
d.attach.items.splice(a, 1), p();
8246+
}, j.get(c.project).then(_.spread(function(b, f) {
8247+
d.project = b;
8248+
var i = a("orderByDisplayName"), j = a("getErrorDetails"), l = a("generateName"), n = function(a, b) {
8249+
d.alerts["attach-persistent-volume-claim"] = {
82488250
type:"error",
82498251
message:a,
82508252
details:b
82518253
};
82528254
};
8253-
g.get(l, b.name, h, {
8255+
h.get(m, c.name, f, {
82548256
errorNotification:!1
82558257
}).then(function(a) {
8256-
c.targetObject = a, c.breadcrumbs = f.getBreadcrumbs({
8258+
d.targetObject = a, d.breadcrumbs = g.getBreadcrumbs({
82578259
object:a,
8258-
project:e,
8260+
project:b,
82598261
subpage:"Add Config Files",
82608262
includeProject:!0
82618263
});
82628264
}, function(a) {
8263-
c.error = a;
8264-
}), g.list("configmaps", h, null, {
8265+
d.error = a;
8266+
}), h.list("configmaps", f, null, {
82658267
errorNotification:!1
82668268
}).then(function(a) {
8267-
c.configMaps = i(a.by("metadata.name"));
8269+
d.configMaps = i(a.by("metadata.name"));
82688270
}, function(a) {
8269-
return 403 === a.status ? void (c.configMaps = []) :void n("Could not load config maps", k(a));
8270-
}), g.list("secrets", h, null, {
8271+
return 403 === a.status ? void (d.configMaps = []) :void n("Could not load config maps", j(a));
8272+
}), h.list("secrets", f, null, {
82718273
errorNotification:!1
82728274
}).then(function(a) {
8273-
c.secrets = i(a.by("metadata.name"));
8275+
d.secrets = i(a.by("metadata.name"));
82748276
}, function(a) {
8275-
return 403 === a.status ? void (c.secrets = []) :void n("Could not load secrets", k(a));
8277+
return 403 === a.status ? void (d.secrets = []) :void n("Could not load secrets", j(a));
82768278
});
82778279
var o = function(a) {
8278-
return c.attach.allContainers || c.attach.containers[a.name];
8280+
return d.attach.allContainers || d.attach.containers[a.name];
82798281
}, p = function() {
8280-
var a = _.get(c, "targetObject.spec.template");
8281-
c.existingMountPaths = j.getMountPaths(a, o);
8282+
var a = _.get(d, "targetObject.spec.template");
8283+
d.existingMountPaths = k.getMountPaths(a, o);
82828284
};
8283-
c.$watchGroup([ "targetObject", "attach.allContainers" ], p), c.$watch("attach.containers", p, !0);
8285+
d.$watchGroup([ "targetObject", "attach.allContainers" ], p), d.$watch("attach.containers", p, !0);
82848286
var q = function() {
8285-
var a = _.map(c.attach.items, "path");
8286-
c.itemPaths = _.compact(a);
8287+
var a = _.map(d.attach.items, "path");
8288+
d.itemPaths = _.compact(a);
82878289
};
8288-
c.$watch("attach.items", q, !0), c.addVolume = function() {
8289-
if (!c.forms.addConfigVolumeForm.$invalid) {
8290-
var e = c.targetObject, f = _.get(c, "attach.source"), i = _.get(e, "spec.template"), j = m("volume-"), p = _.get(c, "attach.mountPath"), q = {
8291-
name:j,
8290+
d.$watch("attach.items", q, !0), d.addVolume = function() {
8291+
if (!d.forms.addConfigVolumeForm.$invalid) {
8292+
var b = d.targetObject, g = _.get(d, "attach.source"), i = _.get(b, "spec.template"), k = l("volume-"), p = _.get(d, "attach.mountPath"), q = {
8293+
name:k,
82928294
mountPath:p
82938295
};
8294-
"Secret" === f.kind && (q.readOnly = !0), _.each(i.spec.containers, function(a) {
8296+
"Secret" === g.kind && (q.readOnly = !0), _.each(i.spec.containers, function(a) {
82958297
o(a) && (a.volumeMounts = a.volumeMounts || [], a.volumeMounts.push(q));
82968298
});
82978299
var r, s = {
8298-
name:j
8300+
name:k
82998301
};
8300-
switch (c.attach.pickKeys && (r = c.attach.items), f.kind) {
8302+
switch (d.attach.pickKeys && (r = d.attach.items), g.kind) {
83018303
case "ConfigMap":
83028304
s.configMap = {
8303-
name:f.metadata.name,
8305+
name:g.metadata.name,
83048306
items:r
83058307
};
83068308
break;
83078309

83088310
case "Secret":
83098311
s.secret = {
8310-
secretName:f.metadata.name,
8312+
secretName:g.metadata.name,
83118313
items:r
83128314
};
83138315
}
8314-
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(s), c.alerts = {}, c.disableInputs = !0, g.update(l, e.metadata.name, c.targetObject, h).then(function() {
8315-
d.history.back();
8316-
}, function(d) {
8317-
c.disableInputs = !1;
8318-
var e = a("humanizeKind"), g = e(f.kind), h = e(b.kind);
8319-
n("An error occurred attaching the " + g + " to the " + h + ".", k(d));
8316+
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(s), d.alerts = {}, d.disableInputs = !0, h.update(m, b.metadata.name, d.targetObject, f).then(function() {
8317+
e.history.back();
8318+
}, function(b) {
8319+
d.disableInputs = !1;
8320+
var e = a("humanizeKind"), f = e(g.kind), h = e(c.kind);
8321+
n("An error occurred attaching the " + f + " to the " + h + ".", j(b));
83208322
});
83218323
}
83228324
};
@@ -14101,7 +14103,9 @@ return _.isRegExp(a) ? a.source :_.escapeRegExp(a);
1410114103
}).join("|"), f = new RegExp("(" + e + ")", "ig");
1410214104
return d.replace(f, "<mark>$&</mark>");
1410314105
};
14104-
} ]), angular.module("openshiftConsole").filter("camelToLower", function() {
14106+
} ]).filter("encodeURIComponent", function() {
14107+
return window.encodeURIComponent;
14108+
}), angular.module("openshiftConsole").filter("camelToLower", function() {
1410514109
return function(a) {
1410614110
return a ? _.startCase(a).toLowerCase() :a;
1410714111
};

dist/scripts/templates.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
948948
"<p>{{error | getErrorDetails}}</p>\n" +
949949
"</div>\n" +
950950
"<div ng-if=\"targetObject && configMaps && secrets\">\n" +
951-
"<div ng-if=\"!configMaps.length && !secrets.length\" class=\"empty-state-message empty-state-full-page\">\n" +
952-
"<h2 class=\"text-center\">No config maps or secrets.</h2>\n" +
953-
"<p class=\"gutter-top\">\n" +
954-
"There are no config maps or secrets in project {{project | displayName}} to use as a volume for this {{kind | humanizeKind}}.\n" +
955-
"</p>\n" +
956-
"<p ng-if=\"targetObject\"><a ng-href=\"{{targetObject | navigateResourceURL}}\">Back to {{kind | humanizeKind}} {{name}}</a></p>\n" +
957-
"</div>\n" +
958-
"<div ng-if=\"configMaps.length || secrets.length\" class=\"mar-top-xl\">\n" +
951+
"<div class=\"mar-top-xl\">\n" +
959952
"<h1>Add Config Files</h1>\n" +
960953
"<div class=\"help-block\">\n" +
961954
"Add values from a config map or secret as volume. This will make the data available as files for {{kind | humanizeKind}} {{name}}.\n" +
@@ -975,6 +968,15 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
975968
"<span ng-bind-html=\"source.metadata.name | highlight : $select.search\"></span>\n" +
976969
"</ui-select-choices>\n" +
977970
"</ui-select>\n" +
971+
"<div ng-if=\"('configmaps' | canI : 'create') || ('secrets' | canI : 'create')\" class=\"mar-top-md\">\n" +
972+
"<span ng-if=\"'configmaps' | canI : 'create'\">\n" +
973+
"<a ng-href=\"project/{{project.metadata.name}}/create-config-map\">Create config map</a>\n" +
974+
"</span>\n" +
975+
"<span ng-if=\"'secrets' | canI : 'create'\">\n" +
976+
"<span ng-if=\"'configmaps' | canI : 'create'\" class=\"action-divider\" aria-hidden=\"true\">|</span>\n" +
977+
"<a ng-href=\"project/{{project.metadata.name}}/create-secret?then={{returnURL | encodeURIComponent}}\">Create Secret</a>\n" +
978+
"</span>\n" +
979+
"</div>\n" +
978980
"<div class=\"help-block\">\n" +
979981
"Pick the config source. Its data will be mounted as a volume in the container.\n" +
980982
"</div>\n" +

0 commit comments

Comments
 (0)