Skip to content

Commit

Permalink
Merge pull request #4567 from kyrtapz/udn_to_default_svc_base4554
Browse files Browse the repository at this point in the history
Add support for Pod->KAPI/DNS traffic in user-defined primary networks
  • Loading branch information
trozet committed Sep 20, 2024
2 parents bc013a8 + 354fa00 commit 0f16d95
Show file tree
Hide file tree
Showing 72 changed files with 7,974 additions and 1,574 deletions.
5 changes: 3 additions & 2 deletions go-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/safchain/ethtool v0.3.1-0.20231027162144-83e5e0097c91
github.com/spf13/afero v1.9.5
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.2.0
github.com/urfave/cli/v2 v2.27.2
github.com/vishvananda/netlink v1.2.1-beta.2.0.20231024175852-77df5d35f725
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/net v0.25.0
Expand Down Expand Up @@ -71,7 +71,7 @@ require (
github.com/cenkalti/rpc2 v0.0.0-20210604223624-c1acbc6ec984 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
Expand Down Expand Up @@ -114,6 +114,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
Expand Down Expand Up @@ -774,8 +774,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
Expand All @@ -793,6 +793,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
39 changes: 26 additions & 13 deletions go-controller/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ var (

// Default holds parsed config file parameters and command-line overrides
Default = DefaultConfig{
MTU: 1400,
ConntrackZone: 64000,
EncapType: "geneve",
EncapIP: "",
EncapPort: DefaultEncapPort,
InactivityProbe: 100000, // in Milliseconds
OpenFlowProbe: 180, // in Seconds
OfctrlWaitBeforeClear: 0, // in Milliseconds
MonitorAll: true,
OVSDBTxnTimeout: DefaultDBTxnTimeout,
LFlowCacheEnable: true,
RawClusterSubnets: "10.128.0.0/14/23",
Zone: types.OvnDefaultZone,
MTU: 1400,
ConntrackZone: 64000,
EncapType: "geneve",
EncapIP: "",
EncapPort: DefaultEncapPort,
InactivityProbe: 100000, // in Milliseconds
OpenFlowProbe: 180, // in Seconds
OfctrlWaitBeforeClear: 0, // in Milliseconds
MonitorAll: true,
OVSDBTxnTimeout: DefaultDBTxnTimeout,
LFlowCacheEnable: true,
RawClusterSubnets: "10.128.0.0/14/23",
Zone: types.OvnDefaultZone,
UDNAllowedDefaultServices: *cli.NewStringSlice("default/kubernetes", "kube-system/kube-dns"),
}

// Logging holds logging-related parsed config file parameters and command-line overrides
Expand Down Expand Up @@ -280,6 +281,10 @@ type DefaultConfig struct {

// Zone name to which ovnkube-node/ovnkube-controller belongs to
Zone string `gcfg:"zone"`

// UDNAllowedDefaultServices holds a list of namespaced names of
// default cluster network services accessible from primary user-defined networks
UDNAllowedDefaultServices cli.StringSlice `gcfg:"udn-allowed-default-services"`
}

// LoggingConfig holds logging-related parsed config file parameters and command-line overrides
Expand Down Expand Up @@ -921,6 +926,14 @@ var CommonFlags = []cli.Flag{
Value: Default.Zone,
Destination: &cliConfig.Default.Zone,
},
&cli.StringSliceFlag{
Name: "udn-allowed-default-services",
Usage: "a list of namespaced names of default cluster network services accessible from primary" +
"user-defined networks. If not specified defaults to [\"default/kubernetes\", \"kube-system/kube-dns\"]." +
"Only used when enable-network-segmentation is set",
Value: &Default.UDNAllowedDefaultServices,
Destination: &cliConfig.Default.UDNAllowedDefaultServices,
},
}

// MonitoringFlags capture monitoring-related options
Expand Down
13 changes: 7 additions & 6 deletions go-controller/pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import (
anpinformerfactory "sigs.k8s.io/network-policy-api/pkg/client/informers/externalversions"
anpinformer "sigs.k8s.io/network-policy-api/pkg/client/informers/externalversions/apis/v1alpha1"

certificatesinformers "k8s.io/client-go/informers/certificates/v1"

ocpnetworkapiv1alpha1 "github.com/openshift/api/network/v1alpha1"
ocpnetworkscheme "github.com/openshift/client-go/network/clientset/versioned/scheme"
ocpnetworkinformerfactory "github.com/openshift/client-go/network/informers/externalversions"
ocpnetworkinformerv1alpha1 "github.com/openshift/client-go/network/informers/externalversions/network/v1alpha1"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
egressfirewallapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1"
egressfirewallscheme "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/clientset/versioned/scheme"
Expand All @@ -20,12 +27,6 @@ import (
egressfirewalllister "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/listers/egressfirewall/v1"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
certificatesinformers "k8s.io/client-go/informers/certificates/v1"

ocpnetworkapiv1alpha1 "github.com/openshift/api/network/v1alpha1"
ocpnetworkscheme "github.com/openshift/client-go/network/clientset/versioned/scheme"
ocpnetworkinformerfactory "github.com/openshift/client-go/network/informers/externalversions"
ocpnetworkinformerv1alpha1 "github.com/openshift/client-go/network/informers/externalversions/network/v1alpha1"

egressipapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressip/v1"
egressipscheme "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressip/v1/apis/clientset/versioned/scheme"
Expand Down
2 changes: 2 additions & 0 deletions go-controller/pkg/node/gateway_init_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/kubernetes/fake"

nadfake "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/fake"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
adminpolicybasedrouteclient "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1/apis/clientset/versioned/fake"
udnfakeclient "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/userdefinednetwork/v1/apis/clientset/versioned/fake"
Expand Down Expand Up @@ -1275,6 +1276,7 @@ OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0`
)
expectedTables["nat"]["OVN-KUBE-UDN-MASQUERADE"] = append(expectedTables["nat"]["OVN-KUBE-UDN-MASQUERADE"],
"-s 169.254.169.2/29 -j RETURN", // this guarantees we don't SNAT default network masqueradeIPs
"-d 172.16.1.0/24 -j RETURN", // this guarantees we don't SNAT service traffic
"-s 169.254.169.0/29 -j MASQUERADE", // this guarantees we SNAT all UDN MasqueradeIPs traffic leaving the node
)
}
Expand Down
29 changes: 26 additions & 3 deletions go-controller/pkg/node/gateway_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
utilnet "k8s.io/utils/net"

"github.com/coreos/go-iptables/iptables"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/node/controllers/egressservice"
nodeipt "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/node/iptables"
Expand Down Expand Up @@ -493,18 +494,21 @@ func getUDNMasqueradeRules(protocol iptables.Protocol) []nodeipt.Rule {
// the following rules are actively used only for the UDN Feature:
// -A POSTROUTING -j OVN-KUBE-UDN-MASQUERADE
// -A OVN-KUBE-UDN-MASQUERADE -s 169.254.0.0/29 -j RETURN
// -A OVN-KUBE-UDN-MASQUERADE -d 10.96.0.0/16 -j RETURN
// -A OVN-KUBE-UDN-MASQUERADE -s 169.254.0.0/17 -j MASQUERADE
// NOTE: Ordering is important here, the RETURN must come before
// the MASQUERADE rule. Please don't change the ordering.
srcUDNMasqueradePrefix := config.Gateway.V4MasqueradeSubnet
// defaultNetworkReservedMasqueradePrefix contains the first 6IPs in the masquerade
// range that shouldn't be MASQUERADED. Hence /29 and /125 is intentionally hardcoded here
defaultNetworkReservedMasqueradePrefix := config.Gateway.MasqueradeIPs.V4HostMasqueradeIP.String() + "/29"
ipFamily := utilnet.IPv4
if protocol == iptables.ProtocolIPv6 {
srcUDNMasqueradePrefix = config.Gateway.V6MasqueradeSubnet
defaultNetworkReservedMasqueradePrefix = config.Gateway.MasqueradeIPs.V6HostMasqueradeIP.String() + "/125"
ipFamily = utilnet.IPv6
}
return []nodeipt.Rule{
rules := []nodeipt.Rule{
{
Table: "nat",
Chain: "POSTROUTING",
Expand All @@ -520,7 +524,25 @@ func getUDNMasqueradeRules(protocol iptables.Protocol) []nodeipt.Rule {
},
Protocol: protocol,
},
{
}
for _, svcCIDR := range config.Kubernetes.ServiceCIDRs {
if utilnet.IPFamilyOfCIDR(svcCIDR) != ipFamily {
continue
}
rules = append(rules,
nodeipt.Rule{
Table: "nat",
Chain: iptableUDNMasqueradeChain,
Args: []string{
"-d", svcCIDR.String(),
"-j", "RETURN",
},
Protocol: protocol,
},
)
}
rules = append(rules,
nodeipt.Rule{
Table: "nat",
Chain: iptableUDNMasqueradeChain,
Args: []string{
Expand All @@ -529,7 +551,8 @@ func getUDNMasqueradeRules(protocol iptables.Protocol) []nodeipt.Rule {
},
Protocol: protocol,
},
}
)
return rules
}

// initLocalGatewayNATRules sets up iptables rules for interfaces
Expand Down
44 changes: 39 additions & 5 deletions go-controller/pkg/node/gateway_shared_intf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"strings"
"sync"

"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube"
Expand All @@ -19,8 +22,6 @@ import (
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
utilerrors "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util/errors"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"

kapi "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
Expand Down Expand Up @@ -275,6 +276,31 @@ func (npw *nodePortWatcher) updateServiceFlowCache(service *kapi.Service, netInf
errors = append(errors, err)
}
}

// Add flows for default network services that are accessible from UDN networks
if util.IsNetworkSegmentationSupportEnabled() {
// The flow added below has a higher priority than the default network service flow:
// priority=500,ip,in_port=LOCAL,nw_dst=10.96.0.0/16 actions=ct(commit,table=2,zone=64001,nat(src=169.254.0.2))
// This ordering ensures that there is no SNAT for UDN originated traffic.

if util.IsUDNEnabledService(ktypes.NamespacedName{Namespace: service.Namespace, Name: service.Name}.String()) {
key = strings.Join([]string{"UDNAllowedSVC", service.Namespace, service.Name}, "_")
if !add {
npw.ofm.deleteFlowsByKey(key)
}

ipPrefix := "ip"
masqueradeSubnet := config.Gateway.V4MasqueradeSubnet
if !utilnet.IsIPv4String(service.Spec.ClusterIP) {
ipPrefix = "ipv6"
masqueradeSubnet = config.Gateway.V6MasqueradeSubnet
}
// table 0, user-defined network host -> OVN towards default cluster network services
npw.ofm.updateFlowCacheEntry(key, []string{fmt.Sprintf("cookie=%s, priority=600, in_port=%s, %s, %s_src=%s, %s_dst=%s,"+
"actions=ct(commit,zone=%d,table=2)",
defaultOpenFlowCookie, npw.ofm.defaultBridge.ofPortHost, ipPrefix, ipPrefix, masqueradeSubnet, ipPrefix, service.Spec.ClusterIP, config.Default.HostMasqConntrackZone)})
}
}
return utilerrors.Join(errors...)
}

Expand Down Expand Up @@ -1276,17 +1302,18 @@ func flowsForDefaultBridge(bridge *bridgeConfiguration, extraIPs []net.IP) ([]st
defaultOpenFlowCookie, ofPortHost, config.Gateway.MasqueradeIPs.V6OVNMasqueradeIP.String(), config.Default.OVNMasqConntrackZone))
}

var protoPrefix string
var masqIP string
var protoPrefix, masqIP, masqSubnet string

// table 0, packets coming from Host -> Service
for _, svcCIDR := range config.Kubernetes.ServiceCIDRs {
if utilnet.IsIPv4CIDR(svcCIDR) {
protoPrefix = "ip"
masqIP = config.Gateway.MasqueradeIPs.V4HostMasqueradeIP.String()
masqSubnet = config.Gateway.V4MasqueradeSubnet
} else {
protoPrefix = "ipv6"
masqIP = config.Gateway.MasqueradeIPs.V6HostMasqueradeIP.String()
masqSubnet = config.Gateway.V6MasqueradeSubnet
}

// table 0, Host -> OVN towards SVC, SNAT to special IP
Expand All @@ -1295,13 +1322,18 @@ func flowsForDefaultBridge(bridge *bridgeConfiguration, extraIPs []net.IP) ([]st
"actions=ct(commit,zone=%d,nat(src=%s),table=2)",
defaultOpenFlowCookie, ofPortHost, protoPrefix, protoPrefix, svcCIDR, config.Default.HostMasqConntrackZone, masqIP))

masqDst := masqIP
if util.IsNetworkSegmentationSupportEnabled() {
// In UDN match on the whole masquerade subnet to handle replies from UDN enabled services
masqDst = masqSubnet
}
for _, netConfig := range bridge.patchedNetConfigs() {
// table 0, Reply hairpin traffic to host, coming from OVN, unSNAT
dftFlows = append(dftFlows,
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, %s, %s_src=%s, %s_dst=%s,"+
"actions=ct(zone=%d,nat,table=3)",
defaultOpenFlowCookie, netConfig.ofPortPatch, protoPrefix, protoPrefix, svcCIDR,
protoPrefix, masqIP, config.Default.HostMasqConntrackZone))
protoPrefix, masqDst, config.Default.HostMasqConntrackZone))
// table 0, Reply traffic coming from OVN to outside, drop it if the DNAT wasn't done either
// at the GR load balancer or switch load balancer. It means the correct port wasn't provided.
// nodeCIDR->serviceCIDR traffic flow is internal and it shouldn't be carried to outside the cluster
Expand Down Expand Up @@ -1383,7 +1415,9 @@ func flowsForDefaultBridge(bridge *bridgeConfiguration, extraIPs []net.IP) ([]st
fmt.Sprintf("cookie=%s, priority=10, table=1, dl_dst=%s, actions=output:%s",
defaultOpenFlowCookie, bridgeMacAddress, ofPortHost))
}

defaultNetConfig := bridge.netConfig[types.DefaultNetworkName]

// table 2, dispatch from Host -> OVN
dftFlows = append(dftFlows,
fmt.Sprintf("cookie=%s, table=2, "+
Expand Down
1 change: 1 addition & 0 deletions go-controller/pkg/ovn/base_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

libovsdbclient "github.com/ovn-org/libovsdb/client"
"github.com/ovn-org/libovsdb/ovsdb"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/allocator/pod"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
Expand Down
40 changes: 39 additions & 1 deletion go-controller/pkg/ovn/controller/services/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"time"

libovsdbclient "github.com/ovn-org/libovsdb/client"
libovsdb "github.com/ovn-org/libovsdb/ovsdb"

libovsdbops "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/ops"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
Expand Down Expand Up @@ -51,7 +53,7 @@ func newRepair(serviceLister corelisters.ServiceLister, nbClient libovsdbclient.
}

// runBeforeSync performs some cleanup of stale LBs and other miscellaneous setup.
func (r *repair) runBeforeSync(useTemplates bool, netInfo util.NetInfo) {
func (r *repair) runBeforeSync(useTemplates bool, netInfo util.NetInfo, nodes map[string]nodeInfo) {
// no need to lock, single-threaded.

startTime := time.Now()
Expand Down Expand Up @@ -151,6 +153,42 @@ func (r *repair) runBeforeSync(useTemplates bool, netInfo util.NetInfo) {
klog.Errorf("Failed to purge existing reject rules: %v", err)
}
}

// remove static routes for UDN enabled services that are no longer valid
udnDelPredicate := func(route *nbdb.LogicalRouterStaticRoute) bool {
if route.ExternalIDs[types.NetworkExternalID] == netInfo.GetNetworkName() &&
route.ExternalIDs[types.TopologyExternalID] == netInfo.TopologyType() {
if serviceKey, exists := route.ExternalIDs[types.UDNEnabledServiceExternalID]; exists {
if !r.unsyncedServices.Has(serviceKey) {
// the service doesn't exist
return true
}
if !util.IsUDNEnabledService(serviceKey) {
// the service is not a part of UDNAllowedDefaultServices anymore
return true
}
}
}
return false
}

if netInfo.IsPrimaryNetwork() {
var ops []libovsdb.Operation
if netInfo.TopologyType() == types.Layer2Topology {
for _, node := range nodes {
if ops, err = libovsdbops.DeleteLogicalRouterStaticRoutesWithPredicateOps(r.nbClient, ops, netInfo.GetNetworkScopedGWRouterName(node.name), udnDelPredicate); err != nil {
klog.Errorf("Failed to create a delete logical router static route op: %v", err)
}
}
} else {
if ops, err = libovsdbops.DeleteLogicalRouterStaticRoutesWithPredicateOps(r.nbClient, ops, netInfo.GetNetworkScopedClusterRouterName(), udnDelPredicate); err != nil {
klog.Errorf("Failed to create a delete logical router static route op: %v", err)
}
}
if _, err = libovsdbops.TransactAndCheck(r.nbClient, ops); err != nil {
klog.Errorf("Failed to delete logical router static routes: %v", err)
}
}
}

// serviceSynced is called by a ServiceController worker when it has successfully
Expand Down
Loading

0 comments on commit 0f16d95

Please sign in to comment.