@@ -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"
@@ -337,8 +338,8 @@ func newTestKubeletWithImageList(
337
338
kubelet .containerGC = containerGC
338
339
339
340
fakeClock := testingclock .NewFakeClock (time .Now ())
340
- kubelet .backOff = flowcontrol .NewBackOff (time .Second , time .Minute )
341
- kubelet .backOff .Clock = fakeClock
341
+ kubelet .crashLoopBackOff = flowcontrol .NewBackOff (time .Second , time .Minute )
342
+ kubelet .crashLoopBackOff .Clock = fakeClock
342
343
kubelet .resyncInterval = 10 * time .Second
343
344
kubelet .workQueue = queue .NewBasicWorkQueue (fakeClock )
344
345
// Relist period does not affect the tests.
@@ -2895,7 +2896,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
2895
2896
now := kubelet .clock .Now ()
2896
2897
// Put the container in backoff so we can confirm backoff is reset.
2897
2898
backoffKey := kuberuntime .GetStableKey (originalPod , originalCtr )
2898
- kubelet .backOff .Next (backoffKey , now )
2899
+ kubelet .crashLoopBackOff .Next (backoffKey , now )
2899
2900
2900
2901
updatedPod , err := kubelet .handlePodResourcesResize (newPod , podStatus )
2901
2902
require .NoError (t , err )
@@ -2917,7 +2918,7 @@ func TestHandlePodResourcesResize(t *testing.T) {
2917
2918
resizeStatus := kubelet .statusManager .GetPodResizeStatus (newPod .UID )
2918
2919
assert .Equal (t , tt .expectedResize , resizeStatus )
2919
2920
2920
- isInBackoff := kubelet .backOff .IsInBackOffSince (backoffKey , now )
2921
+ isInBackoff := kubelet .crashLoopBackOff .IsInBackOffSince (backoffKey , now )
2921
2922
if tt .expectBackoffReset {
2922
2923
assert .False (t , isInBackoff , "container backoff should be reset" )
2923
2924
} else {
@@ -3403,7 +3404,7 @@ func TestSyncPodSpans(t *testing.T) {
3403
3404
kubelet .os ,
3404
3405
kubelet ,
3405
3406
nil ,
3406
- kubelet .backOff ,
3407
+ kubelet .crashLoopBackOff ,
3407
3408
kubeCfg .SerializeImagePulls ,
3408
3409
kubeCfg .MaxParallelImagePulls ,
3409
3410
float32 (kubeCfg .RegistryPullQPS ),
@@ -3933,3 +3934,86 @@ func TestIsPodResizeInProgress(t *testing.T) {
3933
3934
})
3934
3935
}
3935
3936
}
3937
+
3938
+ func TestCrashLoopBackOffConfiguration (t * testing.T ) {
3939
+ testCases := []struct {
3940
+ name string
3941
+ featureGates []featuregate.Feature
3942
+ nodeDecay metav1.Duration
3943
+ expectedInitial time.Duration
3944
+ expectedMax time.Duration
3945
+ }{
3946
+ {
3947
+ name : "Prior behavior" ,
3948
+ expectedMax : time .Duration (300 * time .Second ),
3949
+ expectedInitial : time .Duration (10 * time .Second ),
3950
+ },
3951
+ {
3952
+ name : "New default only" ,
3953
+ featureGates : []featuregate.Feature {features .ReduceDefaultCrashLoopBackOffDecay },
3954
+ expectedMax : time .Duration (60 * time .Second ),
3955
+ expectedInitial : time .Duration (1 * time .Second ),
3956
+ },
3957
+ {
3958
+ name : "Faster per node config; only node config configured" ,
3959
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
3960
+ nodeDecay : metav1.Duration {Duration : 2 * time .Second },
3961
+ expectedMax : time .Duration (2 * time .Second ),
3962
+ expectedInitial : time .Duration (2 * time .Second ),
3963
+ },
3964
+ {
3965
+ name : "Faster per node config; new default and node config configured" ,
3966
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3967
+ nodeDecay : metav1.Duration {Duration : 2 * time .Second },
3968
+ expectedMax : time .Duration (2 * time .Second ),
3969
+ expectedInitial : time .Duration (1 * time .Second ),
3970
+ },
3971
+ {
3972
+ name : "Slower per node config; new default and node config configured, set A" ,
3973
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3974
+ nodeDecay : metav1.Duration {Duration : 10 * time .Second },
3975
+ expectedMax : time .Duration (10 * time .Second ),
3976
+ expectedInitial : time .Duration (1 * time .Second ),
3977
+ },
3978
+ {
3979
+ name : "Slower per node config; new default and node config configured, set B" ,
3980
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax , features .ReduceDefaultCrashLoopBackOffDecay },
3981
+ nodeDecay : metav1.Duration {Duration : 300 * time .Second },
3982
+ expectedMax : time .Duration (300 * time .Second ),
3983
+ expectedInitial : time .Duration (1 * time .Second ),
3984
+ },
3985
+ {
3986
+ name : "Slower per node config; only node config configured, set A" ,
3987
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
3988
+ nodeDecay : metav1.Duration {Duration : 11 * time .Second },
3989
+ expectedMax : time .Duration (11 * time .Second ),
3990
+ expectedInitial : time .Duration (10 * time .Second ),
3991
+ },
3992
+ {
3993
+ name : "Slower per node config; only node config configured, set B" ,
3994
+ featureGates : []featuregate.Feature {features .KubeletCrashLoopBackOffMax },
3995
+ nodeDecay : metav1.Duration {Duration : 300 * time .Second },
3996
+ expectedMax : time .Duration (300 * time .Second ),
3997
+ expectedInitial : time .Duration (10 * time .Second ),
3998
+ },
3999
+ }
4000
+
4001
+ for _ , tc := range testCases {
4002
+ t .Run (tc .name , func (t * testing.T ) {
4003
+ kubeCfg := & kubeletconfiginternal.KubeletConfiguration {}
4004
+
4005
+ for _ , f := range tc .featureGates {
4006
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , f , true )
4007
+ }
4008
+ if tc .nodeDecay .Duration > 0 {
4009
+ kubeCfg .CrashLoopBackOff .MaxContainerRestartPeriod = & tc .nodeDecay
4010
+ }
4011
+
4012
+ resultMax , resultInitial := newCrashLoopBackOff (kubeCfg )
4013
+
4014
+ assert .Equalf (t , tc .expectedMax , resultMax , "wrong max calculated, want: %v, got %v" , tc .expectedMax , resultMax )
4015
+ assert .Equalf (t , tc .expectedInitial , resultInitial , "wrong base calculated, want: %v, got %v" , tc .expectedInitial , resultInitial )
4016
+ })
4017
+ }
4018
+
4019
+ }
0 commit comments