fix(sys-svc-compose): let docker stack deploy adopt pre-created overlays

A network pre-created by the util carried only the compose labels, so
`docker stack deploy` could not recognise it as belonging to the stack:
`getStackNetworks` filters on `com.docker.stack.namespace`, finds nothing,
and the deploy retries the create and aborts with "network with name
<entity> already exists".

This is reachable whenever a network is pre-created for a role whose stack
has not deployed yet. web-app-prometheus does exactly that for every
native-metrics app, which broke the swarm deploy of web-app-openbao.

Stamping the namespace label makes the owning stack adopt the existing
network instead of recreating it. Verified against docker 29.1.3 on a
throwaway swarm: without the label the deploy fails as above, with it the
stack adopts the same network id, and an external consumer stack deploying
with --prune leaves the network intact.
This commit is contained in:
evangelostsak committed 2026-09-09 14:00:05 +02:00
1 parent 5dbc440b66
commit dc6aeee471
1 file changed
+4
@@ -39,6 +39,10 @@
- "com.docker.compose.network={{ lookup('shared_network_key', network_role_id) }}"
- --label
- "com.docker.compose.project={{ network_role_id | get_entity_name }}"
# Exception: without the stack namespace label `docker stack deploy` cannot see this
# network as one of its own, so it retries the create and dies on "already exists".
- --label
- "com.docker.stack.namespace={{ network_role_id | get_entity_name }}"
- "{{ network_role_id | get_entity_name }}"
when:
- (SWARM_CLUSTER_AVAILABLE | bool) and not (lookup('config', network_role_id, 'networks.local.force_bridge', false) | bool)