fix(snapshot): prevent snapshot containers from fast failing in Swarm mode (#8308)

pull/8485/head
Oscar Zhou 2023-02-13 14:42:10 +13:00 committed by GitHub
parent 0befdacc0e
commit cef9255161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 14 deletions

View File

@ -167,9 +167,15 @@ func snapshotContainers(snapshot *portainer.DockerSnapshot, cli *client.Client)
// snapshot GPUs
response, err := cli.ContainerInspect(context.Background(), container.ID)
if err != nil {
// Inspect a container will fail when the container runs on a different
// Swarm node, so it is better to log the error instead of return error
// when the Swarm mode is enabled
if !snapshot.Swarm {
return err
} else {
log.Info().Str("container", container.ID).Err(err).Msg("unable to inspect container in other Swarm nodes")
}
} else {
var gpuOptions *_container.DeviceRequest = nil
for _, deviceRequest := range response.HostConfig.Resources.DeviceRequests {
if deviceRequest.Driver == "nvidia" || deviceRequest.Capabilities[0][0] == "gpu" {
@ -186,6 +192,7 @@ func snapshotContainers(snapshot *portainer.DockerSnapshot, cli *client.Client)
}
}
}
}
if strings.Contains(container.Status, "(healthy)") {
healthyContainers++