1
0
mirror of https://github.com/offen/docker-volume-backup.git synced 2025-11-29 05:46:50 +02:00

Swarm mode check fails on non-standard Info responses (#376)

* Swarm mode check fails on non-standard Info responses

* Add unit test

* Remove balena tests, add note to docs
This commit is contained in:
Frederik Ring
2024-02-27 22:12:36 +01:00
committed by GitHub
parent 6c8b0ccce5
commit 5abfe5bb39
3 changed files with 102 additions and 3 deletions

View File

@@ -81,6 +81,16 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
}
}
func isSwarm(c interface {
Info(context.Context) (types.Info, error)
}) (bool, error) {
info, err := c.Info(context.Background())
if err != nil {
return false, errwrap.Wrap(err, "error getting docker info")
}
return info.Swarm.LocalNodeState != "" && info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive, nil
}
// stopContainersAndServices stops all Docker containers that are marked as to being
// stopped during the backup and returns a function that can be called to
// restart everything that has been stopped.
@@ -89,11 +99,10 @@ func (s *script) stopContainersAndServices() (func() error, error) {
return noop, nil
}
dockerInfo, err := s.cli.Info(context.Background())
isDockerSwarm, err := isSwarm(s.cli)
if err != nil {
return noop, errwrap.Wrap(err, "error getting docker info")
return noop, errwrap.Wrap(err, "error determining swarm state")
}
isDockerSwarm := dockerInfo.Swarm.LocalNodeState != "inactive"
labelValue := s.c.BackupStopDuringBackupLabel
if s.c.BackupStopContainerLabel != "" {