Skip to content

Commit 509ec59

Browse files
authored
vpc egress gateway: fix invalid route destination (#5202)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent 8d75e5c commit 509ec59

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,7 @@ jobs:
25102510
- build-kube-ovn
25112511
- build-e2e-binaries
25122512
runs-on: ubuntu-24.04
2513-
timeout-minutes: 10
2513+
timeout-minutes: 15
25142514
strategy:
25152515
fail-fast: false
25162516
matrix:

dist/images/init-vpc-egress-gateway.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ sysctl -w net.ipv6.conf.all.forwarding=1
1414

1515
iptables -V
1616

17-
for dst in ${INTERNAL_ROUTE_DST_IPV4[*]}; do
18-
ip route add "${dst}" via "${INTERNAL_GATEWAY_IPV4}"
17+
for dst in ${INTERNAL_ROUTE_DST_IPV4[*]}; do
18+
ip route replace "${dst}" via "${INTERNAL_GATEWAY_IPV4}"
1919
done
2020

21-
for dst in ${INTERNAL_ROUTE_DST_IPV6[*]}; do
22-
ip route add "${dst}" via "${INTERNAL_GATEWAY_IPV6}"
21+
for dst in ${INTERNAL_ROUTE_DST_IPV6[*]}; do
22+
ip route replace "${dst}" via "${INTERNAL_GATEWAY_IPV6}"
2323
done
2424

25-
for src in ${SNAT_SOURCES_IPV4[*]}; do
26-
iptables -t nat -A POSTROUTING -s "${src}" -j MASQUERADE --random-fully
25+
for src in ${SNAT_SOURCES_IPV4[*]}; do
26+
if ! iptables -t nat -C POSTROUTING -s "${src}" -j MASQUERADE --random-fully 2>/dev/null; then
27+
iptables -t nat -A POSTROUTING -s "${src}" -j MASQUERADE --random-fully
28+
fi
2729
done
2830

2931
for src in ${SNAT_SOURCES_IPV6[*]}; do
30-
ip6tables -t nat -A POSTROUTING -s "${src}" -j MASQUERADE --random-fully
32+
if ! ip6tables -t nat -C POSTROUTING -s "${src}" -j MASQUERADE --random-fully 2>/dev/null; then
33+
ip6tables -t nat -A POSTROUTING -s "${src}" -j MASQUERADE --random-fully
34+
fi
3135
done

pkg/util/pod_routes.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"slices"
8+
"strings"
89

910
"github.com/kubeovn/kube-ovn/pkg/request"
1011
)
@@ -25,6 +26,14 @@ func (r PodRoutes) Add(provider, destination, gateway string) {
2526
return
2627
}
2728

29+
if !strings.ContainsRune(destination, '/') {
30+
if strings.ContainsRune(destination, ':') {
31+
destination += "/128"
32+
} else {
33+
destination += "/32"
34+
}
35+
}
36+
2837
if r[provider] == nil {
2938
r[provider] = make(PodProviderRoutes)
3039
}

pkg/util/pod_routes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestPodRoutes(t *testing.T) {
2727
require.Len(t, annotations, 1)
2828
require.Equal(t,
2929
annotations[fmt.Sprintf(RoutesAnnotationTemplate, "foo")],
30-
`[{"dst":"0.0.0.1","gw":"1.1.1.1"},{"dst":"0.0.1.0/24","gw":"1.1.1.1"},{"dst":"0.1.0.0/16","gw":"1.1.1.2"}]`,
30+
`[{"dst":"0.0.0.1/32","gw":"1.1.1.1"},{"dst":"0.0.1.0/24","gw":"1.1.1.1"},{"dst":"0.1.0.0/16","gw":"1.1.1.2"}]`,
3131
)
3232

3333
routes.Add("foo", "0.0.0.1", "")

0 commit comments

Comments
 (0)