Skip to content

Commit 7b414b3

Browse files
author
OpenShift Bot
authored
Merge pull request #1806 from spadgett/app-label
Merged by openshift-bot
2 parents 620d2d4 + 2a0ee2b commit 7b414b3

File tree

11 files changed

+60
-93
lines changed

11 files changed

+60
-93
lines changed

app/scripts/controllers/create/createFromImage.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ angular.module("openshiftConsole")
116116
include: true,
117117
portOptions: []
118118
};
119-
scope.userDefinedLabels = [];
120-
scope.systemLabels = [appLabel];
119+
scope.labelArray = [appLabel];
121120
scope.annotations = {};
122121
scope.scaling = {
123122
replicas: 1,
@@ -276,8 +275,11 @@ angular.module("openshiftConsole")
276275

277276
$scope.$watch('scaling.autoscale', checkCPURequest);
278277
$scope.$watch('container', checkCPURequest, true);
279-
$scope.$watch('name', function(newValue) {
280-
appLabel.value = newValue;
278+
$scope.$watch('name', function(newValue, oldValue) {
279+
// Only change the app label if the user hasn't modified it themselves.
280+
if (!appLabel.value || appLabel.value === oldValue) {
281+
appLabel.value = newValue;
282+
}
281283
});
282284

283285
initAndValidate($scope);
@@ -384,9 +386,9 @@ angular.module("openshiftConsole")
384386
hideErrorNotifications();
385387
$scope.buildConfig.envVars = keyValueEditorUtils.compactEntries($scope.buildConfigEnvVars);
386388
$scope.deploymentConfig.envVars = keyValueEditorUtils.compactEntries($scope.DCEnvVarsFromUser);
387-
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.userDefinedLabels));
388-
var systemLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.systemLabels));
389-
$scope.labels = _.extend(systemLabels, userLabels);
389+
390+
// Remove empty values and convert the label array to a map.
391+
$scope.labels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labelArray));
390392

391393
var resourceMap = ApplicationGenerator.generate($scope);
392394
//init tasks

app/scripts/directives/deployImage.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ angular.module("openshiftConsole")
3232

3333
$scope.app = {};
3434
$scope.env = [];
35-
$scope.labels = [];
36-
$scope.systemLabels = [{
35+
$scope.labels = [{
3736
name: 'app',
3837
value: ''
3938
}];
@@ -122,8 +121,7 @@ angular.module("openshiftConsole")
122121
};
123122

124123
function getResources() {
125-
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels));
126-
var systemLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.systemLabels));
124+
var labels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels));
127125

128126
return ImagesService.getResources({
129127
name: $scope.app.name,
@@ -133,7 +131,7 @@ angular.module("openshiftConsole")
133131
ports: $scope.ports,
134132
volumes: $scope.volumes,
135133
env: keyValueEditorUtils.compactEntries($scope.env),
136-
labels: _.extend(systemLabels, userLabels),
134+
labels: labels,
137135
pullSecrets: $scope.pullSecrets
138136
});
139137
}
@@ -170,12 +168,13 @@ angular.module("openshiftConsole")
170168
});
171169
};
172170

173-
$scope.$watch('app.name', function() {
171+
$scope.$watch('app.name', function(name, previous) {
174172
$scope.nameTaken = false;
175-
_.set(
176-
_.find($scope.systemLabels, { name: 'app' }),
177-
'value',
178-
$scope.app.name);
173+
174+
var appLabel = _.find($scope.labels, { name: 'app' });
175+
if (appLabel && (!appLabel.value || appLabel.value === previous)) {
176+
appLabel.value = name;
177+
}
179178
});
180179

181180
$scope.$watch('mode', function(newMode, oldMode) {

app/scripts/directives/labels.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ angular.module('openshiftConsole')
5454
restrict: 'E',
5555
scope: {
5656
labels: "=",
57-
systemLabels: "=",
5857
expand: "=?",
5958
canToggle: "=?",
6059
// Optional help text to show with the label controls

app/scripts/directives/processTemplate.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@
217217
context = {
218218
namespace: ctrl.selectedProject.metadata.name
219219
};
220-
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.labels));
221-
var systemLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.systemLabels));
222-
ctrl.template.labels = _.extend(systemLabels, userLabels);
220+
ctrl.template.labels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries(ctrl.labels));
223221

224222
DataService.create("processedtemplates", null, ctrl.template, context).then(
225223
function(config) { // success
@@ -289,15 +287,15 @@
289287
});
290288
}
291289

292-
ctrl.systemLabels = _.map(ctrl.template.labels, function(value, key) {
290+
ctrl.labels = _.map(ctrl.template.labels, function(value, key) {
293291
return {
294292
name: key,
295293
value: value
296294
};
297295
});
298296

299297
if (shouldAddAppLabel()) {
300-
ctrl.systemLabels.push({
298+
ctrl.labels.push({
301299
name: 'app',
302300
value: ctrl.template.metadata.name
303301
});

app/scripts/services/images.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ angular.module("openshiftConsole")
131131
resources.push(imageStream);
132132
}
133133

134+
var dcLabels = _.assign({
135+
deploymentconfig: config.name
136+
}, config.labels);
137+
134138
var deploymentConfig = {
135139
kind: "DeploymentConfig",
136140
apiVersion: "v1",
@@ -164,15 +168,10 @@ angular.module("openshiftConsole")
164168
}],
165169
replicas: 1,
166170
test: false,
167-
selector: {
168-
app: config.name,
169-
deploymentconfig: config.name
170-
},
171+
selector: dcLabels,
171172
template: {
172173
metadata: {
173-
labels: _.assign({
174-
deploymentconfig: config.name
175-
}, config.labels),
174+
labels: dcLabels,
176175
annotations: annotations
177176
},
178177
spec: {

app/views/create/fromimage.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ <h3>Environment Variables <span class="appended-icon">(Runtime only) <span class
401401
<!-- /limits -->
402402

403403
<label-editor
404-
labels="userDefinedLabels"
405-
system-labels="systemLabels"
404+
labels="labelArray"
406405
expand="true"
407406
can-toggle="false"
408407
help-text="Each label is applied to each created resource.">
@@ -415,7 +414,6 @@ <h3>Environment Variables <span class="appended-icon">(Runtime only) <span class
415414
for source, routes, builds, and deployments.
416415
</div>
417416
<div class="buttons gutter-bottom" ng-class="{'gutter-top': !alerts.length}">
418-
<!-- unable to use form.valid. need to fix validators in labels and key values directive -->
419417
<button type="submit"
420418
class="btn btn-primary btn-lg"
421419
ng-disabled="form.$invalid || nameTaken || cpuProblems.length || memoryProblems.length || disableInputs"

app/views/directives/deploy-image.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ <h2>
177177

178178
<label-editor
179179
labels="labels"
180-
system-labels="systemLabels"
181180
expand="true"
182181
can-toggle="false"
183182
help-text="Each label is applied to each created resource.">

app/views/directives/label-editor.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@
55
expand="expand"
66
can-toggle="canToggle">
77

8-
<div ng-if="systemLabels.length">
9-
<div class="help-block">
10-
The following labels are being added automatically. If you want to override them, you can do so below.
11-
</div>
12-
<key-value-editor
13-
entries="systemLabels"
14-
is-readonly
15-
cannot-sort
16-
cannot-delete
17-
cannot-add
18-
key-placeholder="Name"></key-value-editor>
19-
</div>
20-
218
<div ng-if="helpText && ((labels | hashSize) !== 0 || $parent.expand)" class="help-block">
229
{{helpText}}
2310
</div>

app/views/directives/process-template.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</template-options>
66
<label-editor
77
labels="$ctrl.labels"
8-
system-labels="$ctrl.systemLabels"
98
expand="true"
109
can-toggle="false"
1110
help-text="Each label is applied to each created resource.">

dist/scripts/scripts.js

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,9 @@ importPolicy: {}
31893189
};
31903190
n.push(l);
31913191
}
3192-
var u = {
3192+
var u = _.assign({
3193+
deploymentconfig: e.name
3194+
}, e.labels), d = {
31933195
kind: "DeploymentConfig",
31943196
apiVersion: "v1",
31953197
metadata: {
@@ -3217,15 +3219,10 @@ namespace: e.namespace
32173219
} ],
32183220
replicas: 1,
32193221
test: !1,
3220-
selector: {
3221-
app: e.name,
3222-
deploymentconfig: e.name
3223-
},
3222+
selector: u,
32243223
template: {
32253224
metadata: {
3226-
labels: _.assign({
3227-
deploymentconfig: e.name
3228-
}, e.labels),
3225+
labels: u,
32293226
annotations: r
32303227
},
32313228
spec: {
@@ -3243,9 +3240,9 @@ resources: {}
32433240
},
32443241
status: {}
32453242
};
3246-
_.first(e.pullSecrets).name && (u.spec.template.spec.imagePullSecrets = e.pullSecrets), n.push(u);
3247-
var d;
3248-
return _.isEmpty(e.ports) || (d = {
3243+
_.first(e.pullSecrets).name && (d.spec.template.spec.imagePullSecrets = e.pullSecrets), n.push(d);
3244+
var m;
3245+
return _.isEmpty(e.ports) || (m = {
32493246
kind: "Service",
32503247
apiVersion: "v1",
32513248
metadata: {
@@ -3261,7 +3258,7 @@ ports: _.map(e.ports, function(e) {
32613258
return t.getServicePort(e);
32623259
})
32633260
}
3264-
}, n.push(d)), n;
3261+
}, n.push(m)), n;
32653262
},
32663263
getEnvironment: function(e) {
32673264
return _.map(_.get(e, "image.dockerImageMetadata.Config.Env"), function(e) {
@@ -7446,8 +7443,8 @@ c.list("resourcequotas", i).then(function(e) {
74467443
y = e.by("metadata.name"), m.log("quotas", y);
74477444
}), c.list("appliedclusterresourcequotas", i).then(function(e) {
74487445
S = e.by("metadata.name"), m.log("cluster quotas", S);
7449-
}), e.$watch("scaling.autoscale", $), e.$watch("container", $, !0), e.$watch("name", function(e) {
7450-
T.value = e;
7446+
}), e.$watch("scaling.autoscale", $), e.$watch("container", $, !0), e.$watch("name", function(e, t) {
7447+
T.value && T.value !== t || (T.value = e);
74517448
}), function(t) {
74527449
t.name = r.name, t.imageName = R, t.imageTag = r.imageTag, t.namespace = r.namespace, t.buildConfig = {
74537450
buildOnSourceChange: !0,
@@ -7467,7 +7464,7 @@ deployOnConfigChange: !0
74677464
}, t.DCEnvVarsFromImage, t.DCEnvVarsFromUser = [], t.routing = {
74687465
include: !0,
74697466
portOptions: []
7470-
}, t.userDefinedLabels = [], t.systemLabels = [ T ], t.annotations = {}, t.scaling = {
7467+
}, t.labelArray = [ T ], t.annotations = {}, t.scaling = {
74717468
replicas: 1,
74727469
autoscale: !1,
74737470
autoscaleOptions: [ {
@@ -7600,17 +7597,15 @@ e.id = _.uniqueId("create-builder-alert-"), f.addNotification(e);
76007597
e.projectDisplayName = function() {
76017598
return k(this.project) || this.projectName;
76027599
}, e.createApp = function() {
7603-
e.disableInputs = !0, I(), e.buildConfig.envVars = w.compactEntries(e.buildConfigEnvVars), e.deploymentConfig.envVars = w.compactEntries(e.DCEnvVarsFromUser);
7604-
var t = w.mapEntries(w.compactEntries(e.userDefinedLabels)), n = w.mapEntries(w.compactEntries(e.systemLabels));
7605-
e.labels = _.extend(n, t);
7606-
var a = s.generate(e);
7607-
A = [], angular.forEach(a, function(e) {
7600+
e.disableInputs = !0, I(), e.buildConfig.envVars = w.compactEntries(e.buildConfigEnvVars), e.deploymentConfig.envVars = w.compactEntries(e.DCEnvVarsFromUser), e.labels = w.mapEntries(w.compactEntries(e.labelArray));
7601+
var t = s.generate(e);
7602+
A = [], angular.forEach(t, function(e) {
76087603
null !== e && (m.debug("Generated resource definition:", e), A.push(e));
76097604
});
7610-
var r = s.ifResourcesDontExist(A, e.projectName), o = v.getLatestQuotaAlerts(A, i), c = function(t) {
7611-
return e.nameTaken = t.nameTaken, o;
7605+
var n = s.ifResourcesDontExist(A, e.projectName), a = v.getLatestQuotaAlerts(A, i), r = function(t) {
7606+
return e.nameTaken = t.nameTaken, a;
76127607
};
7613-
r.then(c, c).then(U, U);
7608+
n.then(r, r).then(U, U);
76147609
};
76157610
})), e.cancel = function() {
76167611
g.toProjectOverview(e.projectName);
@@ -10213,7 +10208,6 @@ return {
1021310208
restrict: "E",
1021410209
scope: {
1021510210
labels: "=",
10216-
systemLabels: "=",
1021710211
expand: "=?",
1021810212
canToggle: "=?",
1021910213
helpText: "@?"
@@ -12175,12 +12169,12 @@ return a;
1217512169
function p() {
1217612170
f.prefillParameters && _.each(f.template.parameters, function(e) {
1217712171
f.prefillParameters[e.name] && (e.value = f.prefillParameters[e.name]);
12178-
}), f.systemLabels = _.map(f.template.labels, function(e, t) {
12172+
}), f.labels = _.map(f.template.labels, function(e, t) {
1217912173
return {
1218012174
name: t,
1218112175
value: e
1218212176
};
12183-
}), R() && f.systemLabels.push({
12177+
}), R() && f.labels.push({
1218412178
name: "app",
1218512179
value: f.template.metadata.name
1218612180
});
@@ -12268,9 +12262,7 @@ f.createFromTemplate = function() {
1226812262
f.disableInputs = !0, j().then(function(e) {
1226912263
f.selectedProject = e, g = {
1227012264
namespace: f.selectedProject.metadata.name
12271-
};
12272-
var t = d.mapEntries(d.compactEntries(f.labels)), n = d.mapEntries(d.compactEntries(f.systemLabels));
12273-
f.template.labels = _.extend(n, t), r.create("processedtemplates", null, f.template, g).then(function(e) {
12265+
}, f.template.labels = d.mapEntries(d.compactEntries(f.labels)), r.create("processedtemplates", null, f.template, g).then(function(e) {
1227412266
s.setTemplateData(e.parameters, f.template.parameters, e.message), y = e.objects, c.getLatestQuotaAlerts(y, g).then(k);
1227512267
}, function(e) {
1227612268
f.disableInputs = !1;
@@ -13044,7 +13036,7 @@ isDialog: "="
1304413036
templateUrl: "views/directives/deploy-image.html",
1304513037
link: function(n) {
1304613038
function l() {
13047-
var e = p.mapEntries(p.compactEntries(n.labels)), t = p.mapEntries(p.compactEntries(n.systemLabels));
13039+
var e = p.mapEntries(p.compactEntries(n.labels));
1304813040
return i.getResources({
1304913041
name: n.app.name,
1305013042
image: n.import.name,
@@ -13053,11 +13045,11 @@ tag: n.import.tag || "latest",
1305313045
ports: n.ports,
1305413046
volumes: n.volumes,
1305513047
env: p.compactEntries(n.env),
13056-
labels: _.extend(t, e),
13048+
labels: e,
1305713049
pullSecrets: n.pullSecrets
1305813050
});
1305913051
}
13060-
n.mode = "istag", n.istag = {}, n.app = {}, n.env = [], n.labels = [], n.systemLabels = [ {
13052+
n.mode = "istag", n.istag = {}, n.app = {}, n.env = [], n.labels = [ {
1306113053
name: "app",
1306213054
value: ""
1306313055
} ], n.pullSecrets = [ {
@@ -13115,10 +13107,12 @@ t && (n.app.name = R(), n.runsAsRoot = i.runsAsRoot(t), n.ports = r.parsePorts(t
1311513107
}, function(t) {
1311613108
n.import.error = e("getErrorDetails")(t) || "An error occurred finding the image.", n.loading = !1;
1311713109
});
13118-
}, n.$watch("app.name", function() {
13119-
n.nameTaken = !1, _.set(_.find(n.systemLabels, {
13110+
}, n.$watch("app.name", function(e, t) {
13111+
n.nameTaken = !1;
13112+
var a = _.find(n.labels, {
1312013113
name: "app"
13121-
}), "value", n.app.name);
13114+
});
13115+
!a || a.value && a.value !== t || (a.value = e);
1312213116
}), n.$watch("mode", function(e, t) {
1312313117
e !== t && (delete n.import, n.istag = {}, "dockerImage" === e ? n.forms.imageSelection.imageName.$setValidity("imageLoaded", !1) : n.forms.imageSelection.imageName.$setValidity("imageLoaded", !0));
1312413118
}), n.$watch("istag", function(t, a) {

0 commit comments

Comments
 (0)