Skip to content

Commit d20179d

Browse files
committed
PoC: Add netplan as alternative backend to nmstate
Signed-off-by: Enrique Llorente <[email protected]>
1 parent d01674b commit d20179d

35 files changed

+2125
-33
lines changed

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ Cluster configuration via environment variables:
183183
- `KUBECONFIG`: Path to kubeconfig (auto-detected via ./cluster/kubeconfig.sh)
184184
- `NMSTATE_VERSION`: When set to `latest`, uses nmstate-git from copr during `make cluster-up`
185185
- `NM_VERSION`: When set to `latest`, installs NetworkManager from copr networkmanager/NetworkManager-main repository during `make cluster-up`
186+
- `NETWORK_RENDERER`: Network renderer to use (default: `NetworkManager`, options: `NetworkManager`, `networkd`)
187+
- `NetworkManager`: Uses NetworkManager for all network interfaces
188+
- `networkd`: Uses systemd-networkd for eth1/eth2, NetworkManager for eth0 (cluster connectivity)
186189

187190
Network interface names vary by provider:
188191
- k8s providers: eth0, eth1, eth2

BACKEND_SELECTION.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# Backend Selection for kubernetes-nmstate
2+
3+
This document explains how to select the network configuration backend when deploying kubernetes-nmstate to a development cluster.
4+
5+
## Available Backends
6+
7+
- **nmstate** (default): Uses nmstatectl and NetworkManager for network configuration
8+
- **netplan**: Uses netplan's D-Bus API for network configuration (PoC)
9+
10+
## Using the BACKEND Variable
11+
12+
The `BACKEND` Makefile variable allows you to select which backend to use when deploying to a local development cluster.
13+
14+
### Default Behavior (nmstate)
15+
16+
```bash
17+
make cluster-sync
18+
```
19+
20+
This deploys kubernetes-nmstate with the default nmstate backend.
21+
22+
### Using Netplan Backend
23+
24+
To deploy with the netplan backend, set the `BACKEND` variable:
25+
26+
```bash
27+
BACKEND=netplan make cluster-sync
28+
```
29+
30+
Or export it before running make:
31+
32+
```bash
33+
export BACKEND=netplan
34+
make cluster-sync
35+
```
36+
37+
## How It Works
38+
39+
1. The `BACKEND` variable is defined in the Makefile (defaults to `nmstate`)
40+
2. It's exported so it's available to shell scripts
41+
3. The `cluster/sync.sh` script patches the NMState CR with the selected backend
42+
4. The operator configures handler pods with the appropriate `NMSTATE_BACKEND` environment variable
43+
5. Handlers initialize the selected backend at startup
44+
45+
## Example Workflow
46+
47+
### Testing with nmstate (default)
48+
49+
```bash
50+
# Build images
51+
make handler operator
52+
53+
# Deploy to cluster
54+
make cluster-sync
55+
56+
# Verify deployment
57+
kubectl get nmstate nmstate -o jsonpath='{.spec.backend}'
58+
# Output: (empty - defaults to nmstate)
59+
60+
# Check handler pods are using nmstate
61+
kubectl get pods -n nmstate -l component=kubernetes-nmstate-handler -o jsonpath='{.items[0].spec.containers[0].env[?(@.name=="NMSTATE_BACKEND")].value}'
62+
# Output: nmstate
63+
```
64+
65+
### Testing with netplan
66+
67+
```bash
68+
# Build images
69+
make handler operator
70+
71+
# Deploy with netplan backend
72+
BACKEND=netplan make cluster-sync
73+
74+
# Verify deployment
75+
kubectl get nmstate nmstate -o jsonpath='{.spec.backend}'
76+
# Output: netplan
77+
78+
# Check handler pods are using netplan
79+
kubectl get pods -n nmstate -l component=kubernetes-nmstate-handler -o jsonpath='{.items[0].spec.containers[0].env[?(@.name=="NMSTATE_BACKEND")].value}'
80+
# Output: netplan
81+
82+
# Monitor handler logs for netplan D-Bus interactions
83+
kubectl logs -n nmstate -l component=kubernetes-nmstate-handler -f
84+
```
85+
86+
### Switching Backends
87+
88+
To switch from one backend to another:
89+
90+
```bash
91+
# Switch to netplan
92+
BACKEND=netplan make cluster-sync
93+
94+
# The operator will update the NMState CR
95+
# Handler pods will be restarted with the new backend
96+
97+
# Switch back to nmstate
98+
BACKEND=nmstate make cluster-sync
99+
# Or simply:
100+
make cluster-sync
101+
```
102+
103+
## Implementation Details
104+
105+
### Makefile
106+
107+
```makefile
108+
# Backend selection for network configuration (nmstate or netplan)
109+
export BACKEND ?= nmstate
110+
```
111+
112+
### cluster/sync.sh
113+
114+
```bash
115+
function patch_handler_backend() {
116+
if [ -n "${BACKEND}" ] && [ "${BACKEND}" != "nmstate" ]; then
117+
echo "Patching NMState CR to use backend: ${BACKEND}"
118+
$kubectl patch -f $nmstate_cr_manifest --patch "{\"spec\": {\"backend\": \"${BACKEND}\"}}" --type=merge
119+
fi
120+
}
121+
```
122+
123+
This function:
124+
- Only patches if `BACKEND` is set and not the default "nmstate"
125+
- Uses `kubectl patch` to update the NMState CR's `spec.backend` field
126+
- The operator watches for changes and updates handler pods accordingly
127+
128+
## Requirements by Backend
129+
130+
### nmstate Backend
131+
132+
**Requirements:**
133+
- NetworkManager >= 1.22 running on nodes
134+
- nmstatectl CLI available
135+
- D-Bus system bus access
136+
137+
**Already provided by default handler image:**
138+
- nmstate package
139+
- NetworkManager dependencies
140+
141+
### netplan Backend (PoC)
142+
143+
**Requirements:**
144+
- netplan >= 0.103 installed on nodes
145+
- netplan D-Bus service running (`io.netplan.Netplan`)
146+
- D-Bus system bus access (already available)
147+
- godbus/dbus/v5 Go library (needs to be added to go.mod)
148+
149+
**Additional setup needed:**
150+
- Handler container image needs netplan package
151+
- Format conversion between nmstate and netplan YAML
152+
153+
## Troubleshooting
154+
155+
### Backend not applied
156+
157+
If the backend doesn't change:
158+
159+
```bash
160+
# Check NMState CR
161+
kubectl get nmstate nmstate -o yaml
162+
163+
# Check if operator is running
164+
kubectl get pods -n nmstate -l component=kubernetes-nmstate-operator
165+
166+
# Check operator logs
167+
kubectl logs -n nmstate -l component=kubernetes-nmstate-operator
168+
```
169+
170+
### Handler pods not updated
171+
172+
```bash
173+
# Restart handler pods to pick up new configuration
174+
kubectl delete pods -n nmstate -l component=kubernetes-nmstate-handler
175+
176+
# Watch pods restart
177+
kubectl get pods -n nmstate -w
178+
```
179+
180+
### Netplan backend errors
181+
182+
```bash
183+
# Check if netplan D-Bus service is running on nodes
184+
./cluster/ssh.sh node01 "systemctl status netplan-dbus || systemctl status netplan"
185+
186+
# Check D-Bus service availability
187+
./cluster/ssh.sh node01 "busctl list | grep netplan"
188+
189+
# Check handler logs for D-Bus errors
190+
kubectl logs -n nmstate -l component=kubernetes-nmstate-handler | grep -i dbus
191+
```
192+
193+
## Production Considerations
194+
195+
**Note:** The `BACKEND` Makefile variable is for **development and testing only**. In production:
196+
197+
1. Set the backend in the NMState CR directly:
198+
```yaml
199+
apiVersion: nmstate.io/v1
200+
kind: NMState
201+
metadata:
202+
name: nmstate
203+
spec:
204+
backend: netplan # or nmstate
205+
```
206+
207+
2. Ensure nodes have the required backend software installed
208+
3. Test thoroughly before deploying to production
209+
4. Monitor handler logs for backend-specific errors
210+
5. Have a rollback plan to switch backends if needed

0 commit comments

Comments
 (0)