mirror of https://github.com/portainer/portainer
fix(edgegroups): fix updateEndpointStacks() EE-5699 (#9154)
parent
74515f102d
commit
e4ae4d5312
|
@ -33,6 +33,29 @@ func (payload *edgeGroupCreatePayload) Validate(r *http.Request) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calculateEndpointsOrTags(tx dataservices.DataStoreTx, edgeGroup *portainer.EdgeGroup, endpoints []portainer.EndpointID, tagIDs []portainer.TagID) error {
|
||||||
|
if edgeGroup.Dynamic {
|
||||||
|
edgeGroup.TagIDs = tagIDs
|
||||||
|
} else {
|
||||||
|
endpointIDs := []portainer.EndpointID{}
|
||||||
|
|
||||||
|
for _, endpointID := range endpoints {
|
||||||
|
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
||||||
|
if err != nil {
|
||||||
|
return httperror.InternalServerError("Unable to retrieve environment from the database", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if endpointutils.IsEdgeEndpoint(endpoint) {
|
||||||
|
endpointIDs = append(endpointIDs, endpoint.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edgeGroup.Endpoints = endpointIDs
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// @id EdgeGroupCreate
|
// @id EdgeGroupCreate
|
||||||
// @summary Create an EdgeGroup
|
// @summary Create an EdgeGroup
|
||||||
// @description **Access policy**: administrator
|
// @description **Access policy**: administrator
|
||||||
|
@ -74,21 +97,8 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
|
||||||
PartialMatch: payload.PartialMatch,
|
PartialMatch: payload.PartialMatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
if edgeGroup.Dynamic {
|
if err := calculateEndpointsOrTags(tx, edgeGroup, payload.Endpoints, payload.TagIDs); err != nil {
|
||||||
edgeGroup.TagIDs = payload.TagIDs
|
return err
|
||||||
} else {
|
|
||||||
endpointIDs := []portainer.EndpointID{}
|
|
||||||
for _, endpointID := range payload.Endpoints {
|
|
||||||
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
|
||||||
if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to retrieve environment from the database", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if endpointutils.IsEdgeEndpoint(endpoint) {
|
|
||||||
endpointIDs = append(endpointIDs, endpoint.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
edgeGroup.Endpoints = endpointIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.EdgeGroup().Create(edgeGroup)
|
err = tx.EdgeGroup().Create(edgeGroup)
|
||||||
|
|
|
@ -99,21 +99,8 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
oldRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups)
|
oldRelatedEndpoints := edge.EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups)
|
||||||
|
|
||||||
edgeGroup.Dynamic = payload.Dynamic
|
edgeGroup.Dynamic = payload.Dynamic
|
||||||
if edgeGroup.Dynamic {
|
if err := calculateEndpointsOrTags(tx, edgeGroup, payload.Endpoints, payload.TagIDs); err != nil {
|
||||||
edgeGroup.TagIDs = payload.TagIDs
|
return err
|
||||||
} else {
|
|
||||||
endpointIDs := []portainer.EndpointID{}
|
|
||||||
for _, endpointID := range payload.Endpoints {
|
|
||||||
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
|
||||||
if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to retrieve environment from the database", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if endpointutils.IsEdgeEndpoint(endpoint) {
|
|
||||||
endpointIDs = append(endpointIDs, endpoint.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
edgeGroup.Endpoints = endpointIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if payload.PartialMatch != nil {
|
if payload.PartialMatch != nil {
|
||||||
|
@ -138,6 +125,13 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the edgeGroups with the modified edgeGroup for updateEndpointStacks()
|
||||||
|
for i := range edgeGroups {
|
||||||
|
if edgeGroups[i].ID == edgeGroup.ID {
|
||||||
|
edgeGroups[i] = *edgeGroup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, endpointID := range endpointsToUpdate {
|
for _, endpointID := range endpointsToUpdate {
|
||||||
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue