Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"

Expand Down Expand Up @@ -320,6 +322,35 @@ func validateROPaths(spec *rspec.Spec) error {
return nil
}

func validateOOMScoreAdj(spec *rspec.Spec) error {
logrus.Debugf("validating oomScoreAdj")
if spec.Linux.Resources != nil && spec.Linux.Resources.OOMScoreAdj != nil {
expected := *spec.Linux.Resources.OOMScoreAdj
f, err := os.Open("/proc/1/oom_score_adj")
if err != nil {
return err
}
defer f.Close()

s := bufio.NewScanner(f)
for s.Scan() {
if err := s.Err(); err != nil {
return err
}
text := strings.TrimSpace(s.Text())
actual, err := strconv.Atoi(text)
if err != nil {
return err
}
if actual != expected {
return fmt.Errorf("oomScoreAdj expected: %v, actual: %v", expected, actual)
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if oomScoreAdj is null or unset? Do we require particular runtime behavior in that case? I'd expect we require the runtime to leave the setting alone, although the current spec doesn't spell that out.


return nil
}

func mountMatch(specMount rspec.Mount, sysMount rspec.Mount) error {
if specMount.Destination != sysMount.Destination {
return fmt.Errorf("mount destination expected: %v, actual: %v", specMount.Destination, sysMount.Destination)
Expand Down Expand Up @@ -398,6 +429,7 @@ func validate(context *cli.Context) error {
validateSysctls,
validateMaskedPaths,
validateROPaths,
validateOOMScoreAdj,
}

for _, v := range defaultValidations {
Expand Down