Validate that memory cgroup exists

pull/22/head
Darren Shepherd 6 years ago
parent 8bdd86198c
commit 04c5567346

@ -2,8 +2,11 @@ package agent
import ( import (
"context" "context"
"errors"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"github.com/rancher/k3s/pkg/agent/config" "github.com/rancher/k3s/pkg/agent/config"
@ -62,6 +65,10 @@ func run(ctx context.Context, cfg cmds.Agent) error {
} }
func Run(ctx context.Context, cfg cmds.Agent) error { func Run(ctx context.Context, cfg cmds.Agent) error {
if err := validate(); err != nil {
return err
}
cfg.DataDir = filepath.Join(cfg.DataDir, "agent") cfg.DataDir = filepath.Join(cfg.DataDir, "agent")
if cfg.ClusterSecret != "" { if cfg.ClusterSecret != "" {
@ -86,3 +93,22 @@ func Run(ctx context.Context, cfg cmds.Agent) error {
os.MkdirAll(cfg.DataDir, 0700) os.MkdirAll(cfg.DataDir, 0700)
return run(ctx, cfg) return run(ctx, cfg)
} }
func validate() error {
cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
if err != nil {
return err
}
if !strings.Contains(string(cgroups), "cpuset") {
logrus.Warn("Failed to find cpuset cgroup, you may need to add \"cgroup_enable=cpuset\" to your linux cmdline (/boot/cmdline.txt on a Raspberry Pi)")
}
if !strings.Contains(string(cgroups), "memory") {
msg := "ailed to find memory cgroup, you may need to add \"cgroup_memory=1 cgroup_enable=memory\" to your linux cmdline (/boot/cmdline.txt on a Raspberry Pi)"
logrus.Error("F" + msg)
return errors.New("f" + msg)
}
return nil
}

Loading…
Cancel
Save