Implement automatic bridge lifecycle management for internal-only bridges #2850
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements automatic bridge creation and deletion for bridge nodes that only connect containerlab-managed interfaces, addressing issue #XXX.
Problem
Previously, users had to manually create and manage Linux bridges when using the
bridge
node kind in topologies. This created friction for the common use case where bridges only connect containerlab nodes (internal-only bridges) and don't interface with external systems.Solution
The implementation adds automatic bridge lifecycle management through:
1. Automatic Bridge Creation
2. Automatic Bridge Deletion
3. Safety Mechanisms
Key Changes
nodes/bridge/bridge.go
:PreDeploy()
method for automatic bridge creationDelete()
method with intelligent cleanup logicshouldAutoDelete()
heuristics for safe bridge identificationCheckDeploymentConditions()
to not require pre-existing bridgeslinks/endpoint_bridge.go
:CheckBridgeExists()
to allow non-existent bridges for auto-creation scenarioslab-examples/br01/br01.clab.yml
:Behavior
Deploy: Containerlab creates the bridge if it doesn't exist
Destroy: Containerlab removes the bridge if no interfaces remain and it was auto-created
Testing
Verified the implementation handles:
This change significantly improves the user experience for internal-only bridge scenarios while maintaining safety and backward compatibility.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.