Skip to content

Commit 6d1f2b7

Browse files
committed
review
1 parent 5db2696 commit 6d1f2b7

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

pkg/controllers/proxy/network_services_controller.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ type endpointSliceInfo struct {
225225
// map of all endpoints, with unique service id(namespace name, service name, port) as key
226226
type endpointSliceInfoMap map[string][]endpointSliceInfo
227227

228+
func checkRpFilter1(ifname string) bool {
229+
rpFilterValue, err := utils.GetSysctlSingleTemplate(utils.IPv4ConfRPFilterTemplate, ifname)
230+
if err != nil {
231+
klog.Errorf("failed to get rp_filter value for %s: %s", ifname, err.Error())
232+
return false
233+
}
234+
return strings.TrimSpace(rpFilterValue) == "1"
235+
}
236+
228237
// Run periodically sync ipvs configuration to reflect desired state of services and endpoints
229238
func (nsc *NetworkServicesController) Run(healthChan chan<- *healthcheck.ControllerHeartbeat,
230239
stopCh <-chan struct{}, wg *sync.WaitGroup) {
@@ -286,30 +295,23 @@ func (nsc *NetworkServicesController) Run(healthChan chan<- *healthcheck.Control
286295
// https://github.com/kubernetes/kubernetes/pull/70530/files
287296
setSysCtlAndCheckError(utils.IPv4ConfAllArpAnnounce, arpAnnounceUseBestLocalAddress)
288297

289-
// Only override rp_filter if it is set to 1, as enabling it from 0 to 2 can cause issues with some network configurations
290-
rpFilter := false
291-
for _, ifname := range []string{"all", "kube-bridge", nsc.krNode.GetNodeInterfaceName()} {
292-
rpFilterValue, err := utils.GetSysctlSingleTemplate(utils.IPv4ConfRPFilterTemplate, ifname)
293-
if err != nil {
294-
klog.Errorf("failed to get rp_filter value for %s: %s", ifname, err.Error())
295-
continue
296-
}
297-
if strings.TrimSpace(rpFilterValue) == "1" {
298-
rpFilter = true
299-
break
300-
}
301-
}
302-
303298
// Ensure rp_filter=2 (or leave 0 untouched) for DSR capability, see:
304299
// * https://access.redhat.com/solutions/53031
305300
// * https://github.com/cloudnativelabs/kube-router/pull/1651#issuecomment-2072851683
306-
if nsc.krNode.IsIPv4Capable() && rpFilter {
307-
sysctlErr := utils.SetSysctlSingleTemplate(utils.IPv4ConfRPFilterTemplate, "all", 2)
308-
if sysctlErr != nil {
309-
if sysctlErr.IsFatal() {
310-
klog.Fatal(sysctlErr.Error())
311-
} else {
312-
klog.Error(sysctlErr.Error())
301+
// Only override rp_filter if it is set to 1, as enabling it from 0 to 2 can cause issues
302+
// with some network configurations which use reverse routing. All must be overriden as it overrides others
303+
rpFilterAll := checkRpFilter1("all")
304+
if nsc.krNode.IsIPv4Capable() {
305+
for _, ifname := range []string{"kube-bridge", "kube-dummy-if", nsc.krNode.GetNodeInterfaceName()} {
306+
if rpFilterAll || checkRpFilter1(ifname) {
307+
sysctlErr := utils.SetSysctlSingleTemplate(utils.IPv4ConfRPFilterTemplate, ifname, 2)
308+
if sysctlErr != nil {
309+
if sysctlErr.IsFatal() {
310+
klog.Fatal(sysctlErr.Error())
311+
} else {
312+
klog.Error(sysctlErr.Error())
313+
}
314+
}
313315
}
314316
}
315317
}

0 commit comments

Comments
 (0)