Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hepto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ACIDES
Hepto
Commits
64c3e35c
Commit
64c3e35c
authored
2 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Move cgroup evacuation to util functions
parent
6d3dcf79
No related branches found
No related tags found
No related merge requests found
Pipeline
#21746
passed
2 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/selfcontain/init.go
+2
-15
2 additions, 15 deletions
pkg/selfcontain/init.go
pkg/selfcontain/utils.go
+19
-0
19 additions, 0 deletions
pkg/selfcontain/utils.go
with
21 additions
and
15 deletions
pkg/selfcontain/init.go
+
2
−
15
View file @
64c3e35c
...
...
@@ -25,24 +25,11 @@ func init() {
// Do not start the full featured runtime
runtime
.
GOMAXPROCS
(
1
)
runtime
.
LockOSThread
()
// Evacuate cgroups, which is required for many in-container cgroup
// use cases, since we are now at the root cgroup
// Libcontainer cgroup manager is not designed for evacuation and will
// fail in such a case, so we are using cgroupfs directly, which is
// explicitely available due to defaults, and simple since we are
// the only running process at the moment
err
:=
os
.
Mkdir
(
"/sys/fs/cgroup/selfcontain"
,
0
o755
)
if
err
!=
nil
{
logrus
.
Fatal
(
"could not create evacuation cgroup: "
,
err
)
}
err
=
os
.
WriteFile
(
"/sys/fs/cgroup/selfcon/cgroup.procs"
,
[]
byte
(
"0"
),
0
o755
)
if
err
!=
nil
{
logrus
.
Fatal
(
"could not evacuate self: "
,
err
)
}
// Run libcontainer initialization, which will fork/exec to the
// provided process executable, a.k.a ourselves
logrus
.
Debug
(
"initializing self-contained app"
)
factory
,
_
:=
libcontainer
.
New
(
""
)
err
=
factory
.
StartInitialization
()
err
:
=
factory
.
StartInitialization
()
if
err
!=
nil
{
logrus
.
Fatal
(
"could not run self-contained app: "
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/selfcontain/utils.go
+
19
−
0
View file @
64c3e35c
...
...
@@ -16,6 +16,7 @@ func RunFun(config *Config, f runnable) error {
for
_
,
arg
:=
range
os
.
Args
{
if
arg
==
argRunFun
{
logrus
.
Debug
(
"we are running inside the container..."
)
Evacuate
()
f
()
return
nil
}
...
...
@@ -44,3 +45,21 @@ func RunFun(config *Config, f runnable) error {
}()
return
c
.
Run
()
}
// Evacuate cgroups, which is required for many in-container use cases
// Remaining in the root cgroup would prevent creating any domain sub-cgroup
func
Evacuate
()
{
// Libcontainer cgroup manager is not designed for evacuation and will
// fail in such a case, so we are using cgroupfs directly, which is
// explicitely available due to defaults, and simple since we are
// the only running process at the moment
logrus
.
Debug
(
"evacuating self to /selfcontain"
)
err
:=
os
.
Mkdir
(
"/sys/fs/cgroup/selfcontain"
,
0
o755
)
if
err
!=
nil
&&
!
os
.
IsExist
(
err
)
{
logrus
.
Fatal
(
"could not create evacuation cgroup: "
,
err
)
}
err
=
os
.
WriteFile
(
"/sys/fs/cgroup/selfcontain/cgroup.procs"
,
[]
byte
(
"0"
),
0
o755
)
if
err
!=
nil
{
logrus
.
Fatal
(
"could not evacuate self: "
,
err
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment