Skip to content

Commit 02dfe87

Browse files
author
Harry Zhang
committed
Add container to pod qos cgroup
Signed-off-by: Harry Zhang <[email protected]>
1 parent 1d08519 commit 02dfe87

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

server/container_create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
251251
specgen.SetLinuxResourcesOOMScoreAdj(int(oomScoreAdj))
252252
}
253253

254+
if sb.cgroupParent != "" {
255+
// NOTE: we only support cgroupfs for now, discussion happens in issue #270.
256+
specgen.SetLinuxCgroupsPath(sb.cgroupParent + "/" + containerID)
257+
}
258+
254259
capabilities := linux.GetSecurityContext().GetCapabilities()
255260
if capabilities != nil {
256261
addCaps := capabilities.GetAddCapabilities()

server/sandbox.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import (
99
"sync"
1010

1111
"github.com/Sirupsen/logrus"
12+
"github.com/containernetworking/cni/pkg/ns"
1213
"github.com/docker/docker/pkg/stringid"
1314
"github.com/kubernetes-incubator/cri-o/oci"
14-
"github.com/containernetworking/cni/pkg/ns"
15+
"golang.org/x/sys/unix"
1516
"k8s.io/kubernetes/pkg/fields"
1617
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
17-
"golang.org/x/sys/unix"
1818
)
1919

2020
type sandboxNetNs struct {
2121
sync.Mutex
22-
ns ns.NetNS
23-
symlink *os.File
24-
closed bool
25-
restored bool
22+
ns ns.NetNS
23+
symlink *os.File
24+
closed bool
25+
restored bool
2626
}
2727

2828
func (ns *sandboxNetNs) symlinkCreate(name string) error {
@@ -138,6 +138,7 @@ type sandbox struct {
138138
netns *sandboxNetNs
139139
metadata *pb.PodSandboxMetadata
140140
shmPath string
141+
cgroupParent string
141142
}
142143

143144
const (
@@ -190,7 +191,7 @@ func (s *sandbox) netNsCreate() error {
190191
}
191192

192193
s.netns = &sandboxNetNs{
193-
ns: netNS,
194+
ns: netNS,
194195
closed: false,
195196
}
196197

server/sandbox_run.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
245245
// setup cgroup settings
246246
cgroupParent := req.GetConfig().GetLinux().GetCgroupParent()
247247
if cgroupParent != "" {
248-
g.SetLinuxCgroupsPath(cgroupParent)
248+
// NOTE: we only support cgroupfs for now, discussion happens in issue #270.
249+
g.SetLinuxCgroupsPath(cgroupParent + "/" + containerID)
250+
sb.cgroupParent = cgroupParent
249251
}
250252

251253
// set up namespaces
@@ -273,7 +275,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
273275
if netnsErr := sb.netNsRemove(); netnsErr != nil {
274276
logrus.Warnf("Failed to remove networking namespace: %v", netnsErr)
275277
}
276-
} ()
278+
}()
277279

278280
// Pass the created namespace path to the runtime
279281
err = g.AddOrReplaceLinuxNamespace("network", sb.netNsPath())

0 commit comments

Comments
 (0)