mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Enable checking whether ipvs modules are built-in or not
This commit is contained in:
parent
e3b0e85138
commit
c3e2fc0c0f
@ -23,7 +23,9 @@ package ipvs
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -412,6 +414,25 @@ func NewLinuxKernelHandler() *LinuxKernelHandler {
|
|||||||
|
|
||||||
// GetModules returns all installed kernel modules.
|
// GetModules returns all installed kernel modules.
|
||||||
func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
|
func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
|
||||||
|
// Check whether IPVS required kernel modules are built-in
|
||||||
|
kernelVersionFile := "/proc/sys/kernel/osrelease"
|
||||||
|
b, err := ioutil.ReadFile(kernelVersionFile)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Failed to read file %s with error %v", kernelVersionFile, err)
|
||||||
|
}
|
||||||
|
kernelVersion := strings.TrimSpace(string(b))
|
||||||
|
builtinModsFilePath := fmt.Sprintf("/lib/modules/%s/modules.builtin", kernelVersion)
|
||||||
|
b, err = ioutil.ReadFile(builtinModsFilePath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Failed to read file %s with error %v", 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
|
// Try to load IPVS required kernel modules using modprobe first
|
||||||
for _, kmod := range ipvsModules {
|
for _, kmod := range ipvsModules {
|
||||||
err := handle.executor.Command("modprobe", "--", kmod).Run()
|
err := handle.executor.Command("modprobe", "--", kmod).Run()
|
||||||
@ -428,7 +449,7 @@ func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mods := strings.Split(string(out), "\n")
|
mods := strings.Split(string(out), "\n")
|
||||||
return mods, nil
|
return append(mods, bmods...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanUseIPVSProxier returns true if we can use the ipvs Proxier.
|
// CanUseIPVSProxier returns true if we can use the ipvs Proxier.
|
||||||
|
Loading…
Reference in New Issue
Block a user