From fcbe61e613e9887de8d8dab0b4085e5e3ef54d04 Mon Sep 17 00:00:00 2001 From: "Kurniagusta Dwinto (win)" Date: Sat, 3 May 2025 20:47:08 +0700 Subject: [PATCH] fix: #1311 --- environment/container/docker/daemon.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/environment/container/docker/daemon.go b/environment/container/docker/daemon.go index 36032976..c58fdc57 100644 --- a/environment/container/docker/daemon.go +++ b/environment/container/docker/daemon.go @@ -29,6 +29,11 @@ func getHostGatewayIp(d dockerRuntime, conf map[string]any) (string, error) { return ip, nil } +func (d dockerRuntime) isSystemd() bool { + output, _ := d.guest.RunOutput("sh", "-c", "[ -S /run/systemd/private ] && printf true || printf false") + return output == "true" +} + func (d dockerRuntime) createDaemonFile(conf map[string]any, env map[string]string) error { if conf == nil { conf = map[string]any{} @@ -39,11 +44,24 @@ func (d dockerRuntime) createDaemonFile(conf map[string]any, env map[string]stri conf["features"] = map[string]any{"buildkit": true} } - // enable cgroupfs for k3s (if not set by user) + // set cgroupdriver for k3s (if not set by user) + cgroupDriver := "cgroupfs" + if d.isSystemd() { + cgroupDriver = "systemd" + } if _, ok := conf["exec-opts"]; !ok { - conf["exec-opts"] = []string{"native.cgroupdriver=cgroupfs"} + conf["exec-opts"] = []string{"native.cgroupdriver=" + cgroupDriver} } else if opts, ok := conf["exec-opts"].([]string); ok { - conf["exec-opts"] = append(opts, "native.cgroupdriver=cgroupfs") + manualCgroupDriver := false + for _, opt := range opts { + if strings.HasPrefix(opt, "native.cgroupdriver=") { + manualCgroupDriver = true + break + } + } + if !manualCgroupDriver { + conf["exec-opts"] = append(opts, "native.cgroupdriver="+cgroupDriver) + } } // remove host-gateway-ip if set by the user // to avoid clash with systemd configuration