mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Add validation for GracefulNodeShutdownBasedOnPodPriority
Co-authored-by: Elana Hashman <ehashman@users.noreply.github.com>
This commit is contained in:
parent
545313bdc7
commit
7a6f792ff3
@ -166,6 +166,16 @@ 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.GracefulNodeShutdownBasedOnPodPriority) {
|
||||||
|
if len(kc.ShutdownGracePeriodByPodPriority) != 0 && (kc.ShutdownGracePeriod.Duration > 0 || kc.ShutdownGracePeriodCriticalPods.Duration > 0) {
|
||||||
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: Cannot specify both shutdownGracePeriodByPodPriority and shutdownGracePeriod at the same time"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !localFeatureGate.Enabled(features.GracefulNodeShutdownBasedOnPodPriority) {
|
||||||
|
if len(kc.ShutdownGracePeriodByPodPriority) != 0 {
|
||||||
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: Specifying shutdownGracePeriodByPodPriority requires feature gate GracefulNodeShutdownBasedOnPodPriority"))
|
||||||
|
}
|
||||||
|
}
|
||||||
if localFeatureGate.Enabled(features.NodeSwap) {
|
if localFeatureGate.Enabled(features.NodeSwap) {
|
||||||
if kc.MemorySwap.SwapBehavior != "" && kc.MemorySwap.SwapBehavior != kubetypes.LimitedSwap && kc.MemorySwap.SwapBehavior != kubetypes.UnlimitedSwap {
|
if kc.MemorySwap.SwapBehavior != "" && kc.MemorySwap.SwapBehavior != kubetypes.LimitedSwap && kc.MemorySwap.SwapBehavior != kubetypes.UnlimitedSwap {
|
||||||
allErrors = append(allErrors, fmt.Errorf("invalid configuration: MemorySwap.SwapBehavior %v must be one of: LimitedSwap, UnlimitedSwap", kc.MemorySwap.SwapBehavior))
|
allErrors = append(allErrors, fmt.Errorf("invalid configuration: MemorySwap.SwapBehavior %v must be one of: LimitedSwap, UnlimitedSwap", kc.MemorySwap.SwapBehavior))
|
||||||
|
@ -110,6 +110,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
"MemoryQoS": true,
|
"MemoryQoS": true,
|
||||||
|
"GracefulNodeShutdownBasedOnPodPriority": true,
|
||||||
},
|
},
|
||||||
Logging: componentbaseconfig.LoggingConfiguration{
|
Logging: componentbaseconfig.LoggingConfiguration{
|
||||||
Format: "text",
|
Format: "text",
|
||||||
@ -149,13 +150,20 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
ReservedSystemCPUs: "0-3",
|
ReservedSystemCPUs: "0-3",
|
||||||
TopologyManagerScope: kubeletconfig.ContainerTopologyManagerScope,
|
TopologyManagerScope: kubeletconfig.ContainerTopologyManagerScope,
|
||||||
TopologyManagerPolicy: kubeletconfig.NoneTopologyManagerPolicy,
|
TopologyManagerPolicy: kubeletconfig.NoneTopologyManagerPolicy,
|
||||||
ShutdownGracePeriod: metav1.Duration{Duration: 10 * time.Minute},
|
ShutdownGracePeriod: metav1.Duration{Duration: 0},
|
||||||
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 0},
|
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 0},
|
||||||
|
ShutdownGracePeriodByPodPriority: []kubeletconfig.ShutdownGracePeriodByPodPriority{
|
||||||
|
{
|
||||||
|
Priority: 0,
|
||||||
|
ShutdownGracePeriodSeconds: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: kubetypes.UnlimitedSwap},
|
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: kubetypes.UnlimitedSwap},
|
||||||
MemoryThrottlingFactor: utilpointer.Float64Ptr(0.5),
|
MemoryThrottlingFactor: utilpointer.Float64Ptr(0.5),
|
||||||
FeatureGates: map[string]bool{
|
FeatureGates: map[string]bool{
|
||||||
"CustomCPUCFSQuotaPeriod": true,
|
"CustomCPUCFSQuotaPeriod": true,
|
||||||
"GracefulNodeShutdown": true,
|
"GracefulNodeShutdown": true,
|
||||||
|
"GracefulNodeShutdownBasedOnPodPriority": true,
|
||||||
"NodeSwap": true,
|
"NodeSwap": true,
|
||||||
"MemoryQoS": true,
|
"MemoryQoS": true,
|
||||||
},
|
},
|
||||||
@ -194,12 +202,18 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
|||||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
|
CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
|
||||||
ShutdownGracePeriod: metav1.Duration{Duration: 30 * time.Second},
|
ShutdownGracePeriod: metav1.Duration{Duration: 30 * time.Second},
|
||||||
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 60 * time.Second},
|
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 60 * time.Second},
|
||||||
|
ShutdownGracePeriodByPodPriority: []kubeletconfig.ShutdownGracePeriodByPodPriority{
|
||||||
|
{
|
||||||
|
Priority: 0,
|
||||||
|
ShutdownGracePeriodSeconds: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
Logging: componentbaseconfig.LoggingConfiguration{
|
Logging: componentbaseconfig.LoggingConfiguration{
|
||||||
Format: "",
|
Format: "",
|
||||||
},
|
},
|
||||||
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: kubetypes.UnlimitedSwap},
|
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: kubetypes.UnlimitedSwap},
|
||||||
}
|
}
|
||||||
const numErrsErrorCase1 = 30
|
const numErrsErrorCase1 = 31
|
||||||
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()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user