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

feat(stacks): migrate stack data from previous portainer version

This commit is contained in:
Anthony Lapenna 2018-06-15 18:14:01 +03:00
parent 5e73a49473
commit e1345416b4
7 changed files with 81 additions and 17 deletions

View file

@ -36,7 +36,7 @@ func (payload *updateSwarmStackPayload) Validate(r *http.Request) error {
return nil
}
// PUT request on /api/stacks/:id
// PUT request on /api/stacks/:id?endpointId=<endpointId>
func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
stackID, err := request.RetrieveRouteVariableValue(r, "id")
if err != nil {
@ -66,6 +66,17 @@ func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *htt
}
}
// 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.ErrEndpointNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}