Merge pull request #544 from mythi/PR-2021-003

sgx: change getDefaultPodCount() logic
This commit is contained in:
Dmitry Rozhkov 2021-01-13 10:31:16 +02:00 committed by GitHub
commit 771b0c7432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -34,7 +34,7 @@ const (
deviceTypeProvision = "provision" deviceTypeProvision = "provision"
devicePath = "/dev" devicePath = "/dev"
podsPerCoreEnvVariable = "PODS_PER_CORE" podsPerCoreEnvVariable = "PODS_PER_CORE"
defaultPodsPerCore uint = 10 defaultPodCount uint = 110
) )
type devicePlugin struct { type devicePlugin struct {
@ -107,29 +107,27 @@ func getDefaultPodCount(nCPUs uint) uint {
// limit by multiplying the number of cores in the system with env variable // limit by multiplying the number of cores in the system with env variable
// "PODS_PER_CORE". // "PODS_PER_CORE".
podsPerCore := defaultPodsPerCore
envPodsPerCore := os.Getenv(podsPerCoreEnvVariable) envPodsPerCore := os.Getenv(podsPerCoreEnvVariable)
if envPodsPerCore != "" { if envPodsPerCore != "" {
tmp, err := strconv.ParseUint(envPodsPerCore, 10, 32) tmp, err := strconv.ParseUint(envPodsPerCore, 10, 32)
if err != nil { if err != nil {
klog.Errorf("Error: failed to parse %s value as uint, using default value.", podsPerCoreEnvVariable) klog.Errorf("Error: failed to parse %s value as uint, using default value.", podsPerCoreEnvVariable)
} else { } else {
podsPerCore = uint(tmp) return uint(tmp) * nCPUs
} }
} }
return podsPerCore * nCPUs return defaultPodCount
} }
func main() { func main() {
var enclaveLimit uint var enclaveLimit uint
var provisionLimit uint var provisionLimit uint
defaultPodCount := getDefaultPodCount(uint(runtime.NumCPU())) podCount := getDefaultPodCount(uint(runtime.NumCPU()))
flag.UintVar(&enclaveLimit, "enclave-limit", defaultPodCount, "Number of \"enclave\" resources") flag.UintVar(&enclaveLimit, "enclave-limit", podCount, "Number of \"enclave\" resources")
flag.UintVar(&provisionLimit, "provision-limit", defaultPodCount, "Number of \"provision\" resources") flag.UintVar(&provisionLimit, "provision-limit", podCount, "Number of \"provision\" resources")
flag.Parse() flag.Parse()
klog.V(4).Infof("SGX device plugin started with %d \"%s/enclave\" resources and %d \"%s/provision\" resources.", enclaveLimit, namespace, provisionLimit, namespace) klog.V(4).Infof("SGX device plugin started with %d \"%s/enclave\" resources and %d \"%s/provision\" resources.", enclaveLimit, namespace, provisionLimit, namespace)

View File

@ -50,16 +50,15 @@ func TestPodCount(t *testing.T) {
expectedPodCount uint expectedPodCount uint
}{ }{
{ {
name: "Only CPU count", name: "Default pod count",
envValue: "", envValue: "",
nCPUs: 5, expectedPodCount: defaultPodCount,
expectedPodCount: defaultPodsPerCore * 5,
}, },
{ {
name: "Broken ENV", name: "Broken ENV",
envValue: "foobar", envValue: "foobar",
nCPUs: 5, nCPUs: 5,
expectedPodCount: defaultPodsPerCore * 5, expectedPodCount: defaultPodCount,
}, },
{ {
name: "Valid ENV", name: "Valid ENV",