Add additional check if all containers have been removed

This commit is contained in:
Frederik Ring 2024-01-27 15:37:31 +01:00
parent bf1d13b78c
commit bb37b8b1d8

View File

@ -478,6 +478,25 @@ func (s *script) stopContainersAndServices() (func() error, error) {
} else {
scaledDownServices = append(scaledDownServices, service)
}
// progress.ServiceProgress returns too early, so we need to manually check
// whether all containers belonging to the service have actually been removed
for {
containers, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{
Key: "label",
Value: fmt.Sprintf("com.docker.swarm.service.id=%s", service.ID),
}),
})
if err != nil {
scaleDownErrors = append(scaleDownErrors, err)
break
}
if len(containers) == 0 {
break
}
time.Sleep(time.Second)
}
}
}