Skip to content

Commit 8d58b89

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 <[email protected]>
1 parent 03b80d0 commit 8d58b89

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
@@ -373,3 +373,4 @@ Imgs
373373
nosec
374374
derr
375375
ldconfig
376+
Rlimits

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
@@ -278,6 +278,16 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
278278
GID: u.Spec.Process.User.GID,
279279
WorkDir: u.Spec.Process.Cwd,
280280
}
281+
282+
if u.Spec.Process.Rlimits != nil {
283+
for _, rl := range u.Spec.Process.Rlimits {
284+
procAttrs.Rlimits = append(procAttrs.Rlimits, types.Rlimit{
285+
Type: rl.Type,
286+
Hard: rl.Hard,
287+
Soft: rl.Soft,
288+
})
289+
}
290+
}
281291
// UnikernelParams
282292
// populate unikernel params
283293
unikernelParams := types.UnikernelParams{

0 commit comments

Comments
 (0)