Skip to content

Commit 54d3a7f

Browse files
szachovyCopilot
andcommitted
Make swarm.init() and network.create() idempotent
Catch APIError on swarm.init() for already-in-swarm case. Check existing networks before creating superset-network. Re-runs after partial failure no longer fail on these operations. Closes #50 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0ab8ce7 commit 54d3a7f

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* CI workflow to build and push service images to GitHub Container Registry on master merge. (#97)
1717
* Pull-first with local build fallback for container images during deployment. (#97)
1818

19+
### Fixed
20+
21+
* Make swarm.init() and network.create() idempotent for re-run support. (#50)
22+
1923
### Changed
2024

2125
* Completed [ARCHITECTURE.md](./docs/ARCHITECTURE.md) (#93)

src/container.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,15 @@ def __init__(self, client: docker.client.DockerClient, virtual_ip_address: str)
384384
self.healthcheck_retries = 5
385385

386386
def initialize_swarm(self) -> None:
387-
self.client.swarm.init(advertise_addr=self.virtual_ip_address)
387+
try:
388+
self.client.swarm.init(advertise_addr=self.virtual_ip_address)
389+
except docker.errors.APIError:
390+
pass # Already in a swarm
388391

389392
def create_network(self) -> None:
390-
self.client.networks.create(name='superset-network', driver='overlay', attachable=True)
393+
existing = self.client.networks.list(names=['superset-network'])
394+
if not existing:
395+
self.client.networks.create(name='superset-network', driver='overlay', attachable=True)
391396

392397
def run(self) -> None:
393398
self.initialize_swarm()

0 commit comments

Comments
 (0)