Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
config: Add default_{vcpus, memory} configurations
Browse files Browse the repository at this point in the history
Introduce two new configuration settings:
 * default_vcpus - defines default vCPU number for new created PODs
 * default_memory - defines default memory size for new created PODs

 Fixes #164.

Signed-off-by: Dmitry Voytik <[email protected]>
  • Loading branch information
Dmitry Voytik committed Jul 4, 2017
1 parent 5c5a5b5 commit 5d17888
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ const defaultRuntimeRun = "$(PKGRUNDIR)"
const defaultShimPath = "$(SHIMPATH)"
const pauseBinRelativePath = "$(PAUSEBINRELPATH)"

const defaultDefaultVCPUs uint32 = 1
const defaultDefaultMemSz uint32 = 256

// Required to be modifiable (for the tests)
var defaultRuntimeConfiguration = "$(DESTCONFIG)"
var defaultProxyPath = "$(PROXYPATH)"
Expand Down
28 changes: 25 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ type tomlConfig struct {
}

type hypervisor struct {
Path string
Kernel string
Image string
Path string
Kernel string
Image string
DefaultVCPUs uint32 `toml:"default_vcpus"`
DefaultMemSz uint32 `toml:"default_memory"`
}

type proxy struct {
Expand Down Expand Up @@ -118,6 +120,22 @@ func (h hypervisor) image() string {
return h.Image
}

func (h hypervisor) defaultVCPUs() uint32 {
if h.DefaultVCPUs == 0 {
return defaultDefaultVCPUs
}

return h.DefaultVCPUs
}

func (h hypervisor) defaultMemSz() uint32 {
if h.DefaultMemSz < 8 {
return defaultDefaultMemSz // MiB
}

return h.DefaultMemSz
}

func (p proxy) url() string {
if p.URL == "" {
return defaultProxyURL
Expand Down Expand Up @@ -158,6 +176,8 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
HypervisorPath: hypervisor,
KernelPath: kernel,
ImagePath: image,
DefaultVCPUs: h.defaultVCPUs(),
DefaultMemSz: h.defaultMemSz(),
}, nil
}

Expand Down Expand Up @@ -264,6 +284,8 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
ImagePath: defaultImagePath,
DefaultVCPUs: defaultDefaultVCPUs,
DefaultMemSz: defaultDefaultMemSz,
}

defaultAgentConfig := vc.HyperConfig{
Expand Down
5 changes: 5 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
path = "@QEMUPATH@"
kernel = "@KERNELPATH@"
image = "@IMAGEPATH@"
# Default vCPU number per POD/VM. If unspecified then it will be set to 1.
#default_vcpus = 1
# Default memory size in MiB for POD/VM. If unspecified then it will be set
# to 256 MiB.
#default_memory = 256

[proxy.cc]
url = "@PROXYURL@"
Expand Down
17 changes: 17 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path"
"path/filepath"
"reflect"
"strconv"
"strings"
"syscall"
"testing"
Expand Down Expand Up @@ -49,6 +50,8 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
path = "` + hypervisorPath + `"
kernel = "` + kernelPath + `"
image = "` + imagePath + `"
default_vcpus = ` + strconv.FormatUint(uint64(defaultDefaultVCPUs), 10) + `
default_memory = ` + strconv.FormatUint(uint64(defaultDefaultMemSz), 10) + `
[proxy.cc]
url = "` + proxyURL + `"
Expand Down Expand Up @@ -131,6 +134,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
HypervisorPath: hypervisorPath,
KernelPath: kernelPath,
ImagePath: imagePath,
DefaultVCPUs: defaultDefaultVCPUs,
DefaultMemSz: defaultDefaultMemSz,
}

agentConfig := vc.HyperConfig{
Expand Down Expand Up @@ -586,6 +591,8 @@ func TestMinimalRuntimeConfig(t *testing.T) {
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
ImagePath: defaultImagePath,
DefaultVCPUs: defaultDefaultVCPUs,
DefaultMemSz: defaultDefaultMemSz,
}

expectedAgentConfig := vc.HyperConfig{
Expand Down Expand Up @@ -770,6 +777,8 @@ func TestHypervisorDefaults(t *testing.T) {
assert.Equal(t, h.path(), defaultHypervisorPath, "default hypervisor path wrong")
assert.Equal(t, h.kernel(), defaultKernelPath, "default hypervisor kernel wrong")
assert.Equal(t, h.image(), defaultImagePath, "default hypervisor image wrong")
assert.Equal(t, h.defaultVCPUs(), defaultDefaultVCPUs, "default vCPU number is wrong")
assert.Equal(t, h.defaultMemSz(), defaultDefaultMemSz, "default memory size is wrong")

path := "/foo"
h.Path = path
Expand All @@ -782,6 +791,14 @@ func TestHypervisorDefaults(t *testing.T) {
image := "foo"
h.Image = image
assert.Equal(t, h.image(), image, "custom hypervisor image wrong")

const vcpus uint32 = 2
h.DefaultVCPUs = vcpus
assert.Equal(t, h.defaultVCPUs(), vcpus, "default vCPU number is wrong")

const memSz uint32 = 1024
h.DefaultMemSz = memSz
assert.Equal(t, h.defaultMemSz(), memSz, "default memory size is wrong")
}

func TestProxyDefaults(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions vendor/github.com/containers/virtcontainers/hypervisor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions vendor/github.com/containers/virtcontainers/qemu.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d17888

Please sign in to comment.