Skip to content

Commit f4bba5a

Browse files
Ma Shimiaowking
authored andcommitted
validation: add linux resource check
Signed-off-by: Ma Shimiao <[email protected]> Backported to v1.0.0.rc1 from 9cad4d8 #195 (cherry-pick applied cleanly). Signed-off-by: W. Trevor King <[email protected]>
1 parent ea1d5dd commit f4bba5a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/ocitools/validate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
361361
}
362362
}
363363

364+
if spec.Linux.Resources != nil {
365+
ms := checkLinuxResources(*spec.Linux.Resources, hostCheck)
366+
msgs = append(msgs, ms...)
367+
}
368+
364369
if spec.Linux.Seccomp != nil {
365370
ms := checkSeccomp(*spec.Linux.Seccomp)
366371
msgs = append(msgs, ms...)
@@ -381,6 +386,21 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
381386
return
382387
}
383388

389+
func checkLinuxResources(r rspec.Resources, hostCheck bool) (msgs []string) {
390+
logrus.Debugf("check linux resources")
391+
392+
if r.Memory != nil {
393+
if r.Memory.Limit != nil && r.Memory.Swap != nil && uint64(*r.Memory.Limit) > uint64(*r.Memory.Swap) {
394+
msgs = append(msgs, fmt.Sprintf("Minimum memoryswap should be larger than memory limit"))
395+
}
396+
if r.Memory.Limit != nil && r.Memory.Reservation != nil && uint64(*r.Memory.Reservation) > uint64(*r.Memory.Limit) {
397+
msgs = append(msgs, fmt.Sprintf("Minimum memory limit should be larger than memory reservation"))
398+
}
399+
}
400+
401+
return
402+
}
403+
384404
func checkSeccomp(s rspec.Seccomp) (msgs []string) {
385405
logrus.Debugf("check seccomp")
386406

0 commit comments

Comments
 (0)