mirror of https://github.com/k3s-io/k3s
Support cgroup v2
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>pull/2576/head
parent
36230daa86
commit
0b45e32486
1
go.mod
1
go.mod
|
@ -64,6 +64,7 @@ require (
|
||||||
github.com/NYTimes/gziphandler v1.1.1 // indirect
|
github.com/NYTimes/gziphandler v1.1.1 // indirect
|
||||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
|
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
|
||||||
github.com/bronze1man/goStrongswanVici v0.0.0-20190828090544-27d02f80ba40 // indirect
|
github.com/bronze1man/goStrongswanVici v0.0.0-20190828090544-27d02f80ba40 // indirect
|
||||||
|
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340
|
||||||
github.com/containerd/containerd v1.4.1
|
github.com/containerd/containerd v1.4.1
|
||||||
github.com/containerd/cri v1.11.1-0.20200820101445-b0cc07999aa5
|
github.com/containerd/cri v1.11.1-0.20200820101445-b0cc07999aa5
|
||||||
github.com/coreos/flannel v0.12.0
|
github.com/coreos/flannel v0.12.0
|
||||||
|
|
|
@ -3,12 +3,15 @@ package agent
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/cgroups"
|
||||||
|
cgroupsv2 "github.com/containerd/cgroups/v2"
|
||||||
systemd "github.com/coreos/go-systemd/daemon"
|
systemd "github.com/coreos/go-systemd/daemon"
|
||||||
"github.com/rancher/k3s/pkg/agent/config"
|
"github.com/rancher/k3s/pkg/agent/config"
|
||||||
"github.com/rancher/k3s/pkg/agent/containerd"
|
"github.com/rancher/k3s/pkg/agent/containerd"
|
||||||
|
@ -170,6 +173,13 @@ func Run(ctx context.Context, cfg cmds.Agent) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validate() error {
|
func validate() error {
|
||||||
|
if cgroups.Mode() == cgroups.Unified {
|
||||||
|
return validateCgroupsV2()
|
||||||
|
}
|
||||||
|
return validateCgroupsV1()
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateCgroupsV1() error {
|
||||||
cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
|
cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -188,6 +198,27 @@ func validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateCgroupsV2() error {
|
||||||
|
manager, err := cgroupsv2.LoadManager("/sys/fs/cgroup", "/")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
controllers, err := manager.RootControllers()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m := make(map[string]struct{})
|
||||||
|
for _, controller := range controllers {
|
||||||
|
m[controller] = struct{}{}
|
||||||
|
}
|
||||||
|
for _, controller := range []string{"cpu", "cpuset", "memory"} {
|
||||||
|
if _, ok := m[controller]; !ok {
|
||||||
|
return fmt.Errorf("faild to find %s cgroup (v2)", controller)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configureNode(ctx context.Context, agentConfig *daemonconfig.Agent, nodes v1.NodeInterface) error {
|
func configureNode(ctx context.Context, agentConfig *daemonconfig.Agent, nodes v1.NodeInterface) error {
|
||||||
count := 0
|
count := 0
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -166,6 +166,7 @@ github.com/cilium/ebpf/internal/unix
|
||||||
# github.com/container-storage-interface/spec v1.2.0
|
# github.com/container-storage-interface/spec v1.2.0
|
||||||
github.com/container-storage-interface/spec/lib/go/csi
|
github.com/container-storage-interface/spec/lib/go/csi
|
||||||
# github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340 => github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59
|
# github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340 => github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59
|
||||||
|
## explicit
|
||||||
github.com/containerd/cgroups
|
github.com/containerd/cgroups
|
||||||
github.com/containerd/cgroups/stats/v1
|
github.com/containerd/cgroups/stats/v1
|
||||||
github.com/containerd/cgroups/v2
|
github.com/containerd/cgroups/v2
|
||||||
|
|
Loading…
Reference in New Issue