1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 07:19:41 +02:00

feat(docker): allow docker container resource settings without restart EE-1942 (#6065)

Co-authored-by: sam <sam@allofword>
Co-authored-by: sam@gemibook <huapox@126.com>
Co-authored-by: Prabhat Khera <prabhat.khera@gmail.com>
This commit is contained in:
Prabhat Khera 2021-11-30 11:01:09 +13:00 committed by GitHub
parent c267355759
commit 1e80061186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 173 additions and 54 deletions

View file

@ -7,6 +7,8 @@ import { ContainerCapabilities, ContainerCapability } from '../../../models/cont
import { AccessControlFormData } from '../../../../portainer/components/accessControlForm/porAccessControlFormModel';
import { ContainerDetailsViewModel } from '../../../models/container';
import './createcontainer.css';
angular.module('portainer.docker').controller('CreateContainerController', [
'$q',
'$scope',
@ -61,6 +63,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [
endpoint
) {
$scope.create = create;
$scope.update = update;
$scope.endpoint = endpoint;
$scope.formValues = {
@ -97,6 +100,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [
actionInProgress: false,
mode: '',
pullImageValidity: true,
settingUnlimitedResources: false,
};
$scope.handleEnvVarChange = handleEnvVarChange;
@ -758,6 +762,40 @@ angular.module('portainer.docker').controller('CreateContainerController', [
return true;
}
$scope.handleResourceChange = handleResourceChange;
function handleResourceChange() {
$scope.state.settingUnlimitedResources = false;
if (
($scope.config.HostConfig.Memory > 0 && $scope.formValues.MemoryLimit === 0) ||
($scope.config.HostConfig.MemoryReservation > 0 && $scope.formValues.MemoryReservation === 0) ||
($scope.config.HostConfig.NanoCpus > 0 && $scope.formValues.CpuLimit === 0)
) {
$scope.state.settingUnlimitedResources = true;
}
}
async function updateLimits(config) {
try {
if ($scope.state.settingUnlimitedResources) {
create();
} else {
await ContainerService.updateLimits($transition$.params().from, config);
$scope.config = config;
Notifications.success('Limits updated');
}
} catch (err) {
Notifications.error('Failure', err, 'Update Limits fail');
}
}
async function update() {
$scope.state.actionInProgress = true;
var config = angular.copy($scope.config);
prepareResources(config);
await updateLimits(config);
$scope.state.actionInProgress = false;
}
function create() {
var oldContainer = null;
HttpRequestHelper.setPortainerAgentTargetHeader($scope.formValues.NodeName);