fix(docker): log cleanup errors during endpointforceupdate [EE-7055] (#11762)

pull/11820/head
Ali 2024-05-13 15:34:13 +12:00 committed by GitHub
parent 6b5a402962
commit e73b1aa49c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/request"
"github.com/portainer/portainer/pkg/libhttp/response"
"github.com/rs/zerolog/log"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
@ -94,10 +95,14 @@ func (handler *Handler) endpointForceUpdateService(w http.ResponseWriter, r *htt
go func() {
images.EvictImageStatus(payload.ServiceID)
images.EvictImageStatus(service.Spec.Labels[consts.SwarmStackNameLabel])
containers, _ := dockerClient.ContainerList(context.TODO(), container.ListOptions{
// ignore errors from this cleanup function, log them instead
containers, err := dockerClient.ContainerList(context.TODO(), container.ListOptions{
All: true,
Filters: filters.NewArgs(filters.Arg("label", consts.SwarmServiceIdLabel+"="+payload.ServiceID)),
})
if err != nil {
log.Warn().Err(err).Str("Environment", endpoint.Name).Msg("Error listing containers")
}
for _, container := range containers {
images.EvictImageStatus(container.ID)

View File

@ -77,7 +77,6 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r
payload.Name = handler.SwarmStackManager.NormalizeStackName(payload.Name)
isUnique, err := handler.checkUniqueStackNameInDocker(endpoint, payload.Name, 0, true)
if err != nil {
return httperror.InternalServerError("Unable to check for name collision", err)
}