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

Commit

Permalink
config: honour VM config resources
Browse files Browse the repository at this point in the history
VM config resources must be honoured in order to create
the pod config with the right number of vCPUs and Memory,
whithout this patch vCPU and Memory will be always 0.

fixes #925

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Jan 16, 2018
1 parent 34d9f2c commit 40df053
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
return fmt.Errorf("%v: %v", configPath, err)
}

config.VMConfig.VCPUs = uint(hConfig.DefaultVCPUs)
config.VMConfig.Memory = uint(hConfig.DefaultMemSz)

config.HypervisorConfig = hConfig
}
}
Expand Down
36 changes: 36 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf

ShimType: defaultShim,
ShimConfig: shimConfig,

VMConfig: vc.Resources{
VCPUs: uint(defaultVCPUCount),
Memory: uint(defaultMemSize),
},
}

config = testRuntimeConfig{
Expand Down Expand Up @@ -1008,3 +1013,34 @@ func TestUpdateRuntimeConfiguration(t *testing.T) {
assert.Equal(config.AgentType, vc.AgentType(kataAgentTableType))
assert.Equal(config.AgentConfig, vc.KataAgentConfig{})
}

func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
assert := assert.New(t)

vcpus := uint(8)
mem := uint(2048)

config := oci.RuntimeConfig{}
expectedVMConfig := vc.Resources{
VCPUs: vcpus,
Memory: mem,
}

tomlConf := tomlConfig{
Hypervisor: map[string]hypervisor{
qemuHypervisorTableType: {
DefaultVCPUs: int32(vcpus),
DefaultMemSz: uint32(mem),
Path: "/",
Kernel: "/",
Image: "/",
Firmware: "/",
},
},
}

err := updateRuntimeConfig("", tomlConf, &config)
assert.NoError(err)

assert.Equal(expectedVMConfig, config.VMConfig)
}

0 comments on commit 40df053

Please sign in to comment.