From 6f9dfcc103cc7ead39e2303beee6c720c8199d45 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Sun, 13 Feb 2022 11:13:56 +0100 Subject: [PATCH] validate: check for reserved resources Add validation check to verify _some_ resources are reserved. We don't want yet to validate the amount of resources nor their NUMA topology. so we just check _something_ has been reserved. Signed-off-by: Francesco Romani --- pkg/validator/kubeletconfig.go | 21 ++++++++++ pkg/validator/kubeletconfig_test.go | 65 +++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/pkg/validator/kubeletconfig.go b/pkg/validator/kubeletconfig.go index b5edc3a4..a7a64b88 100644 --- a/pkg/validator/kubeletconfig.go +++ b/pkg/validator/kubeletconfig.go @@ -158,6 +158,16 @@ func ValidateClusterNodeKubeletConfig(nodeName string, nodeVersion *version.Info Detected: fmt.Sprintf("%v", kubeletConf.CPUManagerReconcilePeriod.Duration), }) } + if kubeletConf.ReservedSystemCPUs == "" { + vrs = append(vrs, ValidationResult{ + Node: nodeName, + Area: AreaKubelet, + Component: ComponentConfiguration, + Setting: "CPU", + Expected: "reserved some CPU cores", + Detected: "no reserved CPU cores", + }) + } if kubeletConf.MemoryManagerPolicy != ExpectedMemoryManagerPolicy { vrs = append(vrs, ValidationResult{ @@ -170,6 +180,17 @@ func ValidateClusterNodeKubeletConfig(nodeName string, nodeVersion *version.Info }) } + if len(kubeletConf.ReservedMemory) == 0 { + vrs = append(vrs, ValidationResult{ + Node: nodeName, + Area: AreaKubelet, + Component: ComponentConfiguration, + Setting: "memory", + Expected: "reserved memory blocks", + Detected: "no reserved memory blocks", + }) + } + if kubeletConf.TopologyManagerPolicy != ExpectedTopologyManagerPolicy { vrs = append(vrs, ValidationResult{ Node: nodeName, diff --git a/pkg/validator/kubeletconfig_test.go b/pkg/validator/kubeletconfig_test.go index ade3df37..6eccf232 100644 --- a/pkg/validator/kubeletconfig_test.go +++ b/pkg/validator/kubeletconfig_test.go @@ -68,6 +68,24 @@ func TestKubeletValidations(t *testing.T) { Component: ComponentCPUManager, Setting: "reconcile period", }, + { + Node: nodeName, + Area: AreaKubelet, + Component: ComponentConfiguration, + Setting: "CPU", + }, + { + Node: nodeName, + Area: AreaKubelet, + Component: ComponentMemoryManager, + Setting: "policy", + }, + { + Node: nodeName, + Area: AreaKubelet, + Component: ComponentConfiguration, + Setting: "memory", + }, { Node: nodeName, Area: AreaKubelet, @@ -86,6 +104,13 @@ func TestKubeletValidations(t *testing.T) { CPUManagerReconcilePeriod: metav1.Duration{ Duration: 5 * time.Second, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, + ReservedSystemCPUs: "0,1", TopologyManagerPolicy: ExpectedTopologyManagerPolicy, }, expected: []ValidationResult{}, @@ -97,6 +122,13 @@ func TestKubeletValidations(t *testing.T) { CPUManagerReconcilePeriod: metav1.Duration{ Duration: 5 * time.Second, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, + ReservedSystemCPUs: "0,1", TopologyManagerPolicy: ExpectedTopologyManagerPolicy, }, expected: []ValidationResult{ @@ -117,6 +149,13 @@ func TestKubeletValidations(t *testing.T) { CPUManagerReconcilePeriod: metav1.Duration{ Duration: 5 * time.Second, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, + ReservedSystemCPUs: "0,1", }, expected: []ValidationResult{ { @@ -137,6 +176,13 @@ func TestKubeletValidations(t *testing.T) { CPUManagerReconcilePeriod: metav1.Duration{ Duration: 5 * time.Second, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, + ReservedSystemCPUs: "0,1", TopologyManagerPolicy: "restricted", }, expected: []ValidationResult{ @@ -154,6 +200,12 @@ func TestKubeletValidations(t *testing.T) { FeatureGates: map[string]bool{ ExpectedPodResourcesFeatureGate: true, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, TopologyManagerPolicy: ExpectedTopologyManagerPolicy, }, expected: []ValidationResult{ @@ -170,6 +222,12 @@ func TestKubeletValidations(t *testing.T) { Component: ComponentCPUManager, Setting: "reconcile period", }, + { + Node: nodeName, + Area: AreaKubelet, + Component: ComponentConfiguration, + Setting: "CPU", + }, }, }, { @@ -182,6 +240,13 @@ func TestKubeletValidations(t *testing.T) { CPUManagerReconcilePeriod: metav1.Duration{ Duration: 30 * time.Second, }, + MemoryManagerPolicy: ExpectedMemoryManagerPolicy, + ReservedMemory: []kubeletconfigv1beta1.MemoryReservation{ + { + NumaNode: 1, + }, + }, + ReservedSystemCPUs: "0,1", TopologyManagerPolicy: ExpectedTopologyManagerPolicy, }, expected: []ValidationResult{