forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment.js
348 lines (307 loc) · 13.2 KB
/
deployment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
'use strict';
/**
* @ngdoc function
* @name openshiftConsole.controller:DeploymentController
* @description
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('DeploymentController',
function ($scope,
$filter,
$routeParams,
AlertMessageService,
DataService,
DeploymentsService,
EnvironmentService,
HPAService,
ImageStreamResolver,
ModalsService,
Navigate,
Logger,
ProjectsService,
StorageService) {
var imageStreamImageRefByDockerReference = {}; // lets us determine if a particular container's docker image reference belongs to an imageStream
$scope.projectName = $routeParams.project;
$scope.name = $routeParams.deployment;
$scope.forms = {};
$scope.alerts = {};
$scope.imagesByDockerReference = {};
$scope.breadcrumbs = [
{
title: "Deployments",
link: "project/" + $routeParams.project + "/browse/deployments"
},
{
title: $routeParams.deployment
}
];
$scope.healthCheckURL = Navigate.healthCheckURL($routeParams.project,
"Deployment",
$routeParams.deployment,
"extensions");
// get and clear any alerts
AlertMessageService.getAlerts().forEach(function(alert) {
$scope.alerts[alert.name] = alert.data;
});
AlertMessageService.clearAlerts();
var previousEnvConflict = false;
var updateEnvironment = function(current, previous) {
if (previousEnvConflict) {
return;
}
if (!$scope.forms.deploymentEnvVars || $scope.forms.deploymentEnvVars.$pristine) {
$scope.updatedDeployment = EnvironmentService.copyAndNormalize(current);
return;
}
// The env var form has changed and the deployment has been updated. See
// if there were any background changes to the environment variables. If
// not, merge the environment edits into the updated deployment object.
if (EnvironmentService.isEnvironmentEqual(current, previous)) {
$scope.updatedDeployment = EnvironmentService.mergeEdits($scope.updatedDeployment, current);
return;
}
previousEnvConflict = true;
$scope.alerts["env-conflict"] = {
type: "warning",
message: "The environment variables for the deployment have been updated in the background. Saving your changes may create a conflict or cause loss of data.",
links: [
{
label: 'Reload Environment Variables',
onClick: function() {
$scope.clearEnvVarUpdates();
return true;
}
}
]
};
};
var orderByDisplayName = $filter('orderByDisplayName');
var getErrorDetails = $filter('getErrorDetails');
var displayError = function(errorMessage, errorDetails) {
$scope.alerts['from-value-objects'] = {
type: "error",
message: errorMessage,
details: errorDetails
};
};
var watches = [];
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
$scope.projectContext = context;
var limitRanges = {};
var updateHPAWarnings = function() {
HPAService.getHPAWarnings($scope.deployment, $scope.autoscalers, limitRanges, project)
.then(function(warnings) {
$scope.hpaWarnings = warnings;
});
};
var saveEnvPromise;
DataService.get({
group: 'extensions',
resource: 'deployments'
}, $routeParams.deployment, context).then(
// success
function(deployment) {
$scope.loaded = true;
$scope.deployment = deployment;
updateHPAWarnings();
$scope.saveEnvVars = function() {
EnvironmentService.compact($scope.updatedDeployment);
saveEnvPromise = DataService.update({
group: 'extensions',
resource: 'deployments'
}, $routeParams.deployment, $scope.updatedDeployment, context);
saveEnvPromise.then(function success(){
// TODO: de-duplicate success and error messages.
// as it stands, multiple messages appear based on how edit
// is made.
$scope.alerts['saveEnvSuccess'] = {
type: "success",
message: $routeParams.deployment + " was updated."
};
$scope.forms.deploymentEnvVars.$setPristine();
}, function error(e){
$scope.alerts['saveEnvError'] = {
type: "error",
message: $routeParams.deployment + " was not updated.",
details: "Reason: " + $filter('getErrorDetails')(e)
};
}).finally(function() {
saveEnvPromise = null;
});
};
$scope.clearEnvVarUpdates = function() {
$scope.updatedDeployment = EnvironmentService.copyAndNormalize($scope.deployment);
$scope.forms.deploymentEnvVars.$setPristine();
previousEnvConflict = false;
};
// If we found the item successfully, watch for changes on it
watches.push(DataService.watchObject({
group: 'extensions',
resource: 'deployments'
}, $routeParams.deployment, context, function(deployment, action) {
if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "This deployment has been deleted."
};
}
var previous = $scope.deployment;
$scope.deployment = deployment;
$scope.updatingPausedState = false;
updateHPAWarnings();
updateEnvironment(deployment, previous);
// Wait for a pending save to complete to avoid a race between the PUT and the watch callbacks.
if (saveEnvPromise) {
saveEnvPromise.finally(function() {
updateEnvironment(deployment, previous);
});
} else {
updateEnvironment(deployment, previous);
}
ImageStreamResolver.fetchReferencedImageStreamImages([deployment.spec.template], $scope.imagesByDockerReference, imageStreamImageRefByDockerReference, context);
}));
// Watch replica sets for this deployment
// TODO: Use controller ref
watches.push(DataService.watch({
group: 'extensions',
resource: 'replicasets'
}, context, function(replicaSetData) {
var replicaSets = replicaSetData.by('metadata.name');
var deploymentSelector = new LabelSelector(deployment.spec.selector);
replicaSets = _.filter(replicaSets, function(replicaSet) {
return deploymentSelector.covers(new LabelSelector(replicaSet.spec.selector));
});
$scope.inProgressDeployment = _.chain(replicaSets).filter('status.replicas').size() > 1;
$scope.replicaSetsForDeployment = DeploymentsService.sortByRevision(replicaSets);
}));
},
// failure
function(e) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: e.status === 404 ? "This deployment can not be found, it may have been deleted." : "The deployment details could not be loaded.",
details: e.status === 404 ? "Any remaining deployment history for this deployment will be shown." : "Reason: " + $filter('getErrorDetails')(e)
};
}
);
// List limit ranges in this project to determine if there is a default
// CPU request for autoscaling.
DataService.list("limitranges", context).then(function(response) {
limitRanges = response.by("metadata.name");
updateHPAWarnings();
});
var configMapDataOrdered = [];
var secretDataOrdered = [];
$scope.valueFromObjects = [];
DataService.list("configmaps", context, null, { errorNotification: false }).then(function(configMapData) {
configMapDataOrdered = orderByDisplayName(configMapData.by("metadata.name"));
$scope.valueFromObjects = configMapDataOrdered.concat(secretDataOrdered);
}, function(e) {
if (e.code === 403) {
return;
}
displayError('Could not load config maps', getErrorDetails(e));
});
DataService.list("secrets", context, null, { errorNotification: false }).then(function(secretData) {
secretDataOrdered = orderByDisplayName(secretData.by("metadata.name"));
$scope.valueFromObjects = secretDataOrdered.concat(configMapDataOrdered);
}, function(e) {
if (e.code === 403) {
return;
}
displayError('Could not load secrets', getErrorDetails(e));
});
watches.push(DataService.watch("imagestreams", context, function(imageStreamData) {
var imageStreams = imageStreamData.by("metadata.name");
ImageStreamResolver.buildDockerRefMapForImageStreams(imageStreams, imageStreamImageRefByDockerReference);
// If the deployment has been loaded already
if ($scope.deployment) {
ImageStreamResolver.fetchReferencedImageStreamImages([$scope.deployment.spec.template], $scope.imagesByDockerReference, imageStreamImageRefByDockerReference, context);
}
Logger.log("imagestreams (subscribe)", $scope.imageStreams);
}));
watches.push(DataService.watch({
group: "extensions",
resource: "horizontalpodautoscalers"
}, context, function(hpa) {
$scope.autoscalers =
HPAService.filterHPA(hpa.by("metadata.name"), 'Deployment', $routeParams.deployment);
updateHPAWarnings();
}));
watches.push(DataService.watch("builds", context, function(builds) {
$scope.builds = builds.by("metadata.name");
Logger.log("builds (subscribe)", $scope.builds);
}));
$scope.scale = function(replicas) {
var showScalingError = function(result) {
$scope.alerts = $scope.alerts || {};
$scope.alerts["scale"] = {
type: "error",
message: "An error occurred scaling the deployment.",
details: $filter('getErrorDetails')(result)
};
};
DeploymentsService.scale($scope.deployment, replicas).then(_.noop, showScalingError);
};
$scope.setPaused = function(paused) {
$scope.updatingPausedState = true;
DeploymentsService.setPaused($scope.deployment, paused, context).then(
// Success
_.noop,
// Failure
function(e) {
$scope.updatingPausedState = false;
$scope.alerts = $scope.alerts || {};
$scope.alerts["scale"] = {
type: "error",
message: "An error occurred " + (paused ? "pausing" : "resuming") + " the deployment.",
details: $filter('getErrorDetails')(e)
};
});
};
$scope.removeVolume = function(volume) {
var details;
if (_.get($scope, 'deployment.spec.paused')) {
details = "This will remove the volume from the deployment.";
} else {
details = "This will remove the volume from the deployment and start a new rollout.";
}
if (volume.persistentVolumeClaim) {
details += " It will not delete the persistent volume claim.";
} else if (volume.secret) {
details += " It will not delete the secret.";
} else if (volume.configMap) {
details += " It will not delete the config map.";
}
var confirm = ModalsService.confirm({
message: "Remove volume " + volume.name + "?",
details: details,
okButtonText: "Remove",
okButtonClass: "btn-danger",
cancelButtonText: "Cancel"
});
var showError = function(e) {
$scope.alerts["remove-volume-error"] = {
type: "error",
message: "An error occurred removing the volume.",
details: $filter('getErrorDetails')(e)
};
};
var removeVolume = function() {
// No-op on success since the page updates.
StorageService
.removeVolume($scope.deployment, volume, context)
.then(_.noop, showError);
};
confirm.then(removeVolume);
};
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});