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