diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index f96efa85057..a4ceb050da4 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -24,7 +24,6 @@ import ( "net" "os" "reflect" - "regexp" "strconv" "strings" "sync" @@ -606,7 +605,6 @@ func newServiceInfo(port *v1.ServicePort, service *v1.Service, bsvcPortInfo *pro // KernelHandler can handle the current installed kernel modules. type KernelHandler interface { - GetModules() ([]string, error) GetKernelVersion() (string, error) } @@ -622,73 +620,6 @@ func NewLinuxKernelHandler() *LinuxKernelHandler { } } -// GetModules returns all installed kernel modules. -func (handle *LinuxKernelHandler) GetModules() ([]string, error) { - // Check whether IPVS required kernel modules are built-in - kernelVersionStr, err := handle.GetKernelVersion() - if err != nil { - return nil, err - } - kernelVersion, err := version.ParseGeneric(kernelVersionStr) - if err != nil { - return nil, fmt.Errorf("error parsing kernel version %q: %v", kernelVersionStr, err) - } - ipvsModules := utilipvs.GetRequiredIPVSModules(kernelVersion) - - var bmods, lmods []string - - // Find out loaded kernel modules. If this is a full static kernel it will try to verify if the module is compiled using /boot/config-KERNELVERSION - modulesFile, err := os.Open("/proc/modules") - if err == os.ErrNotExist { - klog.ErrorS(err, "Failed to read file /proc/modules, assuming this is a kernel without loadable modules support enabled") - kernelConfigFile := fmt.Sprintf("/boot/config-%s", kernelVersionStr) - kConfig, err := os.ReadFile(kernelConfigFile) - if err != nil { - return nil, fmt.Errorf("failed to read Kernel Config file %s with error %w", kernelConfigFile, err) - } - for _, module := range ipvsModules { - if match, _ := regexp.Match("CONFIG_"+strings.ToUpper(module)+"=y", kConfig); match { - bmods = append(bmods, module) - } - } - return bmods, nil - } - if err != nil { - return nil, fmt.Errorf("failed to read file /proc/modules with error %w", err) - } - defer modulesFile.Close() - - mods, err := getFirstColumn(modulesFile) - if err != nil { - return nil, fmt.Errorf("failed to find loaded kernel modules: %v", err) - } - - builtinModsFilePath := fmt.Sprintf("/lib/modules/%s/modules.builtin", kernelVersionStr) - b, err := os.ReadFile(builtinModsFilePath) - if err != nil { - klog.ErrorS(err, "Failed to read builtin modules file, you can ignore this message when kube-proxy is running inside container without mounting /lib/modules", "filePath", builtinModsFilePath) - } - - for _, module := range ipvsModules { - if match, _ := regexp.Match(module+".ko", b); match { - bmods = append(bmods, module) - } else { - // Try to load the required IPVS kernel modules if not built in - err := handle.executor.Command("modprobe", "--", module).Run() - if err != nil { - klog.InfoS("Failed to load kernel module with modprobe, "+ - "you can ignore this message when kube-proxy is running inside container without mounting /lib/modules", "moduleName", module) - } else { - lmods = append(lmods, module) - } - } - } - - mods = append(mods, bmods...) - mods = append(mods, lmods...) - return mods, nil -} - // getFirstColumn reads all the content from r into memory and return a // slice which consists of the first word from each line. func getFirstColumn(r io.Reader) ([]string, error) { diff --git a/pkg/util/ipvs/ipvs.go b/pkg/util/ipvs/ipvs.go index 419c5f46af0..2bb08e430a5 100644 --- a/pkg/util/ipvs/ipvs.go +++ b/pkg/util/ipvs/ipvs.go @@ -21,8 +21,6 @@ import ( "strconv" "strings" "time" - - "k8s.io/apimachinery/pkg/util/version" ) // Interface is an injectable interface for running ipvs commands. Implementations must be goroutine-safe. @@ -71,22 +69,6 @@ const ( FlagHashed = 0x2 ) -// IPVS required kernel modules. -const ( - // KernelModuleIPVS is the kernel module "ip_vs" - KernelModuleIPVS string = "ip_vs" - // KernelModuleIPVSRR is the kernel module "ip_vs_rr" - KernelModuleIPVSRR string = "ip_vs_rr" - // KernelModuleIPVSWRR is the kernel module "ip_vs_wrr" - KernelModuleIPVSWRR string = "ip_vs_wrr" - // KernelModuleIPVSSH is the kernel module "ip_vs_sh" - KernelModuleIPVSSH string = "ip_vs_sh" - // KernelModuleNfConntrackIPV4 is the module "nf_conntrack_ipv4" - KernelModuleNfConntrackIPV4 string = "nf_conntrack_ipv4" - // KernelModuleNfConntrack is the kernel module "nf_conntrack" - KernelModuleNfConntrack string = "nf_conntrack" -) - // Equal check the equality of virtual server. // We don't use struct == since it doesn't work because of slice. func (svc *VirtualServer) Equal(other *VirtualServer) bool { @@ -122,17 +104,6 @@ func (rs *RealServer) Equal(other *RealServer) bool { rs.Port == other.Port } -// GetRequiredIPVSModules returns the required ipvs modules for the given linux kernel version. -func GetRequiredIPVSModules(kernelVersion *version.Version) []string { - // "nf_conntrack_ipv4" has been removed since v4.19 - // see https://github.com/torvalds/linux/commit/a0ae2562c6c4b2721d9fddba63b7286c13517d9f - if kernelVersion.LessThan(version.MustParseGeneric("4.19")) { - return []string{KernelModuleIPVS, KernelModuleIPVSRR, KernelModuleIPVSWRR, KernelModuleIPVSSH, KernelModuleNfConntrackIPV4} - } - return []string{KernelModuleIPVS, KernelModuleIPVSRR, KernelModuleIPVSWRR, KernelModuleIPVSSH, KernelModuleNfConntrack} - -} - // IsRsGracefulTerminationNeeded returns true if protocol requires graceful termination for the stale connections func IsRsGracefulTerminationNeeded(proto string) bool { return !strings.EqualFold(proto, "UDP") && !strings.EqualFold(proto, "SCTP")