mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Add flag value validation of TopologyManagerScope
Signed-off-by: Krzysztof Wiatrzyk <k.wiatrzyk@samsung.com>
This commit is contained in:
parent
d070bff273
commit
a05eead211
@ -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))
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: topologyManager %v requires feature gate TopologyManager", kc.TopologyManagerPolicy))
|
||||||
}
|
}
|
||||||
if kc.TopologyManagerScope != kubeletconfig.ContainerTopologyManagerScope && !localFeatureGate.Enabled(features.TopologyManager) {
|
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 {
|
for _, val := range kc.EnforceNodeAllocatable {
|
||||||
switch val {
|
switch val {
|
||||||
case kubetypes.NodeAllocatableEnforcementKey:
|
case kubetypes.NodeAllocatableEnforcementKey:
|
||||||
|
@ -53,6 +53,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
HairpinMode: kubeletconfig.PromiscuousBridge,
|
HairpinMode: kubeletconfig.PromiscuousBridge,
|
||||||
NodeLeaseDurationSeconds: 1,
|
NodeLeaseDurationSeconds: 1,
|
||||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 25 * time.Millisecond},
|
CPUCFSQuotaPeriod: metav1.Duration{Duration: 25 * time.Millisecond},
|
||||||
|
TopologyManagerScope: kubeletconfig.PodTopologyManagerScope,
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
},
|
},
|
||||||
@ -89,6 +90,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
NodeLeaseDurationSeconds: 1,
|
NodeLeaseDurationSeconds: 1,
|
||||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond},
|
CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond},
|
||||||
ReservedSystemCPUs: "0-3",
|
ReservedSystemCPUs: "0-3",
|
||||||
|
TopologyManagerScope: kubeletconfig.ContainerTopologyManagerScope,
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
},
|
},
|
||||||
@ -123,7 +125,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
NodeLeaseDurationSeconds: -1,
|
NodeLeaseDurationSeconds: -1,
|
||||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
|
CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
|
||||||
}
|
}
|
||||||
const numErrsErrorCase1 = 25
|
const numErrsErrorCase1 = 26
|
||||||
if allErrors := ValidateKubeletConfiguration(errorCase1); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase1 {
|
if allErrors := ValidateKubeletConfiguration(errorCase1); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase1 {
|
||||||
t.Errorf("expect %d errors, got %v", numErrsErrorCase1, len(allErrors.(utilerrors.Aggregate).Errors()))
|
t.Errorf("expect %d errors, got %v", numErrsErrorCase1, len(allErrors.(utilerrors.Aggregate).Errors()))
|
||||||
}
|
}
|
||||||
@ -156,11 +158,12 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
NodeLeaseDurationSeconds: 1,
|
NodeLeaseDurationSeconds: 1,
|
||||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond},
|
CPUCFSQuotaPeriod: metav1.Duration{Duration: 50 * time.Millisecond},
|
||||||
ReservedSystemCPUs: "0-3",
|
ReservedSystemCPUs: "0-3",
|
||||||
|
TopologyManagerScope: "invalid",
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const numErrsErrorCase2 = 1
|
const numErrsErrorCase2 = 2
|
||||||
if allErrors := ValidateKubeletConfiguration(errorCase2); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase2 {
|
if allErrors := ValidateKubeletConfiguration(errorCase2); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase2 {
|
||||||
t.Errorf("expect %d errors, got %v", numErrsErrorCase2, len(allErrors.(utilerrors.Aggregate).Errors()))
|
t.Errorf("expect %d errors, got %v", numErrsErrorCase2, len(allErrors.(utilerrors.Aggregate).Errors()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user