Skip to content

Commit

Permalink
proxy/ipvs: Describe and handle a bug in moby/ipvs
Browse files Browse the repository at this point in the history
Handle moby/ipvs#27
A work-around was already in place, but a segv would occur
when the bug is fixed. That will not happen now.
  • Loading branch information
Lars Ekman committed Dec 24, 2022
1 parent 68d78c8 commit 5ff705f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/proxy/ipvs/proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ func (handle *LinuxKernelHandler) GetKernelVersion() (string, error) {
// we check if a dummy VS can be configured with the configured scheduler.
// Kernel modules will be loaded automatically if necessary.
func CanUseIPVSProxier(ipvs utilipvs.Interface, ipsetver IPSetVersioner, scheduler string) error {
// BUG: https://github.com/moby/ipvs/issues/27
// If ipvs is not compiled into the kernel no error is returned and handle==nil.
// This in turn causes ipvs.GetVirtualServers and ipvs.AddVirtualServer
// to return ok (err==nil). If/when this bug is fixed parameter "ipvs" will be nil
// if ipvs is not supported by the kernel. Until then a re-read work-around is used.
if ipvs == nil {
return fmt.Errorf("Ipvs not supported by the kernel")
}

// Check ipset version
versionString, err := ipsetver.GetVersion()
if err != nil {
Expand All @@ -669,30 +678,25 @@ func CanUseIPVSProxier(ipvs utilipvs.Interface, ipsetver IPSetVersioner, schedul
scheduler = defaultScheduler
}

// Check is any virtual servers (vs) are configured. If any, we assume
// that this is a kube-proxy re-start and skip the checks.
// If any virtual server (VS) using the scheduler exist we skip the checks.
vservers, err := ipvs.GetVirtualServers()
if err != nil {
klog.ErrorS(err, "Can't read the ipvs")
return err
}
klog.V(5).InfoS("Virtual Servers", "count", len(vservers))
if len(vservers) > 0 {
klog.V(5).InfoS("Virtual server exists", "count", len(vservers))
// This is most likely a kube-proxy re-start. We know that ipvs works
// and if any VS uses the configured scheduler, we are done.
for _, vs := range vservers {
if vs.Scheduler == scheduler {
klog.V(5).InfoS("VS exist, Skipping checks")
return nil
}
}
klog.V(5).InfoS("No existing VS uses the configured scheduler", "scheduler", scheduler)
}

// BUG: If ipvs is not compiled into the kernel ipvs.GetVirtualServers
// does not return an error. Instead also ipvs.AddVirtualServer returns OK
// (no error)!

// Try to insert a dummy VS with the passed scheduler.
// We should use a VIP address that is not used on the node.
// An address "198.51.100.0" from the TEST-NET-2 rage in https://datatracker.ietf.org/doc/html/rfc5737
Expand Down Expand Up @@ -726,8 +730,8 @@ func CanUseIPVSProxier(ipvs utilipvs.Interface, ipsetver IPSetVersioner, schedul
klog.InfoS("Dummy VS not created", "scheduler", scheduler)
return fmt.Errorf("Ipvs not supported") // This is a BUG work-around
}

klog.V(5).InfoS("Dummy VS created", "vs", vs)

if err := ipvs.DeleteVirtualServer(&vs); err != nil {
klog.ErrorS(err, "Could not delete dummy VS")
return err
Expand Down

0 comments on commit 5ff705f

Please sign in to comment.