@@ -104,7 +104,7 @@ var ring0Cmd = &cobra.Command{
104
104
cmd := exec .Command ("/proc/self/exe" , "ring1" )
105
105
cmd .SysProcAttr = & syscall.SysProcAttr {
106
106
Pdeathsig : syscall .SIGKILL ,
107
- Cloneflags : syscall .CLONE_NEWUSER | syscall .CLONE_NEWNS ,
107
+ Cloneflags : syscall .CLONE_NEWUSER | syscall .CLONE_NEWNS | unix . CLONE_NEWCGROUP ,
108
108
}
109
109
cmd .Stdin = os .Stdin
110
110
cmd .Stdout = os .Stdout
@@ -288,6 +288,12 @@ var ring1Cmd = &cobra.Command{
288
288
}
289
289
mnts = append (mnts , mnte {Target : "/tmp" , Source : "tmpfs" , FSType : "tmpfs" })
290
290
291
+ // If this is a cgroupv2 machine, we'll want to mount the cgroup2 FS ourselves
292
+ if _ , err := os .Stat ("/sys/fs/cgroup/cgroup.controllers" ); err == nil {
293
+ mnts = append (mnts , mnte {Target : "/sys/fs/cgroup" , Source : "tmpfs" , FSType : "tmpfs" })
294
+ mnts = append (mnts , mnte {Target : "/sys/fs/cgroup" , Source : "cgroup" , FSType : "cgroup2" })
295
+ }
296
+
291
297
if adds := os .Getenv ("GITPOD_WORKSPACEKIT_BIND_MOUNTS" ); adds != "" {
292
298
var additionalMounts []string
293
299
err = json .Unmarshal ([]byte (adds ), & additionalMounts )
@@ -335,14 +341,13 @@ var ring1Cmd = &cobra.Command{
335
341
}).Debug ("mounting new rootfs" )
336
342
err = unix .Mount (m .Source , dst , m .FSType , m .Flags , "" )
337
343
if err != nil {
338
- log .WithError (err ).WithField ("dest" , dst ).Error ("cannot establish mount" )
344
+ log .WithError (err ).WithField ("dest" , dst ).WithField ( "fsType" , m . FSType ). Error ("cannot establish mount" )
339
345
return
340
346
}
341
347
}
342
348
343
349
// We deliberately do not bind mount `/etc/resolv.conf` and `/etc/hosts`, but instead place a copy
344
350
// so that users in the workspace can modify the file.
345
-
346
351
copyPaths := []string {"/etc/resolv.conf" , "/etc/hosts" }
347
352
for _ , fn := range copyPaths {
348
353
err = copyRing2Root (ring2Root , fn )
@@ -411,12 +416,18 @@ var ring1Cmd = &cobra.Command{
411
416
Target : procLoc ,
412
417
Pid : int64 (cmd .Process .Pid ),
413
418
})
414
- client .Close ()
415
-
416
419
if err != nil {
420
+ client .Close ()
417
421
log .WithError (err ).Error ("cannot mount proc" )
418
422
return
419
423
}
424
+ _ , err = client .EvacuateCGroup (ctx , & daemonapi.EvacuateCGroupRequest {})
425
+ if err != nil {
426
+ client .Close ()
427
+ log .WithError (err ).Error ("cannot evacuate cgroup" )
428
+ return
429
+ }
430
+ client .Close ()
420
431
421
432
// We have to wait for ring2 to come back to us and connect to the socket we've passed along.
422
433
// There's a chance that ring2 crashes or misbehaves, so we don't want to wait forever, hence
@@ -618,7 +629,7 @@ func findBindMountCandidates(procMounts io.Reader, readlink func(path string) (d
618
629
reject bool
619
630
)
620
631
switch fs {
621
- case "cgroup" , "devpts" , "mqueue" , "shm" , "proc" , "sysfs" :
632
+ case "cgroup" , "devpts" , "mqueue" , "shm" , "proc" , "sysfs" , "cgroup2" :
622
633
reject = true
623
634
}
624
635
if reject {
0 commit comments