Add container to pod qos cgroup

Signed-off-by: Harry Zhang <harryz@hyper.sh>
This commit is contained in:
Harry Zhang 2016-12-13 16:34:55 +08:00
parent 1d08519ffe
commit 02dfe877e4
3 changed files with 17 additions and 9 deletions

View file

@ -251,6 +251,11 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
specgen.SetLinuxResourcesOOMScoreAdj(int(oomScoreAdj)) 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() capabilities := linux.GetSecurityContext().GetCapabilities()
if capabilities != nil { if capabilities != nil {
addCaps := capabilities.GetAddCapabilities() addCaps := capabilities.GetAddCapabilities()

View file

@ -9,20 +9,20 @@ import (
"sync" "sync"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/containernetworking/cni/pkg/ns"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/kubernetes-incubator/cri-o/oci" "github.com/kubernetes-incubator/cri-o/oci"
"github.com/containernetworking/cni/pkg/ns" "golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"golang.org/x/sys/unix"
) )
type sandboxNetNs struct { type sandboxNetNs struct {
sync.Mutex sync.Mutex
ns ns.NetNS ns ns.NetNS
symlink *os.File symlink *os.File
closed bool closed bool
restored bool restored bool
} }
func (ns *sandboxNetNs) symlinkCreate(name string) error { func (ns *sandboxNetNs) symlinkCreate(name string) error {
@ -138,6 +138,7 @@ type sandbox struct {
netns *sandboxNetNs netns *sandboxNetNs
metadata *pb.PodSandboxMetadata metadata *pb.PodSandboxMetadata
shmPath string shmPath string
cgroupParent string
} }
const ( const (
@ -190,7 +191,7 @@ func (s *sandbox) netNsCreate() error {
} }
s.netns = &sandboxNetNs{ s.netns = &sandboxNetNs{
ns: netNS, ns: netNS,
closed: false, closed: false,
} }

View file

@ -245,7 +245,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
// setup cgroup settings // setup cgroup settings
cgroupParent := req.GetConfig().GetLinux().GetCgroupParent() cgroupParent := req.GetConfig().GetLinux().GetCgroupParent()
if cgroupParent != "" { 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 // set up namespaces
@ -273,7 +275,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
if netnsErr := sb.netNsRemove(); netnsErr != nil { if netnsErr := sb.netNsRemove(); netnsErr != nil {
logrus.Warnf("Failed to remove networking namespace: %v", netnsErr) logrus.Warnf("Failed to remove networking namespace: %v", netnsErr)
} }
} () }()
// Pass the created namespace path to the runtime // Pass the created namespace path to the runtime
err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath()) err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath())