@@ -4114,12 +4114,14 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
4114
4114
testCases := []struct {
4115
4115
name string
4116
4116
podSpec * api.PodSpec
4117
+ featureEnabled bool
4117
4118
expectAllowPodLifecycleSleepActionZeroValue bool
4118
4119
}{
4119
4120
{
4120
- name : "no lifecycle hooks" ,
4121
- podSpec : & api.PodSpec {},
4122
- expectAllowPodLifecycleSleepActionZeroValue : false ,
4121
+ name : "no lifecycle hooks" ,
4122
+ podSpec : & api.PodSpec {},
4123
+ featureEnabled : true ,
4124
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4123
4125
},
4124
4126
{
4125
4127
name : "Prestop with non-zero second duration" ,
@@ -4136,7 +4138,8 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
4136
4138
},
4137
4139
},
4138
4140
},
4139
- expectAllowPodLifecycleSleepActionZeroValue : false ,
4141
+ featureEnabled : true ,
4142
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4140
4143
},
4141
4144
{
4142
4145
name : "PostStart with non-zero second duration" ,
@@ -4153,7 +4156,8 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
4153
4156
},
4154
4157
},
4155
4158
},
4156
- expectAllowPodLifecycleSleepActionZeroValue : false ,
4159
+ featureEnabled : true ,
4160
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4157
4161
},
4158
4162
{
4159
4163
name : "PreStop with zero seconds" ,
@@ -4170,6 +4174,7 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
4170
4174
},
4171
4175
},
4172
4176
},
4177
+ featureEnabled : true ,
4173
4178
expectAllowPodLifecycleSleepActionZeroValue : true ,
4174
4179
},
4175
4180
{
@@ -4187,12 +4192,93 @@ func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
4187
4192
},
4188
4193
},
4189
4194
},
4195
+ featureEnabled : true ,
4196
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4197
+ },
4198
+ {
4199
+ name : "no lifecycle hooks with feature gate disabled" ,
4200
+ podSpec : & api.PodSpec {},
4201
+ featureEnabled : false ,
4202
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4203
+ },
4204
+ {
4205
+ name : "Prestop with non-zero second duration with feature gate disabled" ,
4206
+ podSpec : & api.PodSpec {
4207
+ Containers : []api.Container {
4208
+ {
4209
+ Lifecycle : & api.Lifecycle {
4210
+ PreStop : & api.LifecycleHandler {
4211
+ Sleep : & api.SleepAction {
4212
+ Seconds : 1 ,
4213
+ },
4214
+ },
4215
+ },
4216
+ },
4217
+ },
4218
+ },
4219
+ featureEnabled : false ,
4220
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4221
+ },
4222
+ {
4223
+ name : "PostStart with non-zero second duration with feature gate disabled" ,
4224
+ podSpec : & api.PodSpec {
4225
+ Containers : []api.Container {
4226
+ {
4227
+ Lifecycle : & api.Lifecycle {
4228
+ PostStart : & api.LifecycleHandler {
4229
+ Sleep : & api.SleepAction {
4230
+ Seconds : 1 ,
4231
+ },
4232
+ },
4233
+ },
4234
+ },
4235
+ },
4236
+ },
4237
+ featureEnabled : false ,
4238
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4239
+ },
4240
+ {
4241
+ name : "PreStop with zero seconds with feature gate disabled" ,
4242
+ podSpec : & api.PodSpec {
4243
+ Containers : []api.Container {
4244
+ {
4245
+ Lifecycle : & api.Lifecycle {
4246
+ PreStop : & api.LifecycleHandler {
4247
+ Sleep : & api.SleepAction {
4248
+ Seconds : 0 ,
4249
+ },
4250
+ },
4251
+ },
4252
+ },
4253
+ },
4254
+ },
4255
+ featureEnabled : false ,
4256
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4257
+ },
4258
+ {
4259
+ name : "PostStart with zero seconds with feature gate disabled" ,
4260
+ podSpec : & api.PodSpec {
4261
+ Containers : []api.Container {
4262
+ {
4263
+ Lifecycle : & api.Lifecycle {
4264
+ PostStart : & api.LifecycleHandler {
4265
+ Sleep : & api.SleepAction {
4266
+ Seconds : 0 ,
4267
+ },
4268
+ },
4269
+ },
4270
+ },
4271
+ },
4272
+ },
4273
+ featureEnabled : false ,
4190
4274
expectAllowPodLifecycleSleepActionZeroValue : true ,
4191
4275
},
4192
4276
}
4193
4277
4194
4278
for _ , tc := range testCases {
4195
4279
t .Run (tc .name , func (t * testing.T ) {
4280
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodLifecycleSleepActionAllowZero , tc .featureEnabled )
4281
+
4196
4282
gotOptions := GetValidationOptionsFromPodSpecAndMeta (& api.PodSpec {}, tc .podSpec , nil , nil )
4197
4283
assert .Equal (t , tc .expectAllowPodLifecycleSleepActionZeroValue , gotOptions .AllowPodLifecycleSleepActionZeroValue , "AllowPodLifecycleSleepActionZeroValue" )
4198
4284
})
0 commit comments