@@ -55,6 +55,7 @@ import (
55
55
"k8s.io/client-go/kubernetes/fake"
56
56
"k8s.io/client-go/tools/record"
57
57
"k8s.io/client-go/util/flowcontrol"
58
+ "k8s.io/component-base/featuregate"
58
59
featuregatetesting "k8s.io/component-base/featuregate/testing"
59
60
"k8s.io/component-base/metrics/testutil"
60
61
internalapi "k8s.io/cri-api/pkg/apis"
@@ -338,8 +339,8 @@ func newTestKubeletWithImageList(
338
339
kubelet .containerGC = containerGC
339
340
340
341
fakeClock := testingclock .NewFakeClock (time .Now ())
341
- kubelet .backOff = flowcontrol .NewBackOff (time .Second , time .Minute )
342
- kubelet .backOff .Clock = fakeClock
342
+ kubelet .crashLoopBackOff = flowcontrol .NewBackOff (time .Second , time .Minute )
343
+ kubelet .crashLoopBackOff .Clock = fakeClock
343
344
kubelet .resyncInterval = 10 * time .Second
344
345
kubelet .workQueue = queue .NewBasicWorkQueue (fakeClock )
345
346
// Relist period does not affect the tests.
@@ -2900,7 +2901,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
2900
2901
now := kubelet .clock .Now ()
2901
2902
// Put the container in backoff so we can confirm backoff is reset.
2902
2903
backoffKey := kuberuntime .GetStableKey (originalPod , originalCtr )
2903
- kubelet .backOff .Next (backoffKey , now )
2904
+ kubelet .crashLoopBackOff .Next (backoffKey , now )
2904
2905
2905
2906
updatedPod , err := kubelet .handlePodResourcesResize (newPod , podStatus )
2906
2907
require .NoError (t , err )
@@ -2922,7 +2923,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
2922
2923
resizeStatus := kubelet .statusManager .GetPodResizeStatus (newPod .UID )
2923
2924
assert .Equal (t , tt .expectedResize , resizeStatus )
2924
2925
2925
- isInBackoff := kubelet .backOff .IsInBackOffSince (backoffKey , now )
2926
+ isInBackoff := kubelet .crashLoopBackOff .IsInBackOffSince (backoffKey , now )
2926
2927
if tt .expectBackoffReset {
2927
2928
assert .False (t , isInBackoff , "container backoff should be reset" )
2928
2929
} else {
@@ -3408,7 +3409,7 @@ func TestSyncPodSpans(t *testing.T) {
3408
3409
kubelet .os ,
3409
3410
kubelet ,
3410
3411
nil ,
3411
- kubelet .backOff ,
3412
+ kubelet .crashLoopBackOff ,
3412
3413
kubeCfg .SerializeImagePulls ,
3413
3414
kubeCfg .MaxParallelImagePulls ,
3414
3415
float32 (kubeCfg .RegistryPullQPS ),
@@ -3938,3 +3939,86 @@ func TestIsPodResizeInProgress(t *testing.T) {
3938
3939
})
3939
3940
}
3940
3941
}
3942
+
3943
+ func TestCrashLoopBackOffConfiguration (t * testing.T ) {
3944
+ testCases := []struct {
3945
+ name string
3946
+ featureGates []featuregate.Feature
3947
+ nodeDecay metav1.Duration
3948
+ expectedInitial time.Duration
3949
+ expectedMax time.Duration
3950
+ }{
3951
+ {
3952
+ name : "Prior behavior" ,
3953
+ expectedMax : time .Duration (300 * time .Second ),
3954
+ expectedInitial : time .Duration (10 * time .Second ),
3955
+ },
3956
+ {
3957
+ name : "New default only" ,
3958
+ featureGates : []featuregate.Feature {features .ReduceDefaultCrashLoopBackOffDecay },
3959
+ expectedMax : time .Duration (60 * time .Second ),
3960
+ expectedInitial : time .Duration (1 * time .Second ),
3961
+ },
3962
+ {
3963
+ name : "Faster per node config; only node config configured" ,
3964
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
3965
+ nodeDecay : metav1.Duration {Duration : 2 * time .Second },
3966
+ expectedMax : time .Duration (2 * time .Second ),
3967
+ expectedInitial : time .Duration (2 * time .Second ),
3968
+ },
3969
+ {
3970
+ name : "Faster per node config; new default and node config configured" ,
3971
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3972
+ nodeDecay : metav1.Duration {Duration : 2 * time .Second },
3973
+ expectedMax : time .Duration (2 * time .Second ),
3974
+ expectedInitial : time .Duration (1 * time .Second ),
3975
+ },
3976
+ {
3977
+ name : "Slower per node config; new default and node config configured, set A" ,
3978
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3979
+ nodeDecay : metav1.Duration {Duration : 10 * time .Second },
3980
+ expectedMax : time .Duration (10 * time .Second ),
3981
+ expectedInitial : time .Duration (1 * time .Second ),
3982
+ },
3983
+ {
3984
+ name : "Slower per node config; new default and node config configured, set B" ,
3985
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3986
+ nodeDecay : metav1.Duration {Duration : 300 * time .Second },
3987
+ expectedMax : time .Duration (300 * time .Second ),
3988
+ expectedInitial : time .Duration (1 * time .Second ),
3989
+ },
3990
+ {
3991
+ name : "Slower per node config; only node config configured, set A" ,
3992
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
3993
+ nodeDecay : metav1.Duration {Duration : 11 * time .Second },
3994
+ expectedMax : time .Duration (11 * time .Second ),
3995
+ expectedInitial : time .Duration (10 * time .Second ),
3996
+ },
3997
+ {
3998
+ name : "Slower per node config; only node config configured, set B" ,
3999
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
4000
+ nodeDecay : metav1.Duration {Duration : 300 * time .Second },
4001
+ expectedMax : time .Duration (300 * time .Second ),
4002
+ expectedInitial : time .Duration (10 * time .Second ),
4003
+ },
4004
+ }
4005
+
4006
+ for _ , tc := range testCases {
4007
+ t .Run (tc .name , func (t * testing.T ) {
4008
+ kubeCfg := & kubeletconfiginternal.KubeletConfiguration {}
4009
+
4010
+ for _ , f := range tc .featureGates {
4011
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , f , true )
4012
+ }
4013
+ if tc .nodeDecay .Duration > 0 {
4014
+ kubeCfg .CrashLoopBackOff .MaxContainerRestartPeriod = & tc .nodeDecay
4015
+ }
4016
+
4017
+ resultMax , resultInitial := newCrashLoopBackOff (kubeCfg )
4018
+
4019
+ assert .Equalf (t , tc .expectedMax , resultMax , "wrong max calculated, want: %v, got %v" , tc .expectedMax , resultMax )
4020
+ assert .Equalf (t , tc .expectedInitial , resultInitial , "wrong base calculated, want: %v, got %v" , tc .expectedInitial , resultInitial )
4021
+ })
4022
+ }
4023
+
4024
+ }
0 commit comments