1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

fix(edgejobs): remove endpoint from edge job mapping on endpoint deletion EE-4764 (#8212)

This commit is contained in:
matias-portainer 2023-01-17 09:47:23 -03:00 committed by GitHub
parent 1c180346e4
commit 6570f1f8eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api"
httperrors "github.com/portainer/portainer/api/http/errors"
"github.com/portainer/portainer/api/internal/endpointutils"
)
// @id EndpointDelete
@ -124,6 +125,28 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
}
}
if !endpointutils.IsEdgeEndpoint(endpoint) {
return response.Empty(w)
}
edgeJobs, err := handler.DataStore.EdgeJob().EdgeJobs()
if err != nil {
return httperror.InternalServerError("Unable to retrieve edge jobs from the database", err)
}
for idx := range edgeJobs {
edgeJob := &edgeJobs[idx]
if _, ok := edgeJob.Endpoints[endpoint.ID]; ok {
err = handler.DataStore.EdgeJob().UpdateEdgeJobFunc(edgeJob.ID, func(j *portainer.EdgeJob) {
delete(j.Endpoints, endpoint.ID)
})
if err != nil {
return httperror.InternalServerError("Unable to update edge job", err)
}
}
}
return response.Empty(w)
}