drivers/docker: fix a hostConfigMemorySwappiness panic (#18238)

cgroupslib.MaybeDisableMemorySwappiness returned an incorrect type, and was
incorrectly typecast to int64 causing a panic on non-linux and non-windows hosts.
This commit is contained in:
Piotr Kazmierczak
2023-08-17 14:45:31 +02:00
committed by GitHub
parent e21ab7d948
commit 53ef6391a5
2 changed files with 7 additions and 3 deletions

View File

@@ -11,6 +11,6 @@ func LinuxResourcesPath(string, string) string {
}
// MaybeDisableMemorySwappiness does nothing on non-Linux systems
func MaybeDisableMemorySwappiness() *int {
func MaybeDisableMemorySwappiness() *uint64 {
return nil
}

View File

@@ -33,6 +33,7 @@ import (
"github.com/hashicorp/nomad/drivers/shared/hostnames"
"github.com/hashicorp/nomad/drivers/shared/resolvconf"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/pointer"
nstructs "github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
@@ -1035,8 +1036,11 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
hostConfig.MemorySwap = memory
// disable swap explicitly in non-Windows environments
swappiness := int64(*(cgroupslib.MaybeDisableMemorySwappiness()))
hostConfig.MemorySwappiness = &swappiness
if cgroupslib.MaybeDisableMemorySwappiness() != nil {
hostConfig.MemorySwappiness = pointer.Of(int64(*(cgroupslib.MaybeDisableMemorySwappiness())))
} else {
hostConfig.MemorySwappiness = nil
}
}
loggingDriver := driverConfig.Logging.Type