k3s/pkg/agent/syssetup/setup.go

44 lines
990 B
Go
Raw Normal View History

2019-01-01 08:23:01 +00:00
package syssetup
import (
"io/ioutil"
"os"
"os/exec"
2019-01-01 08:23:01 +00:00
"github.com/sirupsen/logrus"
)
var (
callIPTablesFile = "/proc/sys/net/bridge/bridge-nf-call-iptables"
forward = "/proc/sys/net/ipv4/ip_forward"
2019-01-01 08:23:01 +00:00
)
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")
2019-01-01 08:23:01 +00:00
if err := ioutil.WriteFile(callIPTablesFile, []byte("1"), 0640); err != nil {
logrus.Warnf("failed to write value 1 at %s: %v", callIPTablesFile, err)
return nil
2019-01-01 08:23:01 +00:00
}
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")
2019-01-01 08:23:01 +00:00
return nil
}