From a05eead21121c9dcc4d48779ba42304f0912410c Mon Sep 17 00:00:00 2001 From: Krzysztof Wiatrzyk Date: Wed, 4 Nov 2020 11:44:47 +0100 Subject: [PATCH] Add flag value validation of TopologyManagerScope Signed-off-by: Krzysztof Wiatrzyk --- pkg/kubelet/apis/config/validation/validation.go | 6 +++++- pkg/kubelet/apis/config/validation/validation_test.go | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index 50c46334e08..fb3dac311bc 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -126,8 +126,12 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error allErrors = append(allErrors, fmt.Errorf("invalid configuration: topologyManager %v requires feature gate TopologyManager", kc.TopologyManagerPolicy)) } if kc.TopologyManagerScope != kubeletconfig.ContainerTopologyManagerScope && !localFeatureGate.Enabled(features.TopologyManager) { - allErrors = append(allErrors, fmt.Errorf("invalid configuration: TopologyManagerScope %v requires feature gate TopologyManager", kc.TopologyManagerScope)) + allErrors = append(allErrors, fmt.Errorf("invalid configuration: topologyManagerScope %v requires feature gate TopologyManager", kc.TopologyManagerScope)) } + if kc.TopologyManagerScope != kubeletconfig.ContainerTopologyManagerScope && kc.TopologyManagerScope != kubeletconfig.PodTopologyManagerScope { + allErrors = append(allErrors, fmt.Errorf("invalid configuration: topologyManagerScope non-allowable value: %v", kc.TopologyManagerScope)) + } + for _, val := range kc.EnforceNodeAllocatable { switch val { case kubetypes.NodeAllocatableEnforcementKey: diff --git a/pkg/kubelet/apis/config/validation/validation_test.go b/pkg/kubelet/apis/config/validation/validation_test.go index 31ab03b7015..851fec3941a 100644 --- a/pkg/kubelet/apis/config/validation/validation_test.go +++ b/pkg/kubelet/apis/config/validation/validation_test.go @@ -53,6 +53,7 @@ func TestValidateKubeletConfiguration(t *testing.T) { HairpinMode: kubeletconfig.PromiscuousBridge, NodeLeaseDurationSeconds: 1, CPUCFSQuotaPeriod: metav1.Duration{Duration: 25 * time.Millisecond}, + TopologyManagerScope: kubeletconfig.PodTopologyManagerScope, FeatureGates: map[string]bool{ "CustomCPUCFSQuotaPeriod": true, }, @@ -89,6 +90,7 @@ func TestValidateKubeletConfiguration(t *testing.T) { NodeLeaseDurationSeconds: 1, CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond}, ReservedSystemCPUs: "0-3", + TopologyManagerScope: kubeletconfig.ContainerTopologyManagerScope, FeatureGates: map[string]bool{ "CustomCPUCFSQuotaPeriod": true, }, @@ -123,7 +125,7 @@ func TestValidateKubeletConfiguration(t *testing.T) { NodeLeaseDurationSeconds: -1, CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond}, } - const numErrsErrorCase1 = 25 + const numErrsErrorCase1 = 26 if allErrors := ValidateKubeletConfiguration(errorCase1); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase1 { t.Errorf("expect %d errors, got %v", numErrsErrorCase1, len(allErrors.(utilerrors.Aggregate).Errors())) } @@ -156,11 +158,12 @@ func TestValidateKubeletConfiguration(t *testing.T) { NodeLeaseDurationSeconds: 1, CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond}, ReservedSystemCPUs: "0-3", + TopologyManagerScope: "invalid", FeatureGates: map[string]bool{ "CustomCPUCFSQuotaPeriod": true, }, } - const numErrsErrorCase2 = 1 + const numErrsErrorCase2 = 2 if allErrors := ValidateKubeletConfiguration(errorCase2); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase2 { t.Errorf("expect %d errors, got %v", numErrsErrorCase2, len(allErrors.(utilerrors.Aggregate).Errors())) }