Skip to content

Commit 72acbfb

Browse files
Use the same bridge for the mgmt network and external connectivity (#216)
1 parent 3348f45 commit 72acbfb

File tree

10 files changed

+32
-21
lines changed

10 files changed

+32
-21
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ external_network:
127127
--driver=bridge \
128128
--gateway=203.0.113.1 \
129129
--subnet=203.0.113.0/24 \
130+
--ip-range=203.0.113.0/26 \
130131
--opt "com.docker.network.driver.mtu=9000" \
131132
--opt "com.docker.network.bridge.name=mini_lab_ext" \
132133
--opt "com.docker.network.bridge.enable_ip_masquerade=true" && \
@@ -276,7 +277,7 @@ ssh-machine:
276277
.PHONY: test-connectivity-to-external-service
277278
test-connectivity-to-external-service:
278279
@for i in $$(seq 1 $(MAX_RETRIES)); do \
279-
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://203.0.113.10" > /dev/null 2>&1; then \
280+
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://203.0.113.100" > /dev/null 2>&1; then \
280281
echo "Connected successfully"; \
281282
exit 0; \
282283
else \
@@ -295,8 +296,8 @@ test-connectivity-to-external-service:
295296

296297
.PHONY: dev-env
297298
dev-env:
298-
@echo "export METALCTL_API_URL=http://api.172.17.0.1.nip.io:8080/metal"
299-
@echo "export METALCTL_HMAC=metal-admin"
299+
@echo "export METALCTL_API_URL=${METALCTL_API_URL}"
300+
@echo "export METALCTL_HMAC=${METALCTL_HMAC}"
300301
@echo "export KUBECONFIG=$(KUBECONFIG)"
301302

302303
## Gardener integration

docs/network.svg

Lines changed: 1 addition & 1 deletion
Loading

files/certs/grpc/server.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"CN": "metal-api",
33
"hosts": [
4-
"172.17.0.1"
4+
"172.17.0.1",
5+
"203.0.113.1"
56
],
67
"key": {
78
"algo": "rsa",

files/external_service/network.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22
set -o errexit -o xtrace
33

4-
ip addr add 203.0.113.10/24 dev mini_lab_ext
4+
ip addr add 203.0.113.100/24 dev mini_lab_ext
55
ip route add 203.0.113.128/25 via 203.0.113.128 dev mini_lab_ext

images/sonic/launch.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python3
22
import fcntl
33
import glob
4+
import ipaddress
45
import json
56
import logging
67
import os
@@ -216,6 +217,8 @@ def wait_until_all_interfaces_are_connected(interfaces: int) -> None:
216217
time.sleep(1)
217218

218219

220+
# This function works only for IPv4 interfaces.
221+
# See: man 7 netdevice
219222
def get_ip_address(iface: str) -> str:
220223
# Source: https://bit.ly/3dROGBN
221224
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -226,6 +229,20 @@ def get_ip_address(iface: str) -> str:
226229
)[20:24])
227230

228231

232+
# This function works only for IPv4 interfaces
233+
# See: man 7 netdevice
234+
def get_netmask(iface: str) -> str:
235+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
236+
netmask = socket.inet_ntoa(fcntl.ioctl(
237+
s.fileno(),
238+
0x891b, # SIOCGIFNETMASK
239+
struct.pack('256s', iface.encode('utf-8'))
240+
)[20:24])
241+
return str(ipaddress.ip_network(f"0.0.0.0/{netmask}").prefixlen)
242+
243+
244+
# This function works only for IPv4 interfaces
245+
# Set: man 7 netdevice
229246
def get_mac_address(iface: str) -> str:
230247
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
231248
mac = fcntl.ioctl(
@@ -236,6 +253,7 @@ def get_mac_address(iface: str) -> str:
236253
return ':'.join('%02x' % b for b in mac)
237254

238255

256+
# This function works only for IPv4 interfaces
239257
def get_default_gateway() -> str:
240258
# Source: https://splunktool.com/python-get-default-gateway-for-a-local-interfaceip-address-in-linux
241259
with open("/proc/net/route") as fh:
@@ -284,6 +302,7 @@ def parse_port_config() -> dict[str, dict]:
284302

285303

286304
def create_config_db(hwsku: str) -> dict:
305+
mgmt_interface_cidr = get_ip_address("eth0") + "/" + get_netmask("eth0")
287306
return {
288307
'AUTO_TECHSUPPORT': {
289308
'GLOBAL': {
@@ -315,7 +334,7 @@ def create_config_db(hwsku: str) -> dict:
315334
}
316335
},
317336
'MGMT_INTERFACE': {
318-
f'eth0|{get_ip_address("eth0")}/16': {
337+
f'eth0|{mgmt_interface_cidr}': {
319338
'gwaddr': get_default_gateway(),
320339
}
321340
},
File renamed without changes.

inventories/group_vars/control-plane/metal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
metal_set_resource_limits: no
3-
metal_check_api_health_endpoint: http://api.172.17.0.1.nip.io:8080/metal/v1/health
3+
metal_check_api_health_endpoint: http://api.{{ metal_control_plane_ingress_dns }}:8080/metal/v1/health
44

55
# metal_helm_chart_local_path: /helm-charts/charts/metal-control-plane
66

inventories/group_vars/partition/common.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ metal_partition_timezone: Europe/Berlin
33
metal_partition_id: mini-lab
44

55
metal_partition_metal_api_protocol: http
6-
metal_partition_metal_api_addr: api.172.17.0.1.nip.io
6+
metal_partition_metal_api_addr: api.{{ metal_control_plane_ingress_dns }}
77
metal_partition_metal_api_port: 8080
88
metal_partition_metal_api_basepath: /metal/
99
metal_partition_metal_api_hmac_edit_key: metal-edit

inventories/group_vars/sonic/main.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ sonic_mgmtif_gateway: "172.17.0.1"
1515

1616
sonic_mgmt_vrf: false
1717

18-
sonic_nameservers:
19-
- "172.17.0.1"
20-
- "1.1.1.1"
21-
- "1.0.0.1"
18+
sonic_nameservers: "{{ router_nameservers }}"
2219

2320
sonic_ip_masquerade: true
2421

mini-lab.capms.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ name: mini-lab
33
prefix: ""
44

55
mgmt:
6-
network: bridge
6+
network: mini_lab_ext
77

88
topology:
99
nodes:
10-
metal-control-plane-control-plane:
11-
kind: ext-container
12-
exec:
13-
- ip addr add 203.0.113.100/24 dev mini_lab_ext
14-
- ip route add 203.0.113.128/25 via 203.0.113.128 dev mini_lab_ext
1510
exit:
1611
kind: linux
1712
image: quay.io/frrouting/frr:10.0.1
@@ -51,8 +46,6 @@ topology:
5146
QEMU_MACHINE_CPU_CORES: 2
5247
QEMU_MACHINE_DISK_SIZE: 20G
5348
links:
54-
- endpoints: ["metal-control-plane-control-plane:mini_lab_ext", "mini_lab_ext:kind"]
55-
mtu: 9000
5649
- endpoints: ["exit:mini_lab_ext", "mini_lab_ext:exit"]
5750
mtu: 9000
5851
- endpoints: ["leaf01:Ethernet0", "vms:lan0"]

0 commit comments

Comments
 (0)