mirror of https://github.com/portainer/portainer
fix(container-creation): revert container state if creation failed (#2565)
* fix(container): rename old container only if exist * fix(container): remove new container only if created * style(container): fix typo Co-Authored-By: chiptus <chiptus@users.noreply.github.com>fix2626-endpoint-management-cmd-line
parent
808eb7d341
commit
62eb47b3cb
|
@ -633,9 +633,9 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
function create() {
|
function create() {
|
||||||
var oldContainer = null;
|
var oldContainer = null;
|
||||||
|
|
||||||
|
|
||||||
HttpRequestHelper.setPortainerAgentTargetHeader($scope.formValues.NodeName);
|
HttpRequestHelper.setPortainerAgentTargetHeader($scope.formValues.NodeName);
|
||||||
return findCurrentContainer()
|
return findCurrentContainer()
|
||||||
|
.then(setOldContainer)
|
||||||
.then(confirmCreateContainer)
|
.then(confirmCreateContainer)
|
||||||
.then(startCreationProcess)
|
.then(startCreationProcess)
|
||||||
.catch(notifyOnError)
|
.catch(notifyOnError)
|
||||||
|
@ -645,6 +645,11 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
$scope.state.actionInProgress = false;
|
$scope.state.actionInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setOldContainer(container) {
|
||||||
|
oldContainer = container;
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
function findCurrentContainer() {
|
function findCurrentContainer() {
|
||||||
return Container.query({ all: 1, filters: { name: ['^/' + $scope.config.name + '$'] } })
|
return Container.query({ all: 1, filters: { name: ['^/' + $scope.config.name + '$'] } })
|
||||||
.$promise
|
.$promise
|
||||||
|
@ -652,8 +657,7 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
if (!containers.length) {
|
if (!containers.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
oldContainer = containers[0];
|
return containers[0];
|
||||||
return oldContainer;
|
|
||||||
})
|
})
|
||||||
.catch(notifyOnError);
|
.catch(notifyOnError);
|
||||||
|
|
||||||
|
@ -676,7 +680,36 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
||||||
.then(applyResourceControl)
|
.then(applyResourceControl)
|
||||||
.then(connectToExtraNetworks)
|
.then(connectToExtraNetworks)
|
||||||
.then(removeOldContainer)
|
.then(removeOldContainer)
|
||||||
.then(onSuccess);
|
.then(onSuccess)
|
||||||
|
.catch(onCreationProcessFail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCreationProcessFail(error) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
removeNewContainer()
|
||||||
|
.then(restoreOldContainerName)
|
||||||
|
.then(function() {
|
||||||
|
deferred.reject(error);
|
||||||
|
})
|
||||||
|
.catch(function(restoreError) {
|
||||||
|
deferred.reject(restoreError);
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeNewContainer() {
|
||||||
|
return findCurrentContainer().then(function onContainerLoaded(container) {
|
||||||
|
if (container && (!oldContainer || container.Id !== oldContainer.Id)) {
|
||||||
|
return ContainerService.remove(container, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreOldContainerName() {
|
||||||
|
if (!oldContainer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return ContainerService.renameContainer(oldContainer.Id, oldContainer.Names[0].substring(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmCreateContainer(container) {
|
function confirmCreateContainer(container) {
|
||||||
|
|
Loading…
Reference in New Issue