You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k3s/pkg/agent/syssetup/setup.go

44 lines
990 B

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