add unit tests
parent
b116cd15bb
commit
de5e493b10
|
@ -715,7 +715,7 @@ func memoryLimits(drvName string) (int, int, error) {
|
|||
}
|
||||
|
||||
// suggestMemoryAllocation calculates the default memory footprint in MB
|
||||
func suggestMemoryAllocation(sysLimit int, containerLimit int) int {
|
||||
func suggestMemoryAllocation(sysLimit int, containerLimit int, nodes int) int {
|
||||
if mem := viper.GetInt(memory); mem != 0 {
|
||||
return mem
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ func suggestMemoryAllocation(sysLimit int, containerLimit int) int {
|
|||
// Suggest 25% of RAM, rounded to nearest 100MB. Hyper-V requires an even number!
|
||||
suggested := int(float32(sysLimit)/400.0) * 100
|
||||
|
||||
if nodes := viper.GetInt(nodes); nodes > 1 {
|
||||
if nodes > 1 {
|
||||
suggested /= nodes
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
|
|||
glog.Warningf("Unable to query memory limits: %v", err)
|
||||
}
|
||||
|
||||
mem := suggestMemoryAllocation(sysLimit, containerLimit)
|
||||
mem := suggestMemoryAllocation(sysLimit, containerLimit, viper.GetInt(nodes))
|
||||
if cmd.Flags().Changed(memory) {
|
||||
mem, err = pkgutil.CalculateSizeInMB(viper.GetString(memory))
|
||||
if err != nil {
|
||||
|
|
|
@ -185,25 +185,34 @@ func TestSuggestMemoryAllocation(t *testing.T) {
|
|||
description string
|
||||
sysLimit int
|
||||
containerLimit int
|
||||
nodes int
|
||||
want int
|
||||
}{
|
||||
{"128GB sys", 128000, 0, 6000},
|
||||
{"64GB sys", 64000, 0, 6000},
|
||||
{"16GB sys", 16384, 0, 4000},
|
||||
{"odd sys", 14567, 0, 3600},
|
||||
{"4GB sys", 4096, 0, 2200},
|
||||
{"2GB sys", 2048, 0, 2048},
|
||||
{"Unable to poll sys", 0, 0, 2200},
|
||||
{"128GB sys, 16GB container", 128000, 16384, 16336},
|
||||
{"64GB sys, 16GB container", 64000, 16384, 16000},
|
||||
{"16GB sys, 4GB container", 16384, 4096, 4000},
|
||||
{"4GB sys, 3.5GB container", 16384, 3500, 3452},
|
||||
{"2GB sys, 2GB container", 16384, 2048, 2048},
|
||||
{"2GB sys, unable to poll container", 16384, 0, 4000},
|
||||
{"128GB sys", 128000, 0, 1, 6000},
|
||||
{"64GB sys", 64000, 0, 1, 6000},
|
||||
{"32GB sys", 32768, 0, 1, 6000},
|
||||
{"16GB sys", 16384, 0, 1, 4000},
|
||||
{"odd sys", 14567, 0, 1, 3600},
|
||||
{"4GB sys", 4096, 0, 1, 2200},
|
||||
{"2GB sys", 2048, 0, 1, 2048},
|
||||
{"Unable to poll sys", 0, 0, 1, 2200},
|
||||
{"128GB sys, 16GB container", 128000, 16384, 1, 16336},
|
||||
{"64GB sys, 16GB container", 64000, 16384, 1, 16000},
|
||||
{"16GB sys, 4GB container", 16384, 4096, 1, 4000},
|
||||
{"4GB sys, 3.5GB container", 16384, 3500, 1, 3452},
|
||||
{"16GB sys, 2GB container", 16384, 2048, 1, 2048},
|
||||
{"16GB sys, unable to poll container", 16384, 0, 1, 4000},
|
||||
{"128GB sys 2 nodes", 128000, 0, 2, 6000},
|
||||
{"8GB sys 3 nodes", 8192, 0, 3, 2200},
|
||||
{"16GB sys 2 nodes", 16384, 0, 2, 2200},
|
||||
{"32GB sys 2 nodes", 32768, 0, 2, 4050},
|
||||
{"odd sys 2 nodes", 14567, 0, 2, 2200},
|
||||
{"4GB sys 2 nodes", 4096, 0, 2, 2200},
|
||||
{"2GB sys 3 nodes", 2048, 0, 3, 2048},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
got := suggestMemoryAllocation(test.sysLimit, test.containerLimit)
|
||||
got := suggestMemoryAllocation(test.sysLimit, test.containerLimit, test.nodes)
|
||||
if got != test.want {
|
||||
t.Errorf("defaultMemorySize(sys=%d, container=%d) = %d, want: %d", test.sysLimit, test.containerLimit, got, test.want)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue