Skip to content

Commit

Permalink
Merge pull request #5033 from WanzenBug/option-for-cgroup-parent-in-c…
Browse files Browse the repository at this point in the history
…ontainerd-worker

containerd: add option to set parent cgroup
  • Loading branch information
tonistiigi authored Jun 18, 2024
2 parents f1d1e99 + 5cb8618 commit 935713c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type ContainerdConfig struct {

MaxParallelism int `toml:"max-parallelism"`

DefaultCgroupParent string `toml:"defaultCgroupParent"`

Rootless bool `toml:"rootless"`
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/buildkitd/main_containerd_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([
Options: opts,
}
}
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))
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))
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions docs/buildkitd.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
# maintain a pool of reusable CNI network namespaces to amortize the overhead
# of allocating and releasing the namespaces
cniPoolSize = 16
# defaultCgroupParent sets the parent cgroup of all containers.
defaultCgroupParent = "buildkit"

[worker.containerd.labels]
"foo" = "bar"
Expand Down
7 changes: 4 additions & 3 deletions worker/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type RuntimeInfo = containerdexecutor.RuntimeInfo
// NewWorkerOpt creates a WorkerOpt.
func NewWorkerOpt(
root string,
address, snapshotterName, ns string,
address, snapshotterName, ns, cgroupParent string,
rootless bool,
labels map[string]string,
dns *oci.DNSConfig,
Expand Down Expand Up @@ -62,6 +62,7 @@ func NewWorkerOpt(
client,
snapshotterName,
ns,
cgroupParent,
rootless,
labels,
dns,
Expand All @@ -74,7 +75,7 @@ func NewWorkerOpt(
)
}

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) {
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) {
if strings.Contains(snapshotterName, "/") {
return base.WorkerOpt{}, errors.Errorf("bad snapshotter name: %q", snapshotterName)
}
Expand Down Expand Up @@ -176,7 +177,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns s
Labels: xlabels,
MetadataStore: md,
NetworkProviders: np,
Executor: containerdexecutor.New(client, root, "", np, dns, apparmorProfile, selinux, traceSocket, rootless, runtime),
Executor: containerdexecutor.New(client, root, cgroupParent, np, dns, apparmorProfile, selinux, traceSocket, rootless, runtime),
Snapshotter: snap,
ContentStore: cs,
Applier: winlayers.NewFileSystemApplierWithWindows(cs, df),
Expand Down
2 changes: 1 addition & 1 deletion worker/containerd/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestContainerdWorkerIntegration(t *testing.T) {
func newWorkerOpt(t *testing.T, addr string) base.WorkerOpt {
tmpdir := t.TempDir()
rootless := false
workerOpt, err := NewWorkerOpt(tmpdir, addr, "overlayfs", "buildkit-test", rootless, nil, nil, netproviders.Opt{Mode: "host"}, "", false, nil, "", nil)
workerOpt, err := NewWorkerOpt(tmpdir, addr, "overlayfs", "buildkit-test", "", rootless, nil, nil, netproviders.Opt{Mode: "host"}, "", false, nil, "", nil)
require.NoError(t, err)
return workerOpt
}
Expand Down

0 comments on commit 935713c

Please sign in to comment.