fix: attach extra_networks to service containers#328
Conversation
ServiceContainerSpec was silently dropping extra_networks from orchestrator_opts. Services were only attached to bridge and the database overlay, even when extra networks were specified. Mirror the existing Postgres spec.go pattern to append ExtraNetworks with target and aliases.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors Swarm orchestrator option handling, forwards user-configured extra Swarm networks into service task network attachments, clarifies in-code behavior for extra volumes/driver options, and adds validation and unit tests to reject/accept specific Swarm orchestrator fields at API validation. Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 7 |
| Duplication | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/internal/orchestrator/swarm/spec.go (1)
74-81: Inconsistent variable usage: useswarmOpts.ExtraNetworksfor consistency.Line 76 accesses
instance.OrchestratorOpts.Swarm.ExtraNetworksdirectly, while lines 66-72 use the extractedswarmOptsvariable forExtraLabelsandExtraVolumes. The newservice_spec.gocode consistently usesswarmOpts.ExtraNetworks.♻️ Suggested fix for consistency
// NOTE: DriverOpts on ExtraNetworkSpec is accepted by the API but not // passed through here — add if needed. - for _, net := range instance.OrchestratorOpts.Swarm.ExtraNetworks { + for _, net := range swarmOpts.ExtraNetworks { networks = append(networks, swarm.NetworkAttachmentConfig{ Target: net.ID, Aliases: net.Aliases, }) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/internal/orchestrator/swarm/spec.go` around lines 74 - 81, The loop building NetworkAttachmentConfig uses instance.OrchestratorOpts.Swarm.ExtraNetworks directly while earlier code uses the extracted swarmOpts variable; change the loop to iterate over swarmOpts.ExtraNetworks instead to be consistent with how ExtraLabels and ExtraVolumes are accessed (look for the variable swarmOpts and the loop that appends to networks with swarm.NetworkAttachmentConfig and replace the source collection with swarmOpts.ExtraNetworks).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/internal/orchestrator/swarm/spec.go`:
- Around line 74-81: The loop building NetworkAttachmentConfig uses
instance.OrchestratorOpts.Swarm.ExtraNetworks directly while earlier code uses
the extracted swarmOpts variable; change the loop to iterate over
swarmOpts.ExtraNetworks instead to be consistent with how ExtraLabels and
ExtraVolumes are accessed (look for the variable swarmOpts and the loop that
appends to networks with swarm.NetworkAttachmentConfig and replace the source
collection with swarmOpts.ExtraNetworks).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8ef1eb1c-b5c0-408a-824d-3752ca728ade
📒 Files selected for processing (3)
server/internal/orchestrator/swarm/service_spec.goserver/internal/orchestrator/swarm/service_spec_test.goserver/internal/orchestrator/swarm/spec.go
Return API validation errors when a service spec includes extra_volumes or driver_opts on extra_networks, rather than silently ignoring them at deploy time.
Summary
extra_networksfromorchestrator_opts.swarminto the service container spec, matching the existing Postgres container behaviorswarmOptslocal variable to consolidate nil-guard (consistent withspec.go)ExtraVolumes(not supported for services) andDriverOpts(not passed through) are intentionally omittedTest plan
make testpassesorchestrator_opts.swarm.extra_networks—docker service inspectshould show the extra network(s)orchestrator_opts— only bridge and database overlay attached (no regression)PLAT-535