1
0
mirror of https://github.com/offen/docker-volume-backup.git synced 2025-06-25 14:32:52 +02:00

Check whether container and service labels collide

This commit is contained in:
Frederik Ring
2024-01-27 13:08:06 +01:00
parent a430772e29
commit 6d0e96ec40
3 changed files with 82 additions and 0 deletions

View File

@ -395,6 +395,26 @@ func (s *script) stopContainersAndServices() (func() error, error) {
return noop, nil
}
if isDockerSwarm {
for _, container := range containersToStop {
if swarmServiceID, ok := container.Labels["com.docker.swarm.service.id"]; ok {
parentService, _, err := s.cli.ServiceInspectWithRaw(context.Background(), swarmServiceID, types.ServiceInspectOptions{})
if err != nil {
return noop, fmt.Errorf("(*script).stopContainersAndServices: error querying for parent service with ID %s: %w", swarmServiceID, err)
}
for label := range parentService.Spec.Labels {
if label == "docker-volume-backup.stop-during-backup" {
return noop, fmt.Errorf(
"(*script).stopContainersAndServices: container %s is labeled to stop but has parent service %s which is also labeled, cannot continue",
container.Names[0],
parentService.Spec.Name,
)
}
}
}
}
}
s.logger.Info(
fmt.Sprintf(
"Stopping %d out of %d running container(s) and scaling down %d out of %d active service(s) as they were labeled %s.",