Skip to content

Commit c49b7cf

Browse files
committed
Fix MetalLB L2Advertisement to use baremetal network interface only
1 parent 05f31ce commit c49b7cf

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

ci-operator/step-registry/hypershift/kubevirt/baremetalds/metallb/hypershift-kubevirt-baremetalds-metallb-commands.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ set -o errexit
55
set -o pipefail
66
set -x
77

8+
POOL_RANGE="192.168.111.30-192.168.111.50"
9+
10+
# Pin L2 announcements to the baremetal network interface only.
11+
# Without this, extra network interfaces (e.g. from nmstate) can cause
12+
# MetalLB speakers to announce VIPs on the wrong interface, making
13+
# LoadBalancer IPs unreachable from the infra cluster.
14+
# In OVN environments the baremetal network (192.168.111.0/24) lives on
15+
# br-ex (OVS external bridge). With OpenShiftSDN the raw NIC keeps the
16+
# IP directly. Detect the network type and choose accordingly.
17+
NETWORK_TYPE=$(oc get network.config cluster -o jsonpath='{.status.networkType}')
18+
if [[ "${NETWORK_TYPE}" == "OVNKubernetes" ]]; then
19+
METALLB_IFACE="br-ex"
20+
else
21+
METALLB_IFACE="enp2s0"
22+
fi
23+
echo "Detected network type ${NETWORK_TYPE}, using interface ${METALLB_IFACE} for L2 advertisements"
24+
825
oc create -f - <<EOF
926
apiVersion: metallb.io/v1beta1
1027
kind: MetalLB
@@ -21,7 +38,7 @@ metadata:
2138
namespace: metallb-system
2239
spec:
2340
addresses:
24-
- 192.168.111.30-192.168.111.50
41+
- ${POOL_RANGE}
2542
EOF
2643

2744
oc create -f - <<EOF
@@ -33,4 +50,6 @@ metadata:
3350
spec:
3451
ipAddressPools:
3552
- metallb
53+
interfaces:
54+
- ${METALLB_IFACE}
3655
EOF

0 commit comments

Comments
 (0)