disable sloppy_tcp if there is no DSR & Maglev service

This commit is contained in:
Anupam Ghosh 2025-08-03 13:52:25 +05:30 committed by Aaron U'Ren
parent 98e38e9e66
commit bbb8f3b0d9
2 changed files with 10 additions and 7 deletions

View File

@ -406,23 +406,24 @@ func (nsc *NetworkServicesController) setupExternalIPServices(serviceInfoMap ser
} }
func (nsc *NetworkServicesController) setupSloppyTCP(serviceInfoMap serviceInfoMap) { func (nsc *NetworkServicesController) setupSloppyTCP(serviceInfoMap serviceInfoMap) {
enableSloppyTCP := false var sloppyTCPVal int8 = 0
for _, svc := range serviceInfoMap { for _, svc := range serviceInfoMap {
// Enable sloppy TCP if any DSR service with Maglev hashing is configured // Enable sloppy TCP if any DSR service with Maglev hashing is configured
if svc.directServerReturn && svc.scheduler == IpvsMaglevHashing { if svc.directServerReturn && svc.scheduler == IpvsMaglevHashing {
enableSloppyTCP = true sloppyTCPVal = 1
break
} }
} }
// set sloppy_tcp to 1 if not already set // enable/disable sloppy_tcp sysctl based on sloppyTCPVal
sloppyTCP := nsc.krNode.SloppyTCP() sloppyTCP := nsc.krNode.SloppyTCP()
if enableSloppyTCP && sloppyTCP.CachedVal() == 0 { if sloppyTCP.CachedVal() != sloppyTCPVal {
sysctlErr := sloppyTCP.WriteVal(1) sysctlErr := sloppyTCP.WriteVal(sloppyTCPVal)
if sysctlErr != nil { if sysctlErr != nil {
klog.Errorf("Failed to enable IPVS sloppy TCP: %s", sysctlErr.Error()) klog.Errorf("Failed to enable IPVS sloppy TCP: %s", sysctlErr.Error())
} else { return
klog.Infof("IPVS sloppy TCP enabled")
} }
klog.Infof("IPVS sloppy TCP set to %d", sloppyTCPVal)
} }
} }

View File

@ -251,6 +251,8 @@ func NewKRNode(node *apiv1.Node, linkQ LocalLinkQuerier, enableIPv4, enableIPv6
}, },
linkQ: linkQ, linkQ: linkQ,
NodeInterfaceName: nodeInterfaceName, NodeInterfaceName: nodeInterfaceName,
// Purposefully set the value of sloppyTCP to 0. This ensures the machine's sloppy_tcp setting remains
// unchanged when there are no services with both Maglev and DSR enabled.
sloppyTCP: SysctlConfig{ sloppyTCP: SysctlConfig{
name: IPv4IPVSSloppyTCP, name: IPv4IPVSSloppyTCP,
value: 0, value: 0,