Skip to content

Commit

Permalink
Merge pull request kubernetes#63850 from islinwb/check_ipvs_mod
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Enable checking whether ipvs modules are built-in or not

**What this PR does / why we need it**:
Enable checking whether ipvs modules are built-in or not.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes kubernetes#63801

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored May 16, 2018
2 parents 8c24052 + c3e2fc0 commit 6406b96
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/proxy/ipvs/proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package ipvs
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"regexp"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -440,6 +442,25 @@ func NewLinuxKernelHandler() *LinuxKernelHandler {

// GetModules returns all installed kernel modules.
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
for _, kmod := range ipvsModules {
err := handle.executor.Command("modprobe", "--", kmod).Run()
Expand All @@ -456,7 +477,7 @@ func (handle *LinuxKernelHandler) GetModules() ([]string, error) {
}

mods := strings.Split(string(out), "\n")
return mods, nil
return append(mods, bmods...), nil
}

// CanUseIPVSProxier returns true if we can use the ipvs Proxier.
Expand Down

0 comments on commit 6406b96

Please sign in to comment.