mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 06:43:54 +00:00
Add validation for KubeletConfig MemorySwap
This commit is contained in:
parent
7d50271d21
commit
7342acb0b8
@ -155,6 +155,11 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error
|
|||||||
if (kc.ShutdownGracePeriod.Duration > 0 || kc.ShutdownGracePeriodCriticalPods.Duration > 0) && !localFeatureGate.Enabled(features.GracefulNodeShutdown) {
|
if (kc.ShutdownGracePeriod.Duration > 0 || kc.ShutdownGracePeriodCriticalPods.Duration > 0) && !localFeatureGate.Enabled(features.GracefulNodeShutdown) {
|
||||||
allErrors = append(allErrors, fmt.Errorf("invalid configuration: Specifying ShutdownGracePeriod or ShutdownGracePeriodCriticalPods requires feature gate GracefulNodeShutdown"))
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: Specifying ShutdownGracePeriod or ShutdownGracePeriodCriticalPods requires feature gate GracefulNodeShutdown"))
|
||||||
}
|
}
|
||||||
|
if localFeatureGate.Enabled(features.NodeSwapEnabled) {
|
||||||
|
if kc.MemorySwap.SwapBehavior != "" && kc.MemorySwap.SwapBehavior != "NoSwap" && kc.MemorySwap.SwapBehavior != "UnlimitedSwap" {
|
||||||
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: MemorySwap.SwapBehavior %v must be one of: NoSwap, UnlimitedSwap", kc.MemorySwap.SwapBehavior))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, val := range kc.EnforceNodeAllocatable {
|
for _, val := range kc.EnforceNodeAllocatable {
|
||||||
switch val {
|
switch val {
|
||||||
|
@ -145,9 +145,11 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
TopologyManagerPolicy: kubeletconfig.NoneTopologyManagerPolicy,
|
TopologyManagerPolicy: kubeletconfig.NoneTopologyManagerPolicy,
|
||||||
ShutdownGracePeriod: metav1.Duration{Duration: 10 * time.Minute},
|
ShutdownGracePeriod: metav1.Duration{Duration: 10 * time.Minute},
|
||||||
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 0},
|
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 0},
|
||||||
|
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: "UnlimitedSwap"},
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
"GracefulNodeShutdown": true,
|
"GracefulNodeShutdown": true,
|
||||||
|
"NodeSwapEnabled": true,
|
||||||
},
|
},
|
||||||
Logging: componentbaseconfig.LoggingConfiguration{
|
Logging: componentbaseconfig.LoggingConfiguration{
|
||||||
Format: "text",
|
Format: "text",
|
||||||
@ -225,15 +227,17 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
TopologyManagerPolicy: "invalid",
|
TopologyManagerPolicy: "invalid",
|
||||||
ShutdownGracePeriod: metav1.Duration{Duration: 40 * time.Second},
|
ShutdownGracePeriod: metav1.Duration{Duration: 40 * time.Second},
|
||||||
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 10 * time.Second},
|
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 10 * time.Second},
|
||||||
|
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: "invalid"},
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
"GracefulNodeShutdown": true,
|
"GracefulNodeShutdown": true,
|
||||||
|
"NodeSwapEnabled": true,
|
||||||
},
|
},
|
||||||
Logging: componentbaseconfig.LoggingConfiguration{
|
Logging: componentbaseconfig.LoggingConfiguration{
|
||||||
Format: "text",
|
Format: "text",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const numErrsErrorCase2 = 3
|
const numErrsErrorCase2 = 4
|
||||||
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