mirror of https://github.com/portainer/portainer
fix(edgegroups): avoid doing extra operations EE-5627 (#9144)
parent
f5e09618f0
commit
b37120802e
|
@ -71,12 +71,12 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
return httperror.InternalServerError("Unable to find an Edge group with the specified identifier inside the database", err)
|
return httperror.InternalServerError("Unable to find an Edge group with the specified identifier inside the database", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if payload.Name != "" {
|
edgeGroups, err := tx.EdgeGroup().ReadAll()
|
||||||
edgeGroups, err := tx.EdgeGroup().ReadAll()
|
if err != nil {
|
||||||
if err != nil {
|
return httperror.InternalServerError("Unable to retrieve Edge groups from the database", err)
|
||||||
return httperror.InternalServerError("Unable to retrieve Edge groups from the database", err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if payload.Name != "" {
|
||||||
for _, edgeGroup := range edgeGroups {
|
for _, edgeGroup := range edgeGroups {
|
||||||
if edgeGroup.Name == payload.Name && edgeGroup.ID != portainer.EdgeGroupID(edgeGroupID) {
|
if edgeGroup.Name == payload.Name && edgeGroup.ID != portainer.EdgeGroupID(edgeGroupID) {
|
||||||
return httperror.BadRequest("Edge group name must be unique", errors.New("edge group name must be unique"))
|
return httperror.BadRequest("Edge group name must be unique", errors.New("edge group name must be unique"))
|
||||||
|
@ -133,23 +133,30 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
return httperror.InternalServerError("Unable to fetch Edge jobs", err)
|
return httperror.InternalServerError("Unable to fetch Edge jobs", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, endpointID := range endpointsToUpdate {
|
edgeStacks, err := tx.EdgeStack().EdgeStacks()
|
||||||
err = handler.updateEndpointStacks(tx, endpointID)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return httperror.InternalServerError("Unable to persist Environment relation changes inside the database", err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
for _, endpointID := range endpointsToUpdate {
|
||||||
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to get Environment from database", err)
|
return httperror.InternalServerError("Unable to get Environment from database", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = handler.updateEndpointStacks(tx, endpoint, edgeGroups, edgeStacks)
|
||||||
|
if err != nil {
|
||||||
|
return httperror.InternalServerError("Unable to persist Environment relation changes inside the database", err)
|
||||||
|
}
|
||||||
|
|
||||||
if !endpointutils.IsEdgeEndpoint(endpoint) {
|
if !endpointutils.IsEdgeEndpoint(endpoint) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var operation string
|
var operation string
|
||||||
if slices.Contains(newRelatedEndpoints, endpointID) {
|
if slices.Contains(newRelatedEndpoints, endpointID) && slices.Contains(oldRelatedEndpoints, endpointID) {
|
||||||
|
continue
|
||||||
|
} else if slices.Contains(newRelatedEndpoints, endpointID) {
|
||||||
operation = "add"
|
operation = "add"
|
||||||
} else if slices.Contains(oldRelatedEndpoints, endpointID) {
|
} else if slices.Contains(oldRelatedEndpoints, endpointID) {
|
||||||
operation = "remove"
|
operation = "remove"
|
||||||
|
@ -169,13 +176,8 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
return txResponse(w, edgeGroup, err)
|
return txResponse(w, edgeGroup, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *Handler) updateEndpointStacks(tx dataservices.DataStoreTx, endpointID portainer.EndpointID) error {
|
func (handler *Handler) updateEndpointStacks(tx dataservices.DataStoreTx, endpoint *portainer.Endpoint, edgeGroups []portainer.EdgeGroup, edgeStacks []portainer.EdgeStack) error {
|
||||||
relation, err := tx.EndpointRelation().EndpointRelation(endpointID)
|
relation, err := tx.EndpointRelation().EndpointRelation(endpoint.ID)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -185,16 +187,6 @@ func (handler *Handler) updateEndpointStacks(tx dataservices.DataStoreTx, endpoi
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeGroups, err := tx.EdgeGroup().ReadAll()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
edgeStacks, err := tx.EdgeStack().EdgeStacks()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
edgeStackSet := map[portainer.EdgeStackID]bool{}
|
edgeStackSet := map[portainer.EdgeStackID]bool{}
|
||||||
|
|
||||||
endpointEdgeStacks := edge.EndpointRelatedEdgeStacks(endpoint, endpointGroup, edgeGroups, edgeStacks)
|
endpointEdgeStacks := edge.EndpointRelatedEdgeStacks(endpoint, endpointGroup, edgeGroups, edgeStacks)
|
||||||
|
|
Loading…
Reference in New Issue