Skip to content

Commit c7ec3cc

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

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

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

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

8+
POOL_RANGE="192.168.111.30-192.168.111.50"
9+
POOL_ADDRESS="${POOL_RANGE%%-*}"
10+
11+
# Determine which network interface routes to the IP pool subnet so that
12+
# L2 announcements are only sent on the baremetal network interface.
13+
# Without this, extra network interfaces (e.g. from nmstate) can cause
14+
# MetalLB speakers to fail to announce VIPs.
15+
NODE_NAME=$(oc get nodes -o jsonpath='{.items[0].metadata.name}')
16+
METALLB_IFACE=$(oc debug "node/${NODE_NAME}" -- chroot /host ip route get "$POOL_ADDRESS" 2>/dev/null \
17+
| grep -oE 'dev [^ ]+' | head -1 | awk '{print $2}')
18+
if [[ -z "$METALLB_IFACE" ]]; then
19+
echo "WARNING: Could not determine MetalLB interface, defaulting to enp1s0"
20+
METALLB_IFACE="enp1s0"
21+
fi
22+
echo "Using interface $METALLB_IFACE for MetalLB L2 announcements"
23+
824
oc create -f - <<EOF
925
apiVersion: metallb.io/v1beta1
1026
kind: MetalLB
@@ -21,7 +37,7 @@ metadata:
2137
namespace: metallb-system
2238
spec:
2339
addresses:
24-
- 192.168.111.30-192.168.111.50
40+
- ${POOL_RANGE}
2541
EOF
2642

2743
oc create -f - <<EOF
@@ -33,4 +49,6 @@ metadata:
3349
spec:
3450
ipAddressPools:
3551
- metallb
52+
interfaces:
53+
- ${METALLB_IFACE}
3654
EOF

0 commit comments

Comments
 (0)