fix(stack): fix an issue with stack migration
parent
a5bd2743f3
commit
23b0d6f1dc
|
@ -23,7 +23,7 @@ func (payload *stackMigratePayload) Validate(r *http.Request) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// POST request on /api/stacks/:id/migrate
|
||||
// POST request on /api/stacks/:id/migrate?endpointId=<endpointId>
|
||||
func (handler *Handler) stackMigrate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||||
if err != nil {
|
||||
|
@ -59,6 +59,17 @@ func (handler *Handler) stackMigrate(w http.ResponseWriter, r *http.Request) *ht
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: this is a work-around for stacks created with Portainer version >= 1.17.1
|
||||
// The EndpointID property is not available for these stacks, this API endpoint
|
||||
// can use the optional EndpointID query parameter to associate a valid endpoint identifier to the stack.
|
||||
endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", true)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
|
||||
}
|
||||
if endpointID != int(stack.EndpointID) {
|
||||
stack.EndpointID = portainer.EndpointID(endpointID)
|
||||
}
|
||||
|
||||
endpoint, err := handler.EndpointService.Endpoint(stack.EndpointID)
|
||||
if err == portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
|
||||
|
|
|
@ -9,6 +9,6 @@ angular.module('portainer.app')
|
|||
update: { method: 'PUT', params: { id: '@id' }, ignoreLoadingBar: true },
|
||||
remove: { method: 'DELETE', params: { id: '@id', external: '@external', endpointId: '@endpointId' } },
|
||||
getStackFile: { method: 'GET', params: { id : '@id', action: 'file' } },
|
||||
migrate: { method: 'POST', params: { id : '@id', action: 'migrate' }, ignoreLoadingBar: true }
|
||||
migrate: { method: 'POST', params: { id : '@id', action: 'migrate', endpointId: '@endpointId' }, ignoreLoadingBar: true }
|
||||
});
|
||||
}]);
|
||||
|
|
|
@ -46,7 +46,7 @@ function StackServiceFactory($q, Stack, ResourceControlService, FileUploadServic
|
|||
return;
|
||||
}
|
||||
|
||||
return Stack.migrate({ id: stack.Id }, { EndpointID: targetEndpointId, SwarmID: swarm.Id }).$promise;
|
||||
return Stack.migrate({ id: stack.Id, endpointId: stack.EndpointId }, { EndpointID: targetEndpointId, SwarmID: swarm.Id }).$promise;
|
||||
})
|
||||
.then(function success(data) {
|
||||
deferred.resolve();
|
||||
|
@ -66,7 +66,7 @@ function StackServiceFactory($q, Stack, ResourceControlService, FileUploadServic
|
|||
|
||||
EndpointProvider.setEndpointID(targetEndpointId);
|
||||
|
||||
Stack.migrate({ id: stack.Id }, { EndpointID: targetEndpointId }).$promise
|
||||
Stack.migrate({ id: stack.Id, endpointId: stack.EndpointId }, { EndpointID: targetEndpointId }).$promise
|
||||
.then(function success(data) {
|
||||
deferred.resolve();
|
||||
})
|
||||
|
|
|
@ -54,6 +54,15 @@ function ($q, $scope, $state, $transition$, StackService, NodeService, ServiceSe
|
|||
migrateRequest = StackService.migrateComposeStack;
|
||||
}
|
||||
|
||||
// TODO: this is a work-around for stacks created with Portainer version >= 1.17.1
|
||||
// The EndpointID property is not available for these stacks, we can pass
|
||||
// the current endpoint identifier as a part of the migrate request. It will be used if
|
||||
// the EndpointID property is not defined on the stack.
|
||||
var endpointId = EndpointProvider.endpointID();
|
||||
if (stack.EndpointId === 0) {
|
||||
stack.EndpointId = endpointId;
|
||||
}
|
||||
|
||||
$scope.state.migrationInProgress = true;
|
||||
migrateRequest(stack, targetEndpointId)
|
||||
.then(function success(data) {
|
||||
|
|
Loading…
Reference in New Issue