Commit 4bba0402 authored by Erik Wilson's avatar Erik Wilson Committed by Erik Wilson

Check for cgroup pids support

If cgroup pids are not supported add a feature-gates flag SupportPodPidsLimit=false for kubelet.
parent af2fc722
...@@ -101,17 +101,23 @@ func kubelet(cfg *config.Agent) { ...@@ -101,17 +101,23 @@ func kubelet(cfg *config.Agent) {
if err != nil || defaultIP.String() != cfg.NodeIP { if err != nil || defaultIP.String() != cfg.NodeIP {
argsMap["node-ip"] = cfg.NodeIP argsMap["node-ip"] = cfg.NodeIP
} }
root, hasCFS := checkCgroups() root, hasCFS, hasPIDs := checkCgroups()
if !hasCFS { if !hasCFS {
logrus.Warn("Disabling CPU quotas due to missing cpu.cfs_period_us") logrus.Warn("Disabling CPU quotas due to missing cpu.cfs_period_us")
argsMap["cpu-cfs-quota"] = "false" argsMap["cpu-cfs-quota"] = "false"
} }
if !hasPIDs {
logrus.Warn("Disabling pod PIDs limit feature due to missing cgroup pids support")
argsMap["cgroups-per-qos"] = "false"
argsMap["enforce-node-allocatable"] = ""
argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "SupportPodPidsLimit=false")
}
if root != "" { if root != "" {
argsMap["runtime-cgroups"] = root argsMap["runtime-cgroups"] = root
argsMap["kubelet-cgroups"] = root argsMap["kubelet-cgroups"] = root
} }
if system.RunningInUserNS() { if system.RunningInUserNS() {
argsMap["feature-gates"] = "DevicePlugins=false" argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "DevicePlugins=false")
} }
args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs) args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs)
...@@ -123,15 +129,20 @@ func kubelet(cfg *config.Agent) { ...@@ -123,15 +129,20 @@ func kubelet(cfg *config.Agent) {
}() }()
} }
func checkCgroups() (string, bool) { func addFeatureGate(current, new string) string {
if current == "" {
return new
}
return current + "," + new
}
func checkCgroups() (root string, hasCFS bool, hasPIDs bool) {
f, err := os.Open("/proc/self/cgroup") f, err := os.Open("/proc/self/cgroup")
if err != nil { if err != nil {
return "", false return "", false, false
} }
defer f.Close() defer f.Close()
ret := false
root := ""
scan := bufio.NewScanner(f) scan := bufio.NewScanner(f)
for scan.Scan() { for scan.Scan() {
parts := strings.Split(scan.Text(), ":") parts := strings.Split(scan.Text(), ":")
...@@ -140,10 +151,12 @@ func checkCgroups() (string, bool) { ...@@ -140,10 +151,12 @@ func checkCgroups() (string, bool) {
} }
systems := strings.Split(parts[1], ",") systems := strings.Split(parts[1], ",")
for _, system := range systems { for _, system := range systems {
if system == "cpu" { if system == "pids" {
hasPIDs = true
} else if system == "cpu" {
p := filepath.Join("/sys/fs/cgroup", parts[1], parts[2], "cpu.cfs_period_us") p := filepath.Join("/sys/fs/cgroup", parts[1], parts[2], "cpu.cfs_period_us")
if _, err := os.Stat(p); err == nil { if _, err := os.Stat(p); err == nil {
ret = true hasCFS = true
} }
} else if system == "name=systemd" { } else if system == "name=systemd" {
last := parts[len(parts)-1] last := parts[len(parts)-1]
...@@ -155,5 +168,5 @@ func checkCgroups() (string, bool) { ...@@ -155,5 +168,5 @@ func checkCgroups() (string, bool) {
} }
} }
return root, ret return root, hasCFS, hasPIDs
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment