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() {
|
||||
var oldContainer = null;
|
||||
|
||||
|
||||
HttpRequestHelper.setPortainerAgentTargetHeader($scope.formValues.NodeName);
|
||||
return findCurrentContainer()
|
||||
.then(setOldContainer)
|
||||
.then(confirmCreateContainer)
|
||||
.then(startCreationProcess)
|
||||
.catch(notifyOnError)
|
||||
|
@ -645,6 +645,11 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
|||
$scope.state.actionInProgress = false;
|
||||
}
|
||||
|
||||
function setOldContainer(container) {
|
||||
oldContainer = container;
|
||||
return container;
|
||||
}
|
||||
|
||||
function findCurrentContainer() {
|
||||
return Container.query({ all: 1, filters: { name: ['^/' + $scope.config.name + '$'] } })
|
||||
.$promise
|
||||
|
@ -652,8 +657,7 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
|||
if (!containers.length) {
|
||||
return;
|
||||
}
|
||||
oldContainer = containers[0];
|
||||
return oldContainer;
|
||||
return containers[0];
|
||||
})
|
||||
.catch(notifyOnError);
|
||||
|
||||
|
@ -676,7 +680,36 @@ function ($q, $scope, $state, $timeout, $transition$, $filter, Container, Contai
|
|||
.then(applyResourceControl)
|
||||
.then(connectToExtraNetworks)
|
||||
.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) {
|
||||
|
|
Loading…
Reference in New Issue