Skip to content

Commit d52485c

Browse files
committed
propagate the dockerd cgroup-parent config to buildkitd
Signed-off-by: Anda Xu <[email protected]>
1 parent b0bc9f6 commit d52485c

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

builder/builder-next/builder.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ func init() {
5050

5151
// Opt is option struct required for creating the builder
5252
type Opt struct {
53-
SessionManager *session.Manager
54-
Root string
55-
Dist images.DistributionServices
56-
NetworkController libnetwork.NetworkController
53+
SessionManager *session.Manager
54+
Root string
55+
Dist images.DistributionServices
56+
NetworkController libnetwork.NetworkController
57+
DefaultCgroupParent string
5758
}
5859

5960
// Builder can build using BuildKit backend

builder/builder-next/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
102102
return nil, err
103103
}
104104

105-
exec, err := newExecutor(root, opt.NetworkController)
105+
exec, err := newExecutor(root, opt.DefaultCgroupParent, opt.NetworkController)
106106
if err != nil {
107107
return nil, err
108108
}

builder/builder-next/executor_unix.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import (
1919

2020
const networkName = "bridge"
2121

22-
func newExecutor(root string, net libnetwork.NetworkController) (executor.Executor, error) {
22+
func newExecutor(root, cgroupParent string, net libnetwork.NetworkController) (executor.Executor, error) {
2323
networkProviders := map[pb.NetMode]network.Provider{
2424
pb.NetMode_UNSET: &bridgeProvider{NetworkController: net},
2525
pb.NetMode_HOST: network.NewHostProvider(),
2626
pb.NetMode_NONE: network.NewNoneProvider(),
2727
}
2828
return runcexecutor.New(runcexecutor.Opt{
29-
Root: filepath.Join(root, "executor"),
30-
CommandCandidates: []string{"docker-runc", "runc"},
29+
Root: filepath.Join(root, "executor"),
30+
CommandCandidates: []string{"docker-runc", "runc"},
31+
DefaultCgroupParent: cgroupParent,
3132
}, networkProviders)
3233
}
3334

cmd/dockerd/daemon.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,23 @@ func newRouterOptions(config *config.Config, daemon *daemon.Daemon) (routerOptio
284284
if err != nil {
285285
return opts, err
286286
}
287+
cgroupParent := "docker"
288+
useSystemd := daemon.UsingSystemd(config)
289+
if useSystemd {
290+
cgroupParent = "system.slice"
291+
}
292+
if config.CgroupParent != "" {
293+
cgroupParent = config.CgroupParent
294+
}
295+
if useSystemd {
296+
cgroupParent = cgroupParent + ":" + "docker" + ":"
297+
}
287298
bk, err := buildkit.New(buildkit.Opt{
288-
SessionManager: sm,
289-
Root: filepath.Join(config.Root, "buildkit"),
290-
Dist: daemon.DistributionServices(),
291-
NetworkController: daemon.NetworkController(),
299+
SessionManager: sm,
300+
Root: filepath.Join(config.Root, "buildkit"),
301+
Dist: daemon.DistributionServices(),
302+
NetworkController: daemon.NetworkController(),
303+
DefaultCgroupParent: cgroupParent,
292304
})
293305
if err != nil {
294306
return opts, err

0 commit comments

Comments
 (0)