From 02dfe877e4e4281cecc1e6101f7a867a24c0845c Mon Sep 17 00:00:00 2001 From: Harry Zhang Date: Tue, 13 Dec 2016 16:34:55 +0800 Subject: [PATCH] Add container to pod qos cgroup Signed-off-by: Harry Zhang --- server/container_create.go | 5 +++++ server/sandbox.go | 15 ++++++++------- server/sandbox_run.go | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/container_create.go b/server/container_create.go index 396d4c12..6ed46281 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -251,6 +251,11 @@ func (s *Server) createSandboxContainer(containerID string, containerName string specgen.SetLinuxResourcesOOMScoreAdj(int(oomScoreAdj)) } + if sb.cgroupParent != "" { + // NOTE: we only support cgroupfs for now, discussion happens in issue #270. + specgen.SetLinuxCgroupsPath(sb.cgroupParent + "/" + containerID) + } + capabilities := linux.GetSecurityContext().GetCapabilities() if capabilities != nil { addCaps := capabilities.GetAddCapabilities() diff --git a/server/sandbox.go b/server/sandbox.go index 83c0eef5..3348ed53 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -9,20 +9,20 @@ import ( "sync" "github.com/Sirupsen/logrus" + "github.com/containernetworking/cni/pkg/ns" "github.com/docker/docker/pkg/stringid" "github.com/kubernetes-incubator/cri-o/oci" - "github.com/containernetworking/cni/pkg/ns" + "golang.org/x/sys/unix" "k8s.io/kubernetes/pkg/fields" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" - "golang.org/x/sys/unix" ) type sandboxNetNs struct { sync.Mutex - ns ns.NetNS - symlink *os.File - closed bool - restored bool + ns ns.NetNS + symlink *os.File + closed bool + restored bool } func (ns *sandboxNetNs) symlinkCreate(name string) error { @@ -138,6 +138,7 @@ type sandbox struct { netns *sandboxNetNs metadata *pb.PodSandboxMetadata shmPath string + cgroupParent string } const ( @@ -190,7 +191,7 @@ func (s *sandbox) netNsCreate() error { } s.netns = &sandboxNetNs{ - ns: netNS, + ns: netNS, closed: false, } diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 7c0d604c..498e6a3d 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -245,7 +245,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest // setup cgroup settings cgroupParent := req.GetConfig().GetLinux().GetCgroupParent() if cgroupParent != "" { - g.SetLinuxCgroupsPath(cgroupParent) + // NOTE: we only support cgroupfs for now, discussion happens in issue #270. + g.SetLinuxCgroupsPath(cgroupParent + "/" + containerID) + sb.cgroupParent = cgroupParent } // set up namespaces @@ -273,7 +275,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest if netnsErr := sb.netNsRemove(); netnsErr != nil { logrus.Warnf("Failed to remove networking namespace: %v", netnsErr) } - } () + }() // Pass the created namespace path to the runtime err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath())