Merge pull request #83553 from rikatz/issue77493-part1

Improve IPVS Module loader logic
This commit is contained in:
Kubernetes Prow Robot 2019-10-15 23:05:13 -07:00 committed by GitHub
commit a7b3114c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -580,30 +580,12 @@ func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
}
ipvsModules := utilipvs.GetRequiredIPVSModules(kernelVersion)
builtinModsFilePath := fmt.Sprintf("/lib/modules/%s/modules.builtin", kernelVersionStr)
b, err := ioutil.ReadFile(builtinModsFilePath)
if err != nil {
klog.Warningf("Failed to read file %s with error %v. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules", builtinModsFilePath, err)
}
var bmods []string
for _, module := range ipvsModules {
if match, _ := regexp.Match(module+".ko", b); match {
bmods = append(bmods, module)
}
}
// Try to load IPVS required kernel modules using modprobe first
for _, kmod := range ipvsModules {
err := handle.executor.Command("modprobe", "--", kmod).Run()
if err != nil {
klog.Warningf("Failed to load kernel module %v with modprobe. "+
"You can ignore this message when kube-proxy is running inside container without mounting /lib/modules", kmod)
}
}
// Find out loaded kernel modules
// Find out loaded kernel modules. If this is a full static kernel it will thrown an error
modulesFile, err := os.Open("/proc/modules")
if err != nil {
klog.Warningf("Failed to read file /proc/modules with error %v. Kube-proxy requires loadable modules support enabled in the kernel", err)
return nil, err
}
@ -612,6 +594,25 @@ func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
return nil, fmt.Errorf("failed to find loaded kernel modules: %v", err)
}
builtinModsFilePath := fmt.Sprintf("/lib/modules/%s/modules.builtin", kernelVersionStr)
b, err := ioutil.ReadFile(builtinModsFilePath)
if err != nil {
klog.Warningf("Failed to read file %s with error %v. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules", builtinModsFilePath, err)
}
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.Warningf("Failed to load kernel module %v with modprobe. "+
"You can ignore this message when kube-proxy is running inside container without mounting /lib/modules", module)
}
}
}
return append(mods, bmods...), nil
}