mirror of https://github.com/portainer/portainer
feat(edgestacks): add a retry period to edge stack deployments BE-11155 (#109)
Co-authored-by: andres-portainer <andres-portainer@users.noreply.github.com> Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>release/2.25.0
parent
47d428f3eb
commit
cd6935b07a
|
@ -31,15 +31,18 @@ type (
|
||||||
// RegistryCredentials holds the credentials for a Docker registry.
|
// RegistryCredentials holds the credentials for a Docker registry.
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
RegistryCredentials []RegistryCredentials
|
RegistryCredentials []RegistryCredentials
|
||||||
// PrePullImage is a flag indicating if the agent should pull the image before deploying the stack.
|
// PrePullImage is a flag indicating if the agent must pull the image before deploying the stack.
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
PrePullImage bool
|
PrePullImage bool
|
||||||
// RePullImage is a flag indicating if the agent should pull the image if it is already present on the node.
|
// RePullImage is a flag indicating if the agent must pull the image if it is already present on the node.
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
RePullImage bool
|
RePullImage bool
|
||||||
// RetryDeploy is a flag indicating if the agent should retry to deploy the stack if it fails.
|
// RetryDeploy is a flag indicating if the agent must retry to deploy the stack if it fails.
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
RetryDeploy bool
|
RetryDeploy bool
|
||||||
|
// RetryPeriod specifies the duration, in seconds, for which the agent should continue attempting to deploy the stack after a failure
|
||||||
|
// Used only for EE
|
||||||
|
RetryPeriod int
|
||||||
// EdgeUpdateID is the ID of the edge update related to this stack.
|
// EdgeUpdateID is the ID of the edge update related to this stack.
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
EdgeUpdateID int
|
EdgeUpdateID int
|
||||||
|
|
|
@ -26,11 +26,10 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
var edgeStack *portainer.EdgeStack
|
var edgeStack *portainer.EdgeStack
|
||||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
if err := handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||||
edgeStack, err = handler.createSwarmStack(tx, method, dryrun, tokenData.ID, r)
|
edgeStack, err = handler.createSwarmStack(tx, method, dryrun, tokenData.ID, r)
|
||||||
return err
|
return err
|
||||||
})
|
}); err != nil {
|
||||||
if err != nil {
|
|
||||||
switch {
|
switch {
|
||||||
case httperrors.IsInvalidPayloadError(err):
|
case httperrors.IsInvalidPayloadError(err):
|
||||||
return httperror.BadRequest("Invalid payload", err)
|
return httperror.BadRequest("Invalid payload", err)
|
||||||
|
|
|
@ -57,17 +57,15 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload updateEdgeStackPayload
|
var payload updateEdgeStackPayload
|
||||||
err = request.DecodeAndValidateJSONPayload(r, &payload)
|
if err := request.DecodeAndValidateJSONPayload(r, &payload); err != nil {
|
||||||
if err != nil {
|
|
||||||
return httperror.BadRequest("Invalid request payload", err)
|
return httperror.BadRequest("Invalid request payload", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var stack *portainer.EdgeStack
|
var stack *portainer.EdgeStack
|
||||||
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
if err := handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
||||||
stack, err = handler.updateEdgeStack(tx, portainer.EdgeStackID(stackID), payload)
|
stack, err = handler.updateEdgeStack(tx, portainer.EdgeStackID(stackID), payload)
|
||||||
return err
|
return err
|
||||||
})
|
}); err != nil {
|
||||||
if err != nil {
|
|
||||||
var httpErr *httperror.HandlerError
|
var httpErr *httperror.HandlerError
|
||||||
if errors.As(err, &httpErr) {
|
if errors.As(err, &httpErr) {
|
||||||
return httpErr
|
return httpErr
|
||||||
|
@ -122,14 +120,12 @@ func (handler *Handler) updateEdgeStack(tx dataservices.DataStoreTx, stackID por
|
||||||
stack.EdgeGroups = groupsIds
|
stack.EdgeGroups = groupsIds
|
||||||
|
|
||||||
if payload.UpdateVersion {
|
if payload.UpdateVersion {
|
||||||
err := handler.updateStackVersion(stack, payload.DeploymentType, []byte(payload.StackFileContent), "", relatedEndpointIds)
|
if err := handler.updateStackVersion(stack, payload.DeploymentType, []byte(payload.StackFileContent), "", relatedEndpointIds); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, httperror.InternalServerError("Unable to update stack version", err)
|
return nil, httperror.InternalServerError("Unable to update stack version", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.EdgeStack().UpdateEdgeStack(stack.ID, stack)
|
if err := tx.EdgeStack().UpdateEdgeStack(stack.ID, stack); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, httperror.InternalServerError("Unable to persist the stack changes inside the database", err)
|
return nil, httperror.InternalServerError("Unable to persist the stack changes inside the database", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +156,7 @@ func (handler *Handler) handleChangeEdgeGroups(tx dataservices.DataStoreTx, edge
|
||||||
|
|
||||||
delete(relation.EdgeStacks, edgeStackID)
|
delete(relation.EdgeStacks, edgeStackID)
|
||||||
|
|
||||||
err = tx.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
|
if err := tx.EndpointRelation().UpdateEndpointRelation(endpointID, relation); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, errors.WithMessage(err, "Unable to persist environment relation in database")
|
return nil, nil, errors.WithMessage(err, "Unable to persist environment relation in database")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,8 +176,7 @@ func (handler *Handler) handleChangeEdgeGroups(tx dataservices.DataStoreTx, edge
|
||||||
|
|
||||||
relation.EdgeStacks[edgeStackID] = true
|
relation.EdgeStacks[edgeStackID] = true
|
||||||
|
|
||||||
err = tx.EndpointRelation().UpdateEndpointRelation(endpointID, relation)
|
if err := tx.EndpointRelation().UpdateEndpointRelation(endpointID, relation); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, errors.WithMessage(err, "Unable to persist environment relation in database")
|
return nil, nil, errors.WithMessage(err, "Unable to persist environment relation in database")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue