mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
f0f57c1e44
Signed-off-by: Wenxuan Zhao <viz@linux.com>
44 lines
990 B
Go
44 lines
990 B
Go
package syssetup
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
callIPTablesFile = "/proc/sys/net/bridge/bridge-nf-call-iptables"
|
|
forward = "/proc/sys/net/ipv4/ip_forward"
|
|
)
|
|
|
|
func loadKernelModule(moduleName string) {
|
|
if _, err := os.Stat("/sys/module/" + moduleName); err == nil {
|
|
logrus.Infof("module %s was already loaded", moduleName)
|
|
return
|
|
}
|
|
|
|
if err := exec.Command("modprobe", moduleName).Run(); err != nil {
|
|
logrus.Warnf("failed to start %s module", moduleName)
|
|
}
|
|
}
|
|
|
|
func Configure() error {
|
|
loadKernelModule("br_netfilter")
|
|
|
|
if err := ioutil.WriteFile(callIPTablesFile, []byte("1"), 0640); err != nil {
|
|
logrus.Warnf("failed to write value 1 at %s: %v", callIPTablesFile, err)
|
|
return nil
|
|
}
|
|
if err := ioutil.WriteFile(forward, []byte("1"), 0640); err != nil {
|
|
logrus.Warnf("failed to write value 1 at %s: %v", forward, err)
|
|
return nil
|
|
}
|
|
|
|
loadKernelModule("overlay")
|
|
loadKernelModule("nf_conntrack")
|
|
|
|
return nil
|
|
}
|