From ed3a650ddd6becb2e222435c6e7efb373c657536 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Tue, 12 Jan 2021 18:27:55 +0200 Subject: [PATCH] sgx: change getDefaultPodCount() logic Decouple the default enclaveLimit/provisionLimit from core count. With this change, the default limit is constant and it can be made relative to core count by setting PODS_PER_CORE multiplier via env variable. Signed-off-by: Mikko Ylinen --- cmd/sgx_plugin/sgx_plugin.go | 14 ++++++-------- cmd/sgx_plugin/sgx_plugin_test.go | 7 +++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cmd/sgx_plugin/sgx_plugin.go b/cmd/sgx_plugin/sgx_plugin.go index 2c3b6249..11bdb33b 100644 --- a/cmd/sgx_plugin/sgx_plugin.go +++ b/cmd/sgx_plugin/sgx_plugin.go @@ -34,7 +34,7 @@ const ( deviceTypeProvision = "provision" devicePath = "/dev" podsPerCoreEnvVariable = "PODS_PER_CORE" - defaultPodsPerCore uint = 10 + defaultPodCount uint = 110 ) 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 // "PODS_PER_CORE". - podsPerCore := defaultPodsPerCore - envPodsPerCore := os.Getenv(podsPerCoreEnvVariable) if envPodsPerCore != "" { tmp, err := strconv.ParseUint(envPodsPerCore, 10, 32) if err != nil { klog.Errorf("Error: failed to parse %s value as uint, using default value.", podsPerCoreEnvVariable) } else { - podsPerCore = uint(tmp) + return uint(tmp) * nCPUs } } - return podsPerCore * nCPUs + return defaultPodCount } func main() { var enclaveLimit 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(&provisionLimit, "provision-limit", defaultPodCount, "Number of \"provision\" resources") + flag.UintVar(&enclaveLimit, "enclave-limit", podCount, "Number of \"enclave\" resources") + flag.UintVar(&provisionLimit, "provision-limit", podCount, "Number of \"provision\" resources") flag.Parse() klog.V(4).Infof("SGX device plugin started with %d \"%s/enclave\" resources and %d \"%s/provision\" resources.", enclaveLimit, namespace, provisionLimit, namespace) diff --git a/cmd/sgx_plugin/sgx_plugin_test.go b/cmd/sgx_plugin/sgx_plugin_test.go index 894ff883..60ed1ca1 100644 --- a/cmd/sgx_plugin/sgx_plugin_test.go +++ b/cmd/sgx_plugin/sgx_plugin_test.go @@ -50,16 +50,15 @@ func TestPodCount(t *testing.T) { expectedPodCount uint }{ { - name: "Only CPU count", + name: "Default pod count", envValue: "", - nCPUs: 5, - expectedPodCount: defaultPodsPerCore * 5, + expectedPodCount: defaultPodCount, }, { name: "Broken ENV", envValue: "foobar", nCPUs: 5, - expectedPodCount: defaultPodsPerCore * 5, + expectedPodCount: defaultPodCount, }, { name: "Valid ENV",