Skip to content

Commit be0d065

Browse files
feat(config): pass rlimits to urunit via UCS
This extracts the rlimits from the OCI spec in the unikontainer logic and appends them to the UCS configuration block generated in linux.go. This allows the guest init process (urunit) to enforce resource limits. Signed-off-by: Sankalp <sankalp25103@gmail.com>
1 parent 6e5ea5e commit be0d065

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

.github/linters/urunc-dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ derr
375375
ldconfig
376376
vfsd
377377
crun
378+
Rlimits
378379
vaccel
379380
VACCEL
380381
vsock

pkg/unikontainers/types/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,18 @@ type RootfsParams struct {
6060
MonRootfs string // The rootfs for the monitor process
6161
}
6262

63+
type Rlimit struct {
64+
Type string
65+
Hard uint64
66+
Soft uint64
67+
}
68+
6369
// Specific to Linux
6470
type ProcessConfig struct {
6571
UID uint32 // The uid of the process inside the guest
6672
GID uint32 // The gid of the process inside the guest
6773
WorkDir string // The workdir of the process inside the guest
74+
Rlimits []Rlimit
6875
}
6976

7077
// UnikernelParams holds the data required to build the unikernels commandline

pkg/unikontainers/unikernels/linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ func (l *Linux) buildUrunitConfig() string {
314314
sb.WriteString("WD:")
315315
sb.WriteString(l.ProcConfig.WorkDir)
316316
sb.WriteString("\n")
317+
for _, limit := range l.ProcConfig.Rlimits {
318+
sb.WriteString("RLIMIT:")
319+
sb.WriteString(limit.Type)
320+
sb.WriteString(":")
321+
sb.WriteString(strconv.FormatUint(limit.Hard, 10))
322+
sb.WriteString(":")
323+
sb.WriteString(strconv.FormatUint(limit.Soft, 10))
324+
sb.WriteString("\n")
325+
}
317326
sb.WriteString(lpcEndMarker)
318327
sb.WriteString("\n")
319328
sb.WriteString(blkStartMarker)

pkg/unikontainers/unikontainers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
280280
GID: u.Spec.Process.User.GID,
281281
WorkDir: u.Spec.Process.Cwd,
282282
}
283+
284+
if u.Spec.Process.Rlimits != nil {
285+
for _, rl := range u.Spec.Process.Rlimits {
286+
procAttrs.Rlimits = append(procAttrs.Rlimits, types.Rlimit{
287+
Type: rl.Type,
288+
Hard: rl.Hard,
289+
Soft: rl.Soft,
290+
})
291+
}
292+
}
283293
// UnikernelParams
284294
// populate unikernel params
285295
unikernelParams := types.UnikernelParams{

0 commit comments

Comments
 (0)