forked from openshift/origin
/
overviewDeployment.js
133 lines (112 loc) · 4.03 KB
/
overviewDeployment.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
'use strict';
angular.module('openshiftConsole')
.directive('overviewDeployment', function($location, $uibModal, $timeout, $filter, LabelFilter, DeploymentsService, Navigate, hashSizeFilter, isDeploymentFilter) {
return {
restrict: 'E',
scope: {
// Replication controller / deployment fields
rc: '=',
deploymentConfigId: '=',
deploymentConfigMissing: '=',
deploymentConfigDifferentService: '=',
deploymentConfig: '=',
scalable: '=',
// Nested podTemplate fields
imagesByDockerReference: '=',
builds: '=',
// Pods
pods: '=',
// To display scaling errors
alerts: '='
},
templateUrl: 'views/_overview-deployment.html',
controller: function($scope) {
$scope.$watch("rc.spec.replicas", function() {
$scope.desiredReplicas = null;
});
// Debounce scaling so multiple clicks within 500 milliseconds only result in one request.
var scale = _.debounce(function () {
if (!angular.isNumber($scope.desiredReplicas)) {
return;
}
var showScalingError = function(result) {
$scope.alerts = $scope.alerts || {};
$scope.desiredReplicas = null;
$scope.alerts["scale"] =
{
type: "error",
message: "An error occurred scaling the deployment.",
details: $filter('getErrorDetails')(result)
};
};
if ($scope.deploymentConfig) {
DeploymentsService.scaleDC($scope.deploymentConfig, $scope.desiredReplicas).then(_.noop, showScalingError);
} else {
DeploymentsService.scaleRC($scope.rc, $scope.desiredReplicas).then(_.noop, showScalingError);
}
}, 500);
$scope.viewPodsForDeployment = function(deployment) {
if (hashSizeFilter($scope.pods) === 0) {
return;
}
Navigate.toPodsForDeployment(deployment);
};
$scope.scaleUp = function() {
if (!$scope.scalable) {
return;
}
$scope.desiredReplicas = $scope.getDesiredReplicas();
$scope.desiredReplicas++;
scale();
};
$scope.scaleDown = function() {
if (!$scope.scalable) {
return;
}
$scope.desiredReplicas = $scope.getDesiredReplicas();
if ($scope.desiredReplicas === 0) {
return;
}
// Prompt before scaling to 0.
if ($scope.desiredReplicas === 1) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/modals/confirmScale.html',
controller: 'ConfirmScaleController',
resolve: {
resource: function() {
return $scope.rc;
},
type: function() {
if (isDeploymentFilter($scope.rc)) {
return "deployment";
}
return "replication controller";
}
}
});
modalInstance.result.then(function() {
// It's possible $scope.desiredReplicas was set to null if
// rc.spec.replicas changed since the dialog was shown, so call
// getDesiredReplicas() again.
$scope.desiredReplicas = $scope.getDesiredReplicas() - 1;
scale();
});
return;
}
$scope.desiredReplicas--;
scale();
};
$scope.getDesiredReplicas = function() {
// If not null or undefined, use $scope.desiredReplicas.
if (angular.isDefined($scope.desiredReplicas) && $scope.desiredReplicas !== null) {
return $scope.desiredReplicas;
}
if ($scope.rc && $scope.rc.spec && angular.isDefined($scope.rc.spec.replicas)) {
return $scope.rc.spec.replicas;
}
return 1;
};
}
};
});