Skip to content

Commit 935713c

Browse files
authored
Merge pull request moby#5033 from WanzenBug/option-for-cgroup-parent-in-containerd-worker
containerd: add option to set parent cgroup
2 parents f1d1e99 + 5cb8618 commit 935713c

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

cmd/buildkitd/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ type ContainerdConfig struct {
142142

143143
MaxParallelism int `toml:"max-parallelism"`
144144

145+
DefaultCgroupParent string `toml:"defaultCgroupParent"`
146+
145147
Rootless bool `toml:"rootless"`
146148
}
147149

cmd/buildkitd/main_containerd_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([
328328
Options: opts,
329329
}
330330
}
331-
opt, err := containerd.NewWorkerOpt(common.config.Root, cfg.Address, snapshotter, cfg.Namespace, cfg.Rootless, cfg.Labels, dns, nc, common.config.Workers.Containerd.ApparmorProfile, common.config.Workers.Containerd.SELinux, parallelismSem, common.traceSocket, runtime, ctd.WithTimeout(60*time.Second))
331+
opt, err := containerd.NewWorkerOpt(common.config.Root, cfg.Address, snapshotter, cfg.Namespace, cfg.DefaultCgroupParent, cfg.Rootless, cfg.Labels, dns, nc, common.config.Workers.Containerd.ApparmorProfile, common.config.Workers.Containerd.SELinux, parallelismSem, common.traceSocket, runtime, ctd.WithTimeout(60*time.Second))
332332
if err != nil {
333333
return nil, err
334334
}

docs/buildkitd.toml.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
104104
# maintain a pool of reusable CNI network namespaces to amortize the overhead
105105
# of allocating and releasing the namespaces
106106
cniPoolSize = 16
107+
# defaultCgroupParent sets the parent cgroup of all containers.
108+
defaultCgroupParent = "buildkit"
107109

108110
[worker.containerd.labels]
109111
"foo" = "bar"

worker/containerd/containerd.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type RuntimeInfo = containerdexecutor.RuntimeInfo
3333
// NewWorkerOpt creates a WorkerOpt.
3434
func NewWorkerOpt(
3535
root string,
36-
address, snapshotterName, ns string,
36+
address, snapshotterName, ns, cgroupParent string,
3737
rootless bool,
3838
labels map[string]string,
3939
dns *oci.DNSConfig,
@@ -62,6 +62,7 @@ func NewWorkerOpt(
6262
client,
6363
snapshotterName,
6464
ns,
65+
cgroupParent,
6566
rootless,
6667
labels,
6768
dns,
@@ -74,7 +75,7 @@ func NewWorkerOpt(
7475
)
7576
}
7677

77-
func newContainerd(root string, client *containerd.Client, snapshotterName, ns string, rootless bool, labels map[string]string, dns *oci.DNSConfig, nopt netproviders.Opt, apparmorProfile string, selinux bool, parallelismSem *semaphore.Weighted, traceSocket string, runtime *RuntimeInfo) (base.WorkerOpt, error) {
78+
func newContainerd(root string, client *containerd.Client, snapshotterName, ns, cgroupParent string, rootless bool, labels map[string]string, dns *oci.DNSConfig, nopt netproviders.Opt, apparmorProfile string, selinux bool, parallelismSem *semaphore.Weighted, traceSocket string, runtime *RuntimeInfo) (base.WorkerOpt, error) {
7879
if strings.Contains(snapshotterName, "/") {
7980
return base.WorkerOpt{}, errors.Errorf("bad snapshotter name: %q", snapshotterName)
8081
}
@@ -176,7 +177,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns s
176177
Labels: xlabels,
177178
MetadataStore: md,
178179
NetworkProviders: np,
179-
Executor: containerdexecutor.New(client, root, "", np, dns, apparmorProfile, selinux, traceSocket, rootless, runtime),
180+
Executor: containerdexecutor.New(client, root, cgroupParent, np, dns, apparmorProfile, selinux, traceSocket, rootless, runtime),
180181
Snapshotter: snap,
181182
ContentStore: cs,
182183
Applier: winlayers.NewFileSystemApplierWithWindows(cs, df),

worker/containerd/containerd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestContainerdWorkerIntegration(t *testing.T) {
3131
func newWorkerOpt(t *testing.T, addr string) base.WorkerOpt {
3232
tmpdir := t.TempDir()
3333
rootless := false
34-
workerOpt, err := NewWorkerOpt(tmpdir, addr, "overlayfs", "buildkit-test", rootless, nil, nil, netproviders.Opt{Mode: "host"}, "", false, nil, "", nil)
34+
workerOpt, err := NewWorkerOpt(tmpdir, addr, "overlayfs", "buildkit-test", "", rootless, nil, nil, netproviders.Opt{Mode: "host"}, "", false, nil, "", nil)
3535
require.NoError(t, err)
3636
return workerOpt
3737
}

0 commit comments

Comments
 (0)