diff --git a/pkg/controllers/proxy/service_endpoints_sync.go b/pkg/controllers/proxy/service_endpoints_sync.go index eba13f59..12425caa 100644 --- a/pkg/controllers/proxy/service_endpoints_sync.go +++ b/pkg/controllers/proxy/service_endpoints_sync.go @@ -406,23 +406,24 @@ func (nsc *NetworkServicesController) setupExternalIPServices(serviceInfoMap ser } func (nsc *NetworkServicesController) setupSloppyTCP(serviceInfoMap serviceInfoMap) { - enableSloppyTCP := false + var sloppyTCPVal int8 = 0 for _, svc := range serviceInfoMap { // Enable sloppy TCP if any DSR service with Maglev hashing is configured 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() - if enableSloppyTCP && sloppyTCP.CachedVal() == 0 { - sysctlErr := sloppyTCP.WriteVal(1) + if sloppyTCP.CachedVal() != sloppyTCPVal { + sysctlErr := sloppyTCP.WriteVal(sloppyTCPVal) if sysctlErr != nil { klog.Errorf("Failed to enable IPVS sloppy TCP: %s", sysctlErr.Error()) - } else { - klog.Infof("IPVS sloppy TCP enabled") + return } + klog.Infof("IPVS sloppy TCP set to %d", sloppyTCPVal) } } diff --git a/pkg/utils/node.go b/pkg/utils/node.go index 45c0cd65..d9a3bf3b 100644 --- a/pkg/utils/node.go +++ b/pkg/utils/node.go @@ -251,6 +251,8 @@ func NewKRNode(node *apiv1.Node, linkQ LocalLinkQuerier, enableIPv4, enableIPv6 }, linkQ: linkQ, 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{ name: IPv4IPVSSloppyTCP, value: 0,