Skip to content

Commit ec2c54d

Browse files
committed
Calculate effective limit min in UI for request/limit ratio
1 parent c76887d commit ec2c54d

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

app/scripts/controllers/setLimits.js

-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ angular.module('openshiftConsole')
6565
// Update project breadcrumb with display name.
6666
$scope.breadcrumbs[0].title = $filter('displayName')(project);
6767

68-
// Check if requests or limits are calculated. Memory limit is never calculated.
69-
$scope.cpuRequestCalculated = LimitRangesService.isRequestCalculated('cpu', project);
70-
$scope.cpuLimitCalculated = LimitRangesService.isLimitCalculated('cpu', project);
71-
$scope.memoryRequestCalculated = LimitRangesService.isRequestCalculated('memory', project);
72-
7368
DataService.get(type, $scope.name, context).then(
7469
function(result) {
7570
var resource = angular.copy(result);

app/scripts/directives/editRequestLimit.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ angular.module('openshiftConsole')
175175
// 'cpu' or 'memory'
176176
type: '@',
177177
limitRanges: '=',
178-
requestCalculated: '=',
179-
limitCalculated: '=?'
178+
// The project, needed to determine if request is calculated from limit.
179+
project: '='
180180
},
181181
templateUrl: 'views/_edit-request-limit.html',
182182
link: function(scope) {
183183
scope.$watch('limitRanges', function() {
184-
scope.limits = LimitRangesService.getEffectiveLimitRange(scope.limitRanges, scope.type, 'Container');
184+
scope.limits = LimitRangesService.getEffectiveLimitRange(scope.limitRanges, scope.type, 'Container', scope.project);
185+
scope.requestCalculated = LimitRangesService.isRequestCalculated(scope.type, scope.project);
186+
scope.limitCalculated = LimitRangesService.isLimitCalculated(scope.type, scope.project);
185187
}, true);
186188
}
187189
};

app/scripts/services/hpa.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ angular.module("openshiftConsole")
6666
// computeResource - 'cpu' or 'memory'
6767
// defaultType - 'defaultRequest' or 'defaultLimit'
6868
// limitRanges - collection of LimitRange objects (hash or array)
69-
var hasDefault = function(computeResource, defaultType, limitRanges) {
70-
var effectiveLimits = LimitRangesService.getEffectiveLimitRange(limitRanges, computeResource, 'Container');
69+
var hasDefault = function(computeResource, defaultType, limitRanges, project) {
70+
var effectiveLimits = LimitRangesService.getEffectiveLimitRange(limitRanges, computeResource, 'Container', project);
7171
return !!effectiveLimits[defaultType];
7272
};
7373

74-
var hasDefaultRequest = function(computeResource, limitRanges) {
75-
return hasDefault(computeResource, 'defaultRequest', limitRanges);
74+
var hasDefaultRequest = function(computeResource, limitRanges, project) {
75+
return hasDefault(computeResource, 'defaultRequest', limitRanges, project);
7676
};
7777

78-
var hasDefaultLimit = function(computeResource, limitRanges) {
79-
return hasDefault(computeResource, 'defaultLimit', limitRanges);
78+
var hasDefaultLimit = function(computeResource, limitRanges, project) {
79+
return hasDefault(computeResource, 'defaultLimit', limitRanges, project);
8080
};
8181

8282
// Is the corresponding limit value set to calculate a request?
@@ -91,7 +91,7 @@ angular.module("openshiftConsole")
9191

9292
// Check if the corresponding limit is set or defaulted.
9393
return hasLimitSet(limitComputeResource, containers) ||
94-
hasDefaultLimit(limitComputeResource, limitRanges);
94+
hasDefaultLimit(limitComputeResource, limitRanges, project);
9595
};
9696

9797
// Checks if a CPU request is currently set or will be defaulted for any
@@ -105,7 +105,7 @@ angular.module("openshiftConsole")
105105
return true;
106106
}
107107

108-
if (hasDefaultRequest('cpu', limitRanges)) {
108+
if (hasDefaultRequest('cpu', limitRanges, project)) {
109109
return true;
110110
}
111111

app/scripts/services/limits.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ angular.module("openshiftConsole")
44
.factory("LimitRangesService", function($filter, LIMIT_REQUEST_OVERRIDES) {
55
var usageValue = $filter('usageValue');
66
var usageWithUnits = $filter('usageWithUnits');
7+
var amountAndUnit = $filter('amountAndUnit');
78

89
var isSmaller = function(candidate, previous) {
910
if (!candidate) {
@@ -89,7 +90,7 @@ angular.module("openshiftConsole")
8990
// max: "2",
9091
// }
9192

92-
var getEffectiveLimitRange = function(limitRanges, computeResource, resourceType) {
93+
var getEffectiveLimitRange = function(limitRanges, computeResource, resourceType, project) {
9394
var effectiveRange = {};
9495
angular.forEach(limitRanges, function(limitRange) {
9596
angular.forEach(limitRange.spec.limits, function(limit) {
@@ -126,6 +127,21 @@ angular.module("openshiftConsole")
126127
});
127128
});
128129

130+
// If request is calculated from limit, adjust the effective min. The
131+
// effective min needs to be large enough so that the calculated request
132+
// value validates.
133+
var requestToLimitPercent, minAmountAndUnit, minAmount, minUnit;
134+
if (effectiveRange.min) {
135+
requestToLimitPercent = getRequestToLimitPercent(computeResource, project);
136+
if (requestToLimitPercent) {
137+
// Apply the ratio, making sure to keep the same unit.
138+
minAmountAndUnit = amountAndUnit(effectiveRange.min);
139+
minAmount = Math.ceil(minAmountAndUnit[0] / (requestToLimitPercent / 100));
140+
minUnit = minAmountAndUnit[1] || '';
141+
effectiveRange.min = '' + minAmount + minUnit;
142+
}
143+
}
144+
129145
return effectiveRange;
130146
};
131147

@@ -137,8 +153,8 @@ angular.module("openshiftConsole")
137153
return [];
138154
}
139155

140-
var podLimits = getEffectiveLimitRange(limitRanges, computeResource, 'Pod');
141-
var containerLimits = getEffectiveLimitRange(limitRanges, computeResource, 'Container');
156+
var podLimits = getEffectiveLimitRange(limitRanges, computeResource, 'Pod', project);
157+
var containerLimits = getEffectiveLimitRange(limitRanges, computeResource, 'Container', project);
142158

143159
// Use usageValue to normalize units.
144160
var requestTotal = 0,

app/views/create/fromimage.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,13 @@ <h3>Environment Variables (Runtime only) <span class="help action-inline">
325325
resources="container.resources"
326326
type="cpu"
327327
limit-ranges="limitRanges"
328-
request-calculated="cpuRequestCalculated"
329-
limit-calculated="cpuLimitCalculated">
328+
project="project">
330329
</edit-request-limit>
331330
<edit-request-limit
332331
resources="container.resources"
333332
type="memory"
334333
limit-ranges="limitRanges"
335-
request-calculated="memoryRequestCalculated">
334+
project="project">
336335
</edit-request-limit>
337336
<div ng-repeat="problem in cpuProblems" class="has-error">
338337
<span class="help-block">{{problem}}</span>

app/views/set-limits.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ <h2 ng-if="containers.length > 1">Container {{container.name}}</h2>
3434
resources="container.resources"
3535
type="cpu"
3636
limit-ranges="limitRanges"
37-
request-calculated="cpuRequestCalculated"
38-
limit-calculated="cpuLimitCalculated">
37+
project="project">
3938
</edit-request-limit>
4039
<edit-request-limit
4140
resources="container.resources"
4241
type="memory"
4342
limit-ranges="limitRanges"
44-
request-calculated="memoryRequestCalculated">
43+
project="project">
4544
</edit-request-limit>
4645
</div>
4746
<div ng-repeat="problem in cpuProblems" class="has-error">

0 commit comments

Comments
 (0)