Skip to content

Commit ebda26c

Browse files
author
Mrunal Patel
authored
Merge pull request #195 from Mashimiao/add-linux-resources-validation
validation: add linux resource check
2 parents 6aeb752 + 9cad4d8 commit ebda26c

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)