Skip to content

Commit d55a933

Browse files
authored
ovn lb select the local chassis's backend prefer (#4894)
* add lb:option prefer_local_backend Signed-off-by: clyi <[email protected]> * support metallb underlay Signed-off-by: clyi <[email protected]>
1 parent c3e2307 commit d55a933

27 files changed

+1402
-17
lines changed

.github/workflows/build-x86-image.yaml

+146
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,151 @@ jobs:
31443144
name: kube-ovn-connectivity-e2e-${{ matrix.mode }}-ko-log
31453145
path: kube-ovn-connectivity-e2e-${{ matrix.mode }}-ko-log.tar.gz
31463146

3147+
3148+
kube-ovn-underlay-metallb-e2e:
3149+
name: OVN METALLB E2E
3150+
needs:
3151+
- build-kube-ovn
3152+
- build-e2e-binaries
3153+
runs-on: ubuntu-24.04
3154+
timeout-minutes: 15
3155+
steps:
3156+
- uses: jlumbroso/[email protected]
3157+
with:
3158+
android: true
3159+
dotnet: true
3160+
haskell: true
3161+
docker-images: false
3162+
large-packages: false
3163+
tool-cache: false
3164+
swap-storage: false
3165+
3166+
- uses: actions/checkout@v4
3167+
3168+
- name: Create the default branch directory
3169+
if: (github.base_ref || github.ref_name) != github.event.repository.default_branch
3170+
run: mkdir -p test/e2e/source
3171+
3172+
- name: Check out the default branch
3173+
if: (github.base_ref || github.ref_name) != github.event.repository.default_branch
3174+
uses: actions/checkout@v4
3175+
with:
3176+
ref: ${{ github.event.repository.default_branch }}
3177+
fetch-depth: 1
3178+
path: test/e2e/source
3179+
3180+
- name: Export E2E directory
3181+
run: |
3182+
if [ '${{ github.base_ref || github.ref_name }}' = '${{ github.event.repository.default_branch }}' ]; then
3183+
echo "E2E_DIR=." >> "$GITHUB_ENV"
3184+
else
3185+
echo "E2E_DIR=test/e2e/source" >> "$GITHUB_ENV"
3186+
fi
3187+
3188+
- uses: actions/setup-go@v5
3189+
id: setup-go
3190+
with:
3191+
go-version-file: ${{ env.E2E_DIR }}/go.mod
3192+
check-latest: true
3193+
cache: false
3194+
3195+
- name: Export Go full version
3196+
run: echo "GO_VERSION=${{ steps.setup-go.outputs.go-version }}" >> "$GITHUB_ENV"
3197+
3198+
- name: Go cache
3199+
uses: actions/cache/restore@v4
3200+
with:
3201+
path: |
3202+
~/.cache/go-build
3203+
~/go/pkg/mod
3204+
key: ${{ runner.os }}-e2e-go-${{ env.GO_VERSION }}-x86-${{ hashFiles(format('{0}/**/go.sum', env.E2E_DIR)) }}
3205+
restore-keys: ${{ runner.os }}-e2e-go-${{ env.GO_VERSION }}-x86-
3206+
3207+
- name: Install kind
3208+
uses: helm/[email protected]
3209+
with:
3210+
version: ${{ env.KIND_VERSION }}
3211+
install_only: true
3212+
3213+
- name: Install ginkgo
3214+
working-directory: ${{ env.E2E_DIR }}
3215+
run: go install -v -mod=mod github.com/onsi/ginkgo/v2/ginkgo
3216+
3217+
- name: Download kube-ovn image
3218+
uses: actions/download-artifact@v4
3219+
with:
3220+
name: kube-ovn
3221+
3222+
- name: Load images
3223+
run: docker load -i kube-ovn.tar
3224+
3225+
- name: Set environment variables
3226+
run: |
3227+
if [ $(($RANDOM%2)) -ne 0 ]; then
3228+
# run as root and use valgrind to debug memory leak
3229+
echo "VERSION=$(cat VERSION)-debug" >> "$GITHUB_ENV"
3230+
echo "DEBUG_WRAPPER=valgrind" >> "$GITHUB_ENV"
3231+
fi
3232+
3233+
- name: Create kind cluster
3234+
run: |
3235+
pipx install jinjanator
3236+
make kind-init
3237+
3238+
- name: Install Kube-OVN
3239+
id: install
3240+
run: make kind-install-metallb-pool-from-underlay
3241+
3242+
- name: Run Ovn Metallb and Kube-OVN Combine E2E
3243+
id: kube-ovn-underlay-metallb-e2e
3244+
working-directory: ${{ env.E2E_DIR }}
3245+
env:
3246+
E2E_BRANCH: ${{ github.base_ref || github.ref_name }}
3247+
run: make kube-ovn-underlay-metallb-e2e
3248+
3249+
- name: Collect k8s events
3250+
if: failure() && ( steps.ovn-metallb-e2e.conclusion == 'failure')
3251+
run: |
3252+
kubectl get events -A -o yaml > kube-ovn-underlay-metallb-e2e-events.yaml
3253+
tar zcf kube-ovn-underlay-metallb-e2e-events.tar.gz kube-ovn-underlay-metallb-e2e-events.yaml
3254+
3255+
- name: Upload k8s events
3256+
uses: actions/upload-artifact@v4
3257+
if: failure() && (steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')
3258+
with:
3259+
name: kube-ovn-underlay-metallb-e2e-events
3260+
path: kube-ovn-underlay-metallb-e2e-events.tar.gz
3261+
3262+
- name: Collect apiserver audit logs
3263+
if: failure() && (steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')
3264+
run: |
3265+
docker cp kube-ovn-control-plane:/var/log/kubernetes/kube-apiserver-audit.log .
3266+
tar zcf kube-ovn-underlay-metallb-e2e-audit-log.tar.gz kube-apiserver-audit.log
3267+
3268+
- name: Upload apiserver audit logs
3269+
uses: actions/upload-artifact@v4
3270+
if: failure() && (steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')
3271+
with:
3272+
name: kube-ovn-underlay-metallb-e2e-audit-log
3273+
path: kube-ovn-underlay-metallb-e2e-audit-log.tar.gz
3274+
3275+
- name: kubectl ko log
3276+
if: failure() && (steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')
3277+
run: |
3278+
make kubectl-ko-log
3279+
mv kubectl-ko-log.tar.gz kube-ovn-underlay-metallb-e2e-ko-log.tar.gz
3280+
3281+
- name: upload kubectl ko log
3282+
uses: actions/upload-artifact@v4
3283+
if: failure() && (steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')
3284+
with:
3285+
name: kube-ovn-underlay-metallb-e2e-ko-log
3286+
path: kube-ovn-underlay-metallb-e2e-ko-log.tar.gz
3287+
3288+
- name: Check kube ovn pod restarts
3289+
if: ${{ success() || (failure() && (steps.install.conclusion == 'failure' || steps.kube-ovn-underlay-metallb-e2e.conclusion == 'failure')) }}
3290+
run: make check-kube-ovn-pod-restarts
3291+
31473292
push:
31483293
name: Push Images
31493294
needs:
@@ -3153,6 +3298,7 @@ jobs:
31533298
- kube-ovn-conformance-e2e
31543299
- kube-ovn-ic-conformance-e2e
31553300
- kube-ovn-ipsec-e2e
3301+
- kube-ovn-underlay-metallb-e2e
31563302
- multus-conformance-e2e
31573303
- vpc-egress-gateway-e2e
31583304
- ovn-vpc-nat-gw-conformance-e2e

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,9 @@ kind-install-metallb:
803803
--set speaker.frr.image.tag=$(FRR_VERSION)
804804
$(call kubectl_wait_exist_and_ready,metallb-system,deployment,metallb-controller)
805805
$(call kubectl_wait_exist_and_ready,metallb-system,daemonset,metallb-speaker)
806+
807+
.PHONY: kind-configure-metallb
808+
kind-configure-metallb:
806809
@metallb_pool=$(shell echo $(KIND_IPV4_SUBNET) | sed 's/.[^.]\+$$/.201/')-$(shell echo $(KIND_IPV4_SUBNET) | sed 's/.[^.]\+$$/.250/') \
807810
jinjanate yamls/metallb-cr.yaml.j2 -o metallb-cr.yaml
808811
kubectl apply -f metallb-cr.yaml
@@ -979,6 +982,11 @@ kind-install-anp: kind-load-image
979982
kubectl apply -f "$(BANP_CR_YAML)"
980983
@$(MAKE) ENABLE_ANP=true kind-install
981984

985+
.PHONY: kind-install-metallb-pool-from-underlay
986+
kind-install-metallb-pool-from-underlay: kind-load-image
987+
@$(MAKE) ENABLE_OVN_LB_PREFER_LOCAL=true LS_CT_SKIP_DST_LPORT_IPS=false kind-install
988+
@$(MAKE) kind-install-metallb
989+
982990
.PHONY: kind-reload
983991
kind-reload: kind-reload-ovs
984992
kubectl delete pod -n kube-system -l app=kube-ovn-controller

charts/kube-ovn/templates/controller-deploy.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ spec:
140140
- --ovsdb-con-timeout={{- .Values.func.OVSDB_CON_TIMEOUT }}
141141
- --ovsdb-inactivity-timeout={{- .Values.func.OVSDB_INACTIVITY_TIMEOUT }}
142142
- --enable-live-migration-optimize={{- .Values.func.ENABLE_LIVE_MIGRATION_OPTIMIZE }}
143+
- --enable-ovn-lb-prefer-local={{- .Values.func.ENABLE_OVN_LB_PREFER_LOCAL }}
143144
- --image={{ .Values.global.registry.address }}/{{ .Values.global.images.kubeovn.repository }}:{{ .Values.global.images.kubeovn.tag }}
144145
securityContext:
145146
runAsUser: {{ include "kubeovn.runAsUser" . }}

charts/kube-ovn/templates/kube-ovn-crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,8 @@ spec:
25642564
type: boolean
25652565
enableMulticastSnoop:
25662566
type: boolean
2567+
enableExternalLBAddress:
2568+
type: boolean
25672569
routeTable:
25682570
type: string
25692571
namespaceSelectors:

charts/kube-ovn/templates/ovn-CR.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ rules:
290290
- nodes
291291
- nodes/status
292292
- pods
293+
- services
293294
verbs:
294295
- get
295296
- list

charts/kube-ovn/values.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func:
7878
OVSDB_CON_TIMEOUT: 3
7979
OVSDB_INACTIVITY_TIMEOUT: 10
8080
ENABLE_LIVE_MIGRATION_OPTIMIZE: true
81+
ENABLE_OVN_LB_PREFER_LOCAL: false
8182

8283
ipv4:
8384
POD_CIDR: "10.16.0.0/16"

dist/images/Dockerfile.base

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ RUN cd /usr/src/ && git clone -b branch-24.03 --depth=1 https://github.com/ovn-o
6565
# support dedicated BFD LRP
6666
curl -s https://github.com/kubeovn/ovn/commit/40345aa35d03c93cde877ccfa8111346291ebc7c.patch | git apply && \
6767
# skip node local dns ip conntrack when set acl
68-
curl -s https://github.com/kubeovn/ovn/commit/e7d3ba53cdcbc524bb29c54ddb07b83cc4258ed7.patch | git apply
68+
curl -s https://github.com/kubeovn/ovn/commit/e7d3ba53cdcbc524bb29c54ddb07b83cc4258ed7.patch | git apply && \
69+
# select local backend first
70+
curl -s https://github.com/kubeovn/ovn/commit/a9e009136a42cf6d985f97e2bf1ec41df6b5ca29.patch | git apply
6971

7072
RUN apt install -y build-essential fakeroot \
7173
autoconf automake bzip2 debhelper-compat dh-exec dh-python dh-sequence-python3 dh-sequence-sphinxdoc \

dist/images/install.sh

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SET_VXLAN_TX_OFF=${SET_VXLAN_TX_OFF:-false}
4646
OVSDB_CON_TIMEOUT=${OVSDB_CON_TIMEOUT:-3}
4747
OVSDB_INACTIVITY_TIMEOUT=${OVSDB_INACTIVITY_TIMEOUT:-10}
4848
ENABLE_LIVE_MIGRATION_OPTIMIZE=${ENABLE_LIVE_MIGRATION_OPTIMIZE:-true}
49+
ENABLE_OVN_LB_PREFER_LOCAL=${ENABLE_OVN_LB_PREFER_LOCAL:-false}
4950

5051
PROBE_HTTP_SCHEME="HTTP"
5152
if [ "$SECURE_SERVING" = "true" ]; then
@@ -2815,6 +2816,8 @@ spec:
28152816
type: boolean
28162817
enableMulticastSnoop:
28172818
type: boolean
2819+
enableExternalLBAddress:
2820+
type: boolean
28182821
routeTable:
28192822
type: string
28202823
namespaceSelectors:
@@ -3672,6 +3675,7 @@ rules:
36723675
- nodes
36733676
- nodes/status
36743677
- pods
3678+
- services
36753679
verbs:
36763680
- get
36773681
- list
@@ -4734,6 +4738,7 @@ spec:
47344738
- --ovsdb-con-timeout=$OVSDB_CON_TIMEOUT
47354739
- --ovsdb-inactivity-timeout=$OVSDB_INACTIVITY_TIMEOUT
47364740
- --enable-live-migration-optimize=$ENABLE_LIVE_MIGRATION_OPTIMIZE
4741+
- --enable-ovn-lb-prefer-local=$ENABLE_OVN_LB_PREFER_LOCAL
47374742
- --image=$REGISTRY/kube-ovn:$VERSION
47384743
securityContext:
47394744
runAsUser: ${RUN_AS_USER}

e2e.mk

+10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ e2e-build:
8484
ginkgo build $(E2E_BUILD_FLAGS) ./test/e2e/kubevirt
8585
ginkgo build $(E2E_BUILD_FLAGS) ./test/e2e/webhook
8686
ginkgo build $(E2E_BUILD_FLAGS) ./test/e2e/connectivity
87+
ginkgo build $(E2E_BUILD_FLAGS) ./test/e2e/metallb
8788

8889
.PHONY: k8s-conformance-e2e
8990
k8s-conformance-e2e:
@@ -253,3 +254,12 @@ kube-ovn-connectivity-e2e:
253254
E2E_NETWORK_MODE=$(E2E_NETWORK_MODE) \
254255
ginkgo $(GINKGO_OUTPUT_OPT) --procs 2 --randomize-all -v \
255256
--focus=CNI:Kube-OVN ./test/e2e/connectivity -- $(TEST_BIN_ARGS)
257+
258+
.PHONY: kube-ovn-underlay-metallb-e2e
259+
kube-ovn-underlay-metallb-e2e:
260+
ginkgo build $(E2E_BUILD_FLAGS) ./test/e2e/metallb
261+
E2E_BRANCH=$(E2E_BRANCH) \
262+
E2E_IP_FAMILY=$(E2E_IP_FAMILY) \
263+
E2E_NETWORK_MODE=$(E2E_NETWORK_MODE) \
264+
ginkgo $(GINKGO_OUTPUT_OPT) $(GINKGO_PARALLEL_OPT) --randomize-all -v \
265+
--focus=CNI:Kube-OVN ./test/e2e/metallb/metallb.test -- $(TEST_BIN_ARGS)

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/containerd/containerd v1.7.27
1313
github.com/containernetworking/cni v1.2.3
1414
github.com/containernetworking/plugins v1.6.2
15+
github.com/digitalocean/go-openvswitch v0.0.0-20241021184246-19e734367535
1516
github.com/docker/docker v28.0.4+incompatible
1617
github.com/emicklei/go-restful/v3 v3.12.2
1718
github.com/evanphx/json-patch/v5 v5.9.11
@@ -42,6 +43,7 @@ require (
4243
github.com/stretchr/testify v1.10.0
4344
github.com/vishvananda/netlink v1.3.1-0.20250303224720-0e7078ed04c8
4445
go.uber.org/mock v0.5.0
46+
go.universe.tf/metallb v0.14.9
4547
golang.org/x/mod v0.24.0
4648
golang.org/x/sys v0.31.0
4749
golang.org/x/time v0.11.0

0 commit comments

Comments
 (0)