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

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

This commit is contained in:
matias-portainer 2023-01-17 09:47:14 -03:00 committed by GitHub
parent de05fa869d
commit eeff16a300
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,7 @@ import (
"github.com/portainer/libhttp/response" "github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
httperrors "github.com/portainer/portainer/api/http/errors" httperrors "github.com/portainer/portainer/api/http/errors"
"github.com/portainer/portainer/api/internal/endpointutils"
) )
// @id EndpointDelete // @id EndpointDelete
@ -124,6 +125,26 @@ 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 {
delete(edgeJob.Endpoints, endpoint.ID)
err = handler.DataStore.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob)
if err != nil {
return httperror.InternalServerError("Unable to update edge job", err)
}
}
}
return response.Empty(w) return response.Empty(w)
} }