Skip to content

Commit

Permalink
Use masquerade default gateway when no default gw is found
Browse files Browse the repository at this point in the history
When no default gateway is found, OVNK will still come up. This behavior
was intentional: 3eeb930

The goal was that with design changes, host->service traffic would work
without the need for a default gateway to be detected. This works, in
most cases, but there is a case we did not consider. If a user has
deployed a cluster with local gateway mode, and is using a different
interface/network for kapi traffic (not the gateway bridge interface),
then endpoints to the kubernetes service will reside on this other
network. In this case when a host tries to talk to kube API service, the
traffic would go to the GR, it would be DNAT'ed to an IP address not on
any known network, and be dropped by OVN routing when there is no
default gateway route.

When the configuration parameter AllowNoUplink is set, we will set the
default route to be the masquerade IP, which solves this problem. This
commit changes the behavior to not require AllowNoUplink to be set in
order to achieve the same behavior, as services should work in this
scenario even without a default gw.

Signed-off-by: Tim Rozet <trozet@redhat.com>
  • Loading branch information
trozet committed Feb 1, 2024
1 parent bf0002d commit 1ccb958
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions go-controller/pkg/node/gateway_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ func getGatewayNextHops() ([]net.IP, string, error) {
}
gatewayIntf = defaultGatewayIntf
} else {
if gatewayIntf != defaultGatewayIntf || len(defaultGatewayNextHops) == 0 {
if config.Gateway.Mode == config.GatewayModeLocal && config.Gateway.AllowNoUplink {
if gatewayIntf != defaultGatewayIntf {
klog.Warningf("Found default gateway interface: %q does not match provided interface from config: %q", defaultGatewayIntf, gatewayIntf)
}
if len(defaultGatewayNextHops) == 0 {
klog.Warning("No default route identified in the host. Egress features and pod egress traffic in " +
"shared gateway mode may not function correctly!")
if config.Gateway.Mode == config.GatewayModeLocal {
// For local gw, if not default gateway is available or the provide gateway interface is not the host gateway interface
// use nexthop masquerade IP as GR default gw to steer traffic to the gateway bridge
// use nexthop masquerade IP as GR default gw to steer traffic to the gateway bridge, and then the host for routing
if needIPv4NextHop {
nexthop := config.Gateway.MasqueradeIPs.V4DummyNextHopMasqueradeIP
gatewayNextHops = append(gatewayNextHops, nexthop)
Expand Down
1 change: 0 additions & 1 deletion go-controller/pkg/node/gateway_init_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,6 @@ var _ = Describe("Gateway unit tests", func() {
gwIPs := []net.IP{config.Gateway.MasqueradeIPs.V4DummyNextHopMasqueradeIP}
config.Gateway.Interface = dummyBridgeName
config.Gateway.Mode = config.GatewayModeLocal
config.Gateway.AllowNoUplink = true

gatewayNextHops, gatewayIntf, err := getGatewayNextHops()
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 1ccb958

Please sign in to comment.