Skip to content

Conversation

@MoeSalah1999
Copy link
Contributor

Proposed Commit Message

**Problem**

Cloud-init currently embeds platform-specific networking logic directly inside Distro.apply_network_config. This results in:

- High cross-platform coupling and conditional branching (if datasource == "MAAS": ...)
- Contributor friction: changes for one platform risk breaking others
- Mock-heavy tests that do not enforce platform contracts
- MyPy type errors due to apply() and apply_netplan() being referenced in adapters

**Solution**
This PR refactors MAAS networking into a dedicated adapter and introduces a render-only interface contract, leaving actual network application in Distro.apply_network_config.

Key changes:

1-Networking Adapter Interface:

- NetworkingAdapter defines a single abstract method render()
- Adapters only transform network config; they do not apply it
- Ensures type safety, mypy compliance, and clear platform contracts

2-MAAS Adapter:

- MAASNetworkingAdapter implements render()
- Encapsulates MAAS-specific network transformations (OVS bridge handling, MTU defaults)
- Drop-in replacement: does not change runtime behavior

3-Integration into apply_network_config():

- Optional adapter lookup via get_networking_adapter(self._datasource)
- Calls render() before parsing and writing network state
- Preserves bring_up semantics and existing renderer/activator behavior

4-Tests:

- Contract test verifies MAAS adapter implements render() and is a subclass of NetworkingAdapter
- Removed invalid apply() assertion in tests
- Platform-specific MAAS tests can verify rendered network config


**Motivation**

- Reduces cross-platform branching in core logic
- Encapsulates MAAS networking logic in a clear adapter
- Improves contributor confidence and CI feedback
- Provides a foundation for adding adapters for other cloud platforms

Fixes GH-6119

Additional Context

Next Steps:

  1. Add adapters for EC2, Azure, GCE following the same contract
  2. Refactor other platform-specific branches in apply_network_config
  3. Add platform-specific golden tests for each adapter

I'll probably do this in a follow up PR.

Test Steps

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant