Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
goruntime "runtime"
Expand Down Expand Up @@ -376,3 +377,31 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat

return resolved, logfilePath, config, nil
}

func ociResourceUpdateRuntimeConfig(ocispec oci.CompatOCISpec, config *oci.RuntimeConfig) error {
if ocispec.Linux == nil {
return nil
}

if ocispec.Linux.Resources == nil {
return nil
}

if ocispec.Linux.Resources.Memory == nil {
return nil
}

if ocispec.Linux.Resources.Memory.Limit == nil {
return nil
}

memBytes := *ocispec.Linux.Resources.Memory.Limit

mem := int(math.Ceil(float64(memBytes) / 1024 / 1024))
if mem <= 0 {
return fmt.Errorf("Invalid OCI memory limit %d", memBytes)
}
config.VMConfig.Memory = uint(mem)

return nil
}
4 changes: 4 additions & 0 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
return err
}

if err := ociResourceUpdateRuntimeConfig(ociSpec, &runtimeConfig); err != nil {
return err
}

containerType, err := ociSpec.ContainerType()
if err != nil {
return err
Expand Down